From cde121735625a1081d09b26bfa90c78adb557bae Mon Sep 17 00:00:00 2001 From: Leonardo Galli Date: Mon, 2 Jan 2017 22:01:11 +0100 Subject: [PATCH] Movies now show up in the Queue. --- src/NzbDrone.Api/Queue/QueueResource.cs | 5 ++- .../Download/Pending/PendingReleaseService.cs | 6 ++++ .../TrackedDownloads/TrackedDownload.cs | 1 + .../TrackedDownloadService.cs | 7 ++-- src/NzbDrone.Core/Queue/Queue.cs | 2 ++ src/NzbDrone.Core/Queue/QueueService.cs | 34 +++++++++++++++++-- src/UI/Activity/Queue/QueueCollection.js | 10 +++++- src/UI/Activity/Queue/QueueLayout.js | 10 +++--- src/UI/Activity/Queue/QueueModel.js | 4 ++- 9 files changed, 66 insertions(+), 13 deletions(-) diff --git a/src/NzbDrone.Api/Queue/QueueResource.cs b/src/NzbDrone.Api/Queue/QueueResource.cs index cf1356c49..e90a9bace 100644 --- a/src/NzbDrone.Api/Queue/QueueResource.cs +++ b/src/NzbDrone.Api/Queue/QueueResource.cs @@ -4,6 +4,7 @@ using NzbDrone.Api.REST; using NzbDrone.Core.Qualities; using NzbDrone.Api.Series; using NzbDrone.Api.Episodes; +using NzbDrone.Api.Movie; using NzbDrone.Core.Download.TrackedDownloads; using NzbDrone.Core.Indexers; using System.Linq; @@ -14,6 +15,7 @@ namespace NzbDrone.Api.Queue { public SeriesResource Series { get; set; } public EpisodeResource Episode { get; set; } + public MovieResource Movie { get; set; } public QualityModel Quality { get; set; } public decimal Size { get; set; } public string Title { get; set; } @@ -49,7 +51,8 @@ namespace NzbDrone.Api.Queue TrackedDownloadStatus = model.TrackedDownloadStatus, StatusMessages = model.StatusMessages, DownloadId = model.DownloadId, - Protocol = model.Protocol + Protocol = model.Protocol, + Movie = model.Movie.ToResource() }; } diff --git a/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs b/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs index 8585a1704..d5fbff7d8 100644 --- a/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs +++ b/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs @@ -33,6 +33,7 @@ namespace NzbDrone.Core.Download.Pending public class PendingReleaseService : IPendingReleaseService, IHandle, IHandle, + IHandle, IHandle { private readonly IIndexerStatusService _indexerStatusService; @@ -341,6 +342,11 @@ namespace NzbDrone.Core.Download.Pending RemoveGrabbed(message.Episode); } + public void Handle(MovieGrabbedEvent message) + { + + } + public void Handle(RssSyncCompleteEvent message) { RemoveRejected(message.ProcessedDecisions.Rejected); diff --git a/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownload.cs b/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownload.cs index be012d57b..57ce35578 100644 --- a/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownload.cs +++ b/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownload.cs @@ -10,6 +10,7 @@ namespace NzbDrone.Core.Download.TrackedDownloads public TrackedDownloadStage State { get; set; } public TrackedDownloadStatus Status { get; private set; } public RemoteEpisode RemoteEpisode { get; set; } + public RemoteMovie RemoteMovie { get; set; } public TrackedDownloadStatusMessage[] StatusMessages { get; private set; } public DownloadProtocol Protocol { get; set; } diff --git a/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs b/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs index 55ce7398d..c7ba36cbc 100644 --- a/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs +++ b/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs @@ -62,6 +62,7 @@ namespace NzbDrone.Core.Download.TrackedDownloads if (parsedEpisodeInfo != null) { trackedDownload.RemoteEpisode = _parsingService.Map(parsedEpisodeInfo, 0, 0); + trackedDownload.RemoteMovie = _parsingService.Map(parsedEpisodeInfo, "", null); } if (historyItems.Any()) @@ -69,10 +70,10 @@ namespace NzbDrone.Core.Download.TrackedDownloads var firstHistoryItem = historyItems.OrderByDescending(h => h.Date).First(); trackedDownload.State = GetStateFromHistory(firstHistoryItem.EventType); - if (parsedEpisodeInfo == null || + if ((parsedEpisodeInfo == null || trackedDownload.RemoteEpisode == null || trackedDownload.RemoteEpisode.Series == null || - trackedDownload.RemoteEpisode.Episodes.Empty()) + trackedDownload.RemoteEpisode.Episodes.Empty()) && trackedDownload.RemoteMovie == null) { // Try parsing the original source title and if that fails, try parsing it as a special // TODO: Pass the TVDB ID and TVRage IDs in as well so we have a better chance for finding the item @@ -85,7 +86,7 @@ namespace NzbDrone.Core.Download.TrackedDownloads } } - if (trackedDownload.RemoteEpisode == null) + if (trackedDownload.RemoteEpisode == null && trackedDownload.RemoteMovie == null) { return null; } diff --git a/src/NzbDrone.Core/Queue/Queue.cs b/src/NzbDrone.Core/Queue/Queue.cs index 7164a17ae..851c404e2 100644 --- a/src/NzbDrone.Core/Queue/Queue.cs +++ b/src/NzbDrone.Core/Queue/Queue.cs @@ -13,6 +13,7 @@ namespace NzbDrone.Core.Queue { public Series Series { get; set; } public Episode Episode { get; set; } + public Movie Movie { get; set; } public QualityModel Quality { get; set; } public decimal Size { get; set; } public string Title { get; set; } @@ -24,6 +25,7 @@ namespace NzbDrone.Core.Queue public List StatusMessages { get; set; } public string DownloadId { get; set; } public RemoteEpisode RemoteEpisode { get; set; } + public RemoteMovie RemoteMovie { get; set; } public DownloadProtocol Protocol { get; set; } } } diff --git a/src/NzbDrone.Core/Queue/QueueService.cs b/src/NzbDrone.Core/Queue/QueueService.cs index 264645ed8..d867b4ddb 100644 --- a/src/NzbDrone.Core/Queue/QueueService.cs +++ b/src/NzbDrone.Core/Queue/QueueService.cs @@ -51,12 +51,42 @@ namespace NzbDrone.Core.Queue yield return MapEpisode(trackedDownload, episode); } } - else + else if (trackedDownload.RemoteMovie.Movie != null) { - // FIXME: Present queue items with unknown series/episodes + yield return MapMovie(trackedDownload, trackedDownload.RemoteMovie.Movie); } } + private Queue MapMovie(TrackedDownload trackedDownload, Movie movie) + { + var queue = new Queue + { + Id = HashConverter.GetHashInt31(string.Format("trackedDownload-{0}", trackedDownload.DownloadItem.DownloadId)), + Series = null, + Episode = null, + Quality = trackedDownload.RemoteMovie.ParsedEpisodeInfo.Quality, + Title = trackedDownload.DownloadItem.Title, + Size = trackedDownload.DownloadItem.TotalSize, + Sizeleft = trackedDownload.DownloadItem.RemainingSize, + Timeleft = trackedDownload.DownloadItem.RemainingTime, + Status = trackedDownload.DownloadItem.Status.ToString(), + TrackedDownloadStatus = trackedDownload.Status.ToString(), + StatusMessages = trackedDownload.StatusMessages.ToList(), + RemoteEpisode = trackedDownload.RemoteEpisode, + RemoteMovie = trackedDownload.RemoteMovie, + DownloadId = trackedDownload.DownloadItem.DownloadId, + Protocol = trackedDownload.Protocol, + Movie = movie + }; + + if (queue.Timeleft.HasValue) + { + queue.EstimatedCompletionTime = DateTime.UtcNow.Add(queue.Timeleft.Value); + } + + return queue; + } + private Queue MapEpisode(TrackedDownload trackedDownload, Episode episode) { var queue = new Queue diff --git a/src/UI/Activity/Queue/QueueCollection.js b/src/UI/Activity/Queue/QueueCollection.js index 474cafe6b..bd3aa065e 100644 --- a/src/UI/Activity/Queue/QueueCollection.js +++ b/src/UI/Activity/Queue/QueueCollection.js @@ -35,6 +35,14 @@ var QueueCollection = PageableCollection.extend({ } }, + movie : { + sortValue : function(model, attr) { + var movie = model.get(attr); + + return movie.get('sortTitle'); + } + }, + episode : { sortValue : function(model, attr) { var episode = model.get('episode'); @@ -84,4 +92,4 @@ QueueCollection = AsPageableCollection.call(QueueCollection); var collection = new QueueCollection().bindSignalR(); collection.fetch(); -module.exports = collection; \ No newline at end of file +module.exports = collection; diff --git a/src/UI/Activity/Queue/QueueLayout.js b/src/UI/Activity/Queue/QueueLayout.js index 462c6a568..4416cb07b 100644 --- a/src/UI/Activity/Queue/QueueLayout.js +++ b/src/UI/Activity/Queue/QueueLayout.js @@ -1,7 +1,7 @@ var Marionette = require('marionette'); var Backgrid = require('backgrid'); var QueueCollection = require('./QueueCollection'); -var SeriesTitleCell = require('../../Cells/SeriesTitleCell'); +var SeriesTitleCell = require('../../Cells/MovieTitleCell'); var EpisodeNumberCell = require('../../Cells/EpisodeNumberCell'); var EpisodeTitleCell = require('../../Cells/EpisodeTitleCell'); var QualityCell = require('../../Cells/QualityCell'); @@ -28,11 +28,11 @@ module.exports = Marionette.Layout.extend({ cellValue : 'this' }, { - name : 'series', - label : 'Series', + name : 'movie', + label : 'Movie', cell : SeriesTitleCell }, - { + /*{ name : 'episode', label : 'Episode', cell : EpisodeNumberCell @@ -42,7 +42,7 @@ module.exports = Marionette.Layout.extend({ label : 'Episode Title', cell : EpisodeTitleCell, cellValue : 'episode' - }, + },*/ { name : 'quality', label : 'Quality', diff --git a/src/UI/Activity/Queue/QueueModel.js b/src/UI/Activity/Queue/QueueModel.js index f8ec8c538..e9b3fb045 100644 --- a/src/UI/Activity/Queue/QueueModel.js +++ b/src/UI/Activity/Queue/QueueModel.js @@ -1,12 +1,14 @@ var Backbone = require('backbone'); var SeriesModel = require('../../Series/SeriesModel'); var EpisodeModel = require('../../Series/EpisodeModel'); +var MovieModel = require('../../Movies/MovieModel'); module.exports = Backbone.Model.extend({ parse : function(model) { model.series = new SeriesModel(model.series); model.episode = new EpisodeModel(model.episode); model.episode.set('series', model.series); + model.movie = new MovieModel(model.movie); return model; } -}); \ No newline at end of file +});