public void Setup()
        {
            var completed = Builder <DownloadClientItem> .CreateNew()
                            .With(h => h.Status     = DownloadItemStatus.Completed)
                            .With(h => h.OutputPath = new OsPath(@"C:\DropFolder\MyDownload".AsOsAgnostic()))
                            .With(h => h.Title      = "Drone.S01E01.HDTV")
                            .Build();

            _grabHistory = Builder <History.History> .CreateListOfSize(2).BuildList();

            var remoteAlbum = new RemoteAlbum
            {
                Artist = new Artist(),
                Albums = new List <Album> {
                    new Album {
                        Id = 1
                    }
                }
            };

            _trackedDownload = Builder <TrackedDownload> .CreateNew()
                               .With(c => c.State        = TrackedDownloadState.DownloadFailedPending)
                               .With(c => c.DownloadItem = completed)
                               .With(c => c.RemoteAlbum  = remoteAlbum)
                               .Build();

            Mocker.GetMock <IHistoryService>()
            .Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, HistoryEventType.Grabbed))
            .Returns(_grabHistory);
        }
示例#2
0
        private Queue MapQueueItem(TrackedDownload trackedDownload, Episode episode)
        {
            var queue = new Queue
            {
                Series   = trackedDownload.RemoteEpisode?.Series,
                Episode  = episode,
                Language = trackedDownload.RemoteEpisode?.ParsedEpisodeInfo.Language ?? Language.Unknown,
                Quality  = trackedDownload.RemoteEpisode?.ParsedEpisodeInfo.Quality ?? new QualityModel(Quality.Unknown),
                Title    = Parser.Parser.RemoveFileExtension(trackedDownload.DownloadItem.Title),
                Size     = trackedDownload.DownloadItem.TotalSize,
                Sizeleft = trackedDownload.DownloadItem.RemainingSize,
                Timeleft = trackedDownload.DownloadItem.RemainingTime,
                Status   = trackedDownload.DownloadItem.Status.ToString(),
                TrackedDownloadStatus = trackedDownload.Status,
                TrackedDownloadState  = trackedDownload.State,
                StatusMessages        = trackedDownload.StatusMessages.ToList(),
                ErrorMessage          = trackedDownload.DownloadItem.Message,
                RemoteEpisode         = trackedDownload.RemoteEpisode,
                DownloadId            = trackedDownload.DownloadItem.DownloadId,
                Protocol       = trackedDownload.Protocol,
                DownloadClient = trackedDownload.DownloadItem.DownloadClientInfo.Name,
                Indexer        = trackedDownload.Indexer,
                OutputPath     = trackedDownload.DownloadItem.OutputPath.ToString()
            };

            queue.Id = HashConverter.GetHashInt31($"trackedDownload-{trackedDownload.DownloadClient}-{trackedDownload.DownloadItem.DownloadId}-ep{episode?.Id ?? 0}");

            if (queue.Timeleft.HasValue)
            {
                queue.EstimatedCompletionTime = DateTime.UtcNow.Add(queue.Timeleft.Value);
            }

            return(queue);
        }
示例#3
0
        public void Process(TrackedDownload trackedDownload)
        {
            string failure = null;

            if (trackedDownload.DownloadItem.IsEncrypted)
            {
                failure = "Encrypted download detected";
            }
            else if (trackedDownload.DownloadItem.Status == DownloadItemStatus.Failed)
            {
                failure = trackedDownload.DownloadItem.Message ?? "Failed download detected";
            }

            if (failure != null)
            {
                var grabbedItems = _historyService.Find(trackedDownload.DownloadItem.DownloadId, HistoryEventType.Grabbed)
                    .ToList();

                if (grabbedItems.Empty())
                {
                    trackedDownload.Warn("Download wasn't grabbed by sonarr, skipping");
                    return;
                }
            
                trackedDownload.State = TrackedDownloadStage.DownloadFailed;
                PublishDownloadFailedEvent(grabbedItems, failure, trackedDownload);
            }
        }
示例#4
0
        public void Setup()
        {
            Mocker.GetMock <IDiskProvider>().Setup(c => c.FolderExists(It.IsAny <string>()))
            .Returns(true);

            Mocker.GetMock <IConfigService>().SetupGet(c => c.DownloadedEpisodesFolder)
            .Returns(_droneFactory);

            Mocker.GetMock <IDownloadedEpisodesImportService>()
            .Setup(v => v.ProcessRootFolder(It.IsAny <DirectoryInfo>()))
            .Returns(new List <ImportResult>());

            Mocker.GetMock <IDownloadedEpisodesImportService>()
            .Setup(v => v.ProcessFolder(It.IsAny <DirectoryInfo>(), It.IsAny <DownloadClientItem>()))
            .Returns(new List <ImportResult>());

            var downloadItem = Builder <DownloadClientItem> .CreateNew()
                               .With(v => v.DownloadClientId = "sab1")
                               .With(v => v.Status           = DownloadItemStatus.Downloading)
                               .Build();

            _trackedDownload = new TrackedDownload
            {
                DownloadItem = downloadItem,
                State        = TrackedDownloadState.Downloading
            };
        }
示例#5
0
        public void Setup()
        {
            var completed = Builder <DownloadClientItem> .CreateNew()
                            .With(h => h.Status     = DownloadItemStatus.Completed)
                            .With(h => h.OutputPath = new OsPath(@"C:\DropFolder\MyDownload".AsOsAgnostic()))
                            .With(h => h.Title      = "Drone.DroneTheBook.FLAC")
                            .Build();

            _grabHistory = Builder <EntityHistory> .CreateListOfSize(2).BuildList();

            var remoteBook = new RemoteBook
            {
                Author = new Author(),
                Books  = new List <Book> {
                    new Book {
                        Id = 1
                    }
                }
            };

            _trackedDownload = Builder <TrackedDownload> .CreateNew()
                               .With(c => c.State        = TrackedDownloadState.Downloading)
                               .With(c => c.DownloadItem = completed)
                               .With(c => c.RemoteBook   = remoteBook)
                               .Build();

            Mocker.GetMock <IHistoryService>()
            .Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, EntityHistoryEventType.Grabbed))
            .Returns(_grabHistory);
        }
示例#6
0
        public void Setup()
        {
            var completed = Builder <DownloadClientItem> .CreateNew()
                            .With(h => h.Status     = DownloadItemStatus.Completed)
                            .With(h => h.OutputPath = new OsPath(@"C:\DropFolder\MyDownload".AsOsAgnostic()))
                            .With(h => h.Title      = "Drone.S01E01.HDTV")
                            .Build();

            _grabHistory = Builder <MovieHistory> .CreateListOfSize(2).BuildList();

            var remoteMovie = new RemoteMovie
            {
                Movie = new Movie(),
            };

            _trackedDownload = Builder <TrackedDownload> .CreateNew()
                               .With(c => c.State        = TrackedDownloadState.Downloading)
                               .With(c => c.DownloadItem = completed)
                               .With(c => c.RemoteMovie  = remoteMovie)
                               .Build();

            Mocker.GetMock <IHistoryService>()
            .Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, MovieHistoryEventType.Grabbed))
            .Returns(_grabHistory);
        }
示例#7
0
        public void Setup()
        {
            var completed = Builder <DownloadClientItem> .CreateNew()
                            .With(h => h.Status     = DownloadItemStatus.Completed)
                            .With(h => h.OutputPath = new OsPath(@"C:\DropFolder\MyDownload".AsOsAgnostic()))
                            .With(h => h.Title      = "Drone.S01E01.HDTV")
                            .Build();

            var remoteBook = BuildRemoteAlbum();

            _trackedDownload = Builder <TrackedDownload> .CreateNew()
                               .With(c => c.State        = TrackedDownloadState.Downloading)
                               .With(c => c.ImportItem   = completed)
                               .With(c => c.DownloadItem = completed)
                               .With(c => c.RemoteBook   = remoteBook)
                               .Build();

            Mocker.GetMock <IDownloadClient>()
            .SetupGet(c => c.Definition)
            .Returns(new DownloadClientDefinition {
                Id = 1, Name = "testClient"
            });

            Mocker.GetMock <IProvideDownloadClient>()
            .Setup(c => c.Get(It.IsAny <int>()))
            .Returns(Mocker.GetMock <IDownloadClient>().Object);

            Mocker.GetMock <IHistoryService>()
            .Setup(s => s.MostRecentForDownloadId(_trackedDownload.DownloadItem.DownloadId))
            .Returns(new History.History());

            Mocker.GetMock <IParsingService>()
            .Setup(s => s.GetArtist("Drone.S01E01.HDTV"))
            .Returns(remoteBook.Author);
        }
示例#8
0
        private Queue MapMovie(TrackedDownload trackedDownload, Movie movie)
        {
            var queue = new Queue
            {
                Languages = trackedDownload.RemoteMovie?.ParsedMovieInfo.Languages ?? new List <Language> {
                    Language.Unknown
                },
                Quality  = trackedDownload.RemoteMovie?.ParsedMovieInfo.Quality ?? new QualityModel(Quality.Unknown),
                Title    = trackedDownload.DownloadItem.Title,
                Size     = trackedDownload.DownloadItem.TotalSize,
                Sizeleft = trackedDownload.DownloadItem.RemainingSize,
                Timeleft = trackedDownload.DownloadItem.RemainingTime,
                Status   = trackedDownload.DownloadItem.Status.ToString(),
                TrackedDownloadStatus = trackedDownload.Status,
                TrackedDownloadState  = trackedDownload.State,
                StatusMessages        = trackedDownload.StatusMessages.ToList(),
                ErrorMessage          = trackedDownload.DownloadItem.Message,
                RemoteMovie           = trackedDownload.RemoteMovie,
                DownloadId            = trackedDownload.DownloadItem.DownloadId,
                Protocol       = trackedDownload.Protocol,
                Movie          = movie,
                DownloadClient = trackedDownload.DownloadItem.DownloadClientInfo.Name,
                Indexer        = trackedDownload.Indexer,
                OutputPath     = trackedDownload.DownloadItem.OutputPath.ToString()
            };

            queue.Id = HashConverter.GetHashInt31($"trackedDownload-{trackedDownload.DownloadClient}-{trackedDownload.DownloadItem.DownloadId}");

            if (queue.Timeleft.HasValue)
            {
                queue.EstimatedCompletionTime = DateTime.UtcNow.Add(queue.Timeleft.Value);
            }

            return(queue);
        }
        public void Setup()
        {
            GivenAudioFiles(_audioFiles, 10);

            Mocker.GetMock <IDiskScanService>().Setup(c => c.GetBookFiles(It.IsAny <string>(), It.IsAny <bool>()))
            .Returns(_audioFiles.Select(x => DiskProvider.GetFileInfo(x)).ToArray());

            Mocker.GetMock <IDiskScanService>().Setup(c => c.FilterFiles(It.IsAny <string>(), It.IsAny <IEnumerable <IFileInfo> >()))
            .Returns <string, IEnumerable <IFileInfo> >((b, s) => s.ToList());

            Mocker.GetMock <IImportApprovedBooks>()
            .Setup(s => s.Import(It.IsAny <List <ImportDecision <LocalBook> > >(), true, null, ImportMode.Auto))
            .Returns(new List <ImportResult>());

            var downloadItem = Builder <DownloadClientItem> .CreateNew()
                               .With(v => v.DownloadId = "sab1")
                               .With(v => v.Status     = DownloadItemStatus.Downloading)
                               .Build();

            var remoteBook = Builder <RemoteBook> .CreateNew()
                             .With(v => v.Author = new Author())
                             .Build();

            _trackedDownload = new TrackedDownload
            {
                DownloadItem = downloadItem,
                RemoteBook   = remoteBook,
                State        = TrackedDownloadState.Downloading
            };
        }
示例#10
0
 private IEnumerable <Queue> MapQueue(TrackedDownload trackedDownload)
 {
     if (trackedDownload.RemoteMovie != null && trackedDownload.RemoteMovie.Movie != null)
     {
         yield return(MapMovie(trackedDownload, trackedDownload.RemoteMovie.Movie));
     }
 }
示例#11
0
        private Queue MapEpisode(TrackedDownload trackedDownload, Episode episode)
        {
            var queue = new Queue
            {
                Id       = HashConverter.GetHashInt31(string.Format("trackedDownload-{0}-ep{1}", trackedDownload.DownloadItem.DownloadId, episode.Id)),
                Series   = trackedDownload.RemoteEpisode.Series,
                Episode  = episode,
                Quality  = trackedDownload.RemoteEpisode.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,
                DownloadId            = trackedDownload.DownloadItem.DownloadId,
                Protocol = trackedDownload.Protocol
            };

            if (queue.Timeleft.HasValue)
            {
                queue.EstimatedCompletionTime = DateTime.UtcNow.Add(queue.Timeleft.Value);
            }

            return(queue);
        }
        public void Setup()
        {
            Mocker.GetMock <IDiskScanService>().Setup(c => c.GetVideoFiles(It.IsAny <string>(), It.IsAny <bool>()))
            .Returns(_videoFiles);

            Mocker.GetMock <IDiskScanService>().Setup(c => c.FilterFiles(It.IsAny <string>(), It.IsAny <IEnumerable <string> >()))
            .Returns <string, IEnumerable <string> >((b, s) => s.ToList());

            Mocker.GetMock <IDiskProvider>().Setup(c => c.GetDirectories(It.IsAny <string>()))
            .Returns(_subFolders);

            Mocker.GetMock <IDiskProvider>().Setup(c => c.FolderExists(It.IsAny <string>()))
            .Returns(true);

            Mocker.GetMock <IImportApprovedEpisodes>()
            .Setup(s => s.Import(It.IsAny <List <ImportDecision> >(), true, null, ImportMode.Auto))
            .Returns(new List <ImportResult>());


            var downloadItem = Builder <DownloadClientItem> .CreateNew()
                               .With(v => v.DownloadId = "sab1")
                               .With(v => v.Status     = DownloadItemStatus.Downloading)
                               .Build();

            var remoteEpisode = Builder <RemoteEpisode> .CreateNew()
                                .With(v => v.Series = new Series())
                                .Build();

            _trackedDownload = new TrackedDownload
            {
                DownloadItem  = downloadItem,
                RemoteEpisode = remoteEpisode,
                State         = TrackedDownloadState.Downloading
            };
        }
        public void Setup()
        {
            Mocker.GetMock <IDownloadedTracksImportService>()
            .Setup(v => v.ProcessRootFolder(It.IsAny <IDirectoryInfo>()))
            .Returns(new List <ImportResult>());

            Mocker.GetMock <IDownloadedTracksImportService>()
            .Setup(v => v.ProcessPath(It.IsAny <string>(), It.IsAny <ImportMode>(), It.IsAny <Artist>(), It.IsAny <DownloadClientItem>()))
            .Returns(new List <ImportResult>());

            var downloadItem = Builder <DownloadClientItem> .CreateNew()
                               .With(v => v.DownloadId = "sab1")
                               .With(v => v.Status     = DownloadItemStatus.Downloading)
                               .Build();

            var remoteAlbum = Builder <RemoteAlbum> .CreateNew()
                              .With(v => v.Artist = new Artist())
                              .Build();

            _trackedDownload = new TrackedDownload
            {
                DownloadItem = downloadItem,
                RemoteAlbum  = remoteAlbum,
                State        = TrackedDownloadState.Downloading
            };
        }
        public void Setup()
        {
            Mocker.GetMock <IConfigService>().SetupGet(c => c.DownloadedEpisodesFolder)
            .Returns(_droneFactory);

            Mocker.GetMock <IDownloadedEpisodesImportService>()
            .Setup(v => v.ProcessRootFolder(It.IsAny <DirectoryInfo>()))
            .Returns(new List <ImportResult>());

            Mocker.GetMock <IDownloadedEpisodesImportService>()
            .Setup(v => v.ProcessPath(It.IsAny <string>(), It.IsAny <ImportMode>(), It.IsAny <Series>(), It.IsAny <DownloadClientItem>()))
            .Returns(new List <ImportResult>());

            var downloadItem = Builder <DownloadClientItem> .CreateNew()
                               .With(v => v.DownloadId = "sab1")
                               .With(v => v.Status     = DownloadItemStatus.Downloading)
                               .Build();

            var remoteEpisode = Builder <RemoteEpisode> .CreateNew()
                                .With(v => v.Series = new Series())
                                .Build();

            _trackedDownload = new TrackedDownload
            {
                DownloadItem  = downloadItem,
                RemoteEpisode = remoteEpisode,
                State         = TrackedDownloadStage.Downloading
            };
        }
示例#15
0
        public void Process(TrackedDownload trackedDownload, bool ignoreWarnings = false)
        {
            if (trackedDownload.DownloadItem.Status != DownloadItemStatus.Completed)
            {
                return;
            }

            if (!ignoreWarnings)
            {
                var historyItem = _historyService.MostRecentForDownloadId(trackedDownload.DownloadItem.DownloadId);

                if (historyItem == null && trackedDownload.DownloadItem.Category.IsNullOrWhiteSpace())
                {
                    trackedDownload.Warn("Download wasn't grabbed by Sonarr and not in a category, Skipping.");
                    return;
                }

                var downloadItemOutputPath = trackedDownload.DownloadItem.OutputPath;

                if (downloadItemOutputPath.IsEmpty)
                {
                    trackedDownload.Warn("Download doesn't contain intermediate path, Skipping.");
                    return;
                }

                if ((OsInfo.IsWindows && !downloadItemOutputPath.IsWindowsPath) ||
                    (OsInfo.IsNotWindows && !downloadItemOutputPath.IsUnixPath))
                {
                    trackedDownload.Warn("[{0}] is not a valid local path. You may need a Remote Path Mapping.", downloadItemOutputPath);
                    return;
                }

                var downloadedEpisodesFolder = new OsPath(_configService.DownloadedEpisodesFolder);

                if (downloadedEpisodesFolder.Contains(downloadItemOutputPath))
                {
                    trackedDownload.Warn("Intermediate Download path inside drone factory, Skipping.");
                    return;
                }

                var series = _parsingService.GetSeries(trackedDownload.DownloadItem.Title);

                if (series == null)
                {
                    if (historyItem != null)
                    {
                        series = _seriesService.GetSeries(historyItem.SeriesId);
                    }

                    if (series == null)
                    {
                        trackedDownload.Warn("Series title mismatch, automatic import is not possible.");
                        return;
                    }
                }
            }

            Import(trackedDownload);
        }
示例#16
0
        public void Setup()
        {
            _episode1 = new Episode {
                Id = 1, SeasonNumber = 1, EpisodeNumber = 1
            };
            _episode2 = new Episode {
                Id = 2, SeasonNumber = 1, EpisodeNumber = 2
            };
            _episode3 = new Episode {
                Id = 2, SeasonNumber = 1, EpisodeNumber = 3
            };

            var completed = Builder <DownloadClientItem> .CreateNew()
                            .With(h => h.Status     = DownloadItemStatus.Completed)
                            .With(h => h.OutputPath = new OsPath(@"C:\DropFolder\MyDownload".AsOsAgnostic()))
                            .With(h => h.Title      = "Drone.S01E01.HDTV")
                            .Build();

            var remoteEpisode = BuildRemoteEpisode();

            _trackedDownload = Builder <TrackedDownload> .CreateNew()
                               .With(c => c.State         = TrackedDownloadState.Downloading)
                               .With(c => c.DownloadItem  = completed)
                               .With(c => c.RemoteEpisode = remoteEpisode)
                               .Build();


            Mocker.GetMock <IDownloadClient>()
            .SetupGet(c => c.Definition)
            .Returns(new DownloadClientDefinition {
                Id = 1, Name = "testClient"
            });

            Mocker.GetMock <IProvideDownloadClient>()
            .Setup(c => c.Get(It.IsAny <int>()))
            .Returns(Mocker.GetMock <IDownloadClient>().Object);

            Mocker.GetMock <IHistoryService>()
            .Setup(s => s.MostRecentForDownloadId(_trackedDownload.DownloadItem.DownloadId))
            .Returns(new EpisodeHistory());

            Mocker.GetMock <IParsingService>()
            .Setup(s => s.GetSeries("Drone.S01E01.HDTV"))
            .Returns(remoteEpisode.Series);

            Mocker.GetMock <IHistoryService>()
            .Setup(s => s.FindByDownloadId(It.IsAny <string>()))
            .Returns(new List <EpisodeHistory>());

            Mocker.GetMock <IProvideImportItemService>()
            .Setup(s => s.ProvideImportItem(It.IsAny <DownloadClientItem>(), It.IsAny <DownloadClientItem>()))
            .Returns <DownloadClientItem, DownloadClientItem>((i, p) => i);
        }
示例#17
0
 private IEnumerable <Queue> MapQueue(TrackedDownload trackedDownload)
 {
     if (trackedDownload.RemoteEpisode.Episodes != null && trackedDownload.RemoteEpisode.Episodes.Any())
     {
         foreach (var episode in trackedDownload.RemoteEpisode.Episodes)
         {
             yield return(MapEpisode(trackedDownload, episode));
         }
     }
     else
     {
         // FIXME: Present queue items with unknown series/episodes
     }
 }
示例#18
0
 private IEnumerable <Queue> MapQueue(TrackedDownload trackedDownload)
 {
     if (trackedDownload.RemoteEpisode != null && trackedDownload.RemoteEpisode.Episodes != null && trackedDownload.RemoteEpisode.Episodes.Any())
     {
         foreach (var episode in trackedDownload.RemoteEpisode.Episodes)
         {
             yield return(MapEpisode(trackedDownload, episode));
         }
     }
     else if (trackedDownload.RemoteMovie != null && trackedDownload.RemoteMovie.Movie != null)
     {
         yield return(MapMovie(trackedDownload, trackedDownload.RemoteMovie.Movie));
     }
 }
        public void Setup()
        {
            _albums = new List <Album>();

            var remoteAlbum = Builder <RemoteAlbum> .CreateNew()
                              .With(r => r.Albums = _albums)
                              .Build();

            _trackedDownload = Builder <TrackedDownload> .CreateNew()
                               .With(t => t.RemoteAlbum = remoteAlbum)
                               .Build();

            _historyItems = new List <History.History>();
        }
示例#20
0
        public void Setup()
        {
            _books = new List <Book>();

            var remoteBook = Builder <RemoteBook> .CreateNew()
                             .With(r => r.Books = _books)
                             .Build();

            _trackedDownload = Builder <TrackedDownload> .CreateNew()
                               .With(t => t.RemoteBook = remoteBook)
                               .Build();

            _historyItems = new List <History.History>();
        }
示例#21
0
 private IEnumerable <Queue> MapQueue(TrackedDownload trackedDownload)
 {
     if (trackedDownload.RemoteAlbum?.Albums != null && trackedDownload.RemoteAlbum.Albums.Any())
     {
         foreach (var album in trackedDownload.RemoteAlbum.Albums)
         {
             yield return(MapQueueItem(trackedDownload, album));
         }
     }
     else
     {
         yield return(MapQueueItem(trackedDownload, null));
     }
 }
示例#22
0
 private IEnumerable <Queue> MapQueue(TrackedDownload trackedDownload)
 {
     if (trackedDownload.RemoteBook?.Books != null && trackedDownload.RemoteBook.Books.Any())
     {
         foreach (var book in trackedDownload.RemoteBook.Books)
         {
             yield return(MapQueueItem(trackedDownload, book));
         }
     }
     else
     {
         yield return(MapQueueItem(trackedDownload, null));
     }
 }
示例#23
0
        public void Setup()
        {
            _episodes = new List <Episode>();

            var remoteEpisode = Builder <RemoteEpisode> .CreateNew()
                                .With(r => r.Episodes = _episodes)
                                .Build();

            _trackedDownload = Builder <TrackedDownload> .CreateNew()
                               .With(t => t.RemoteEpisode = remoteEpisode)
                               .Build();

            _historyItems = new List <History.History>();
        }
示例#24
0
 private IEnumerable <Queue> MapQueue(TrackedDownload trackedDownload)
 {
     if (trackedDownload.RemoteEpisode?.Episodes != null && trackedDownload.RemoteEpisode.Episodes.Any())
     {
         foreach (var episode in trackedDownload.RemoteEpisode.Episodes)
         {
             yield return(MapQueueItem(trackedDownload, episode));
         }
     }
     else
     {
         yield return(MapQueueItem(trackedDownload, null));
     }
 }
示例#25
0
        private Queue MapQueueItem(TrackedDownload trackedDownload, Album album)
        {
            bool downloadForced = false;
            var  history        = _historyService.Find(trackedDownload.DownloadItem.DownloadId, HistoryEventType.Grabbed).FirstOrDefault();

            if (history != null && history.Data.ContainsKey("downloadForced"))
            {
                downloadForced = bool.Parse(history.Data["downloadForced"]);
            }

            var queue = new Queue
            {
                Artist   = trackedDownload.RemoteAlbum?.Artist,
                Album    = album,
                Quality  = trackedDownload.RemoteAlbum?.ParsedAlbumInfo.Quality ?? new QualityModel(Quality.Unknown),
                Title    = Parser.Parser.RemoveFileExtension(trackedDownload.DownloadItem.Title),
                Size     = trackedDownload.DownloadItem.TotalSize,
                Sizeleft = trackedDownload.DownloadItem.RemainingSize,
                Timeleft = trackedDownload.DownloadItem.RemainingTime,
                Status   = trackedDownload.DownloadItem.Status.ToString(),
                TrackedDownloadStatus = trackedDownload.Status,
                TrackedDownloadState  = trackedDownload.State,
                StatusMessages        = trackedDownload.StatusMessages.ToList(),
                ErrorMessage          = trackedDownload.DownloadItem.Message,
                RemoteAlbum           = trackedDownload.RemoteAlbum,
                DownloadId            = trackedDownload.DownloadItem.DownloadId,
                Protocol       = trackedDownload.Protocol,
                DownloadClient = trackedDownload.DownloadItem.DownloadClientInfo.Name,
                Indexer        = trackedDownload.Indexer,
                OutputPath     = trackedDownload.DownloadItem.OutputPath.ToString(),
                DownloadForced = downloadForced
            };

            if (album != null)
            {
                queue.Id = HashConverter.GetHashInt31(string.Format("trackedDownload-{0}-album{1}", trackedDownload.DownloadItem.DownloadId, album.Id));
            }
            else
            {
                queue.Id = HashConverter.GetHashInt31(string.Format("trackedDownload-{0}", trackedDownload.DownloadItem.DownloadId));
            }

            if (queue.Timeleft.HasValue)
            {
                queue.EstimatedCompletionTime = DateTime.UtcNow.Add(queue.Timeleft.Value);
            }

            return(queue);
        }
        public void Setup()
        {
            _books = new List <Book>();

            var remoteBook = Builder <RemoteBook> .CreateNew()
                             .With(r => r.Books = _books)
                             .Build();

            var downloadItem = Builder <DownloadClientItem> .CreateNew().Build();

            _trackedDownload = Builder <TrackedDownload> .CreateNew()
                               .With(t => t.RemoteBook   = remoteBook)
                               .With(t => t.DownloadItem = downloadItem)
                               .Build();

            _historyItems = new List <EntityHistory>();
        }
示例#27
0
        public void Setup()
        {
            _movie = Builder <Movie> .CreateNew().Build();

            var remoteMovie = Builder <RemoteMovie> .CreateNew()
                              .With(r => r.Movie = _movie)
                              .Build();

            var downloadItem = Builder <DownloadClientItem> .CreateNew()
                               .Build();

            _trackedDownload = Builder <TrackedDownload> .CreateNew()
                               .With(t => t.RemoteMovie  = remoteMovie)
                               .With(t => t.DownloadItem = downloadItem)
                               .Build();

            _historyItems = new List <MovieHistory>();
        }
示例#28
0
        private void PublishDownloadFailedEvent(List<History.History> historyItems, string message, TrackedDownload trackedDownload = null)
        {
            var historyItem = historyItems.First();

            var downloadFailedEvent = new DownloadFailedEvent
            {
                SeriesId = historyItem.SeriesId,
                EpisodeIds = historyItems.Select(h => h.EpisodeId).ToList(),
                Quality = historyItem.Quality,
                SourceTitle = historyItem.SourceTitle,
                DownloadClient = historyItem.Data.GetValueOrDefault(History.History.DOWNLOAD_CLIENT),
                DownloadId = historyItem.DownloadId,
                Message = message,
                Data = historyItem.Data,
                TrackedDownload = trackedDownload
            };

            _eventAggregator.PublishEvent(downloadFailedEvent);
        }
示例#29
0
        public void Setup()
        {
            var completed = Builder <DownloadClientItem> .CreateNew()
                            .With(h => h.Status     = DownloadItemStatus.Completed)
                            .With(h => h.OutputPath = new OsPath(@"C:\DropFolder\MyDownload".AsOsAgnostic()))
                            .With(h => h.Title      = "Drone.S01E01.HDTV")
                            .Build();

            var remoteEpisode = new RemoteEpisode
            {
                Series   = new Series(),
                Episodes = new List <Episode> {
                    new Episode {
                        Id = 1
                    }
                }
            };

            _trackedDownload = Builder <TrackedDownload> .CreateNew()
                               .With(c => c.State         = TrackedDownloadStage.Downloading)
                               .With(c => c.DownloadItem  = completed)
                               .With(c => c.RemoteEpisode = remoteEpisode)
                               .Build();


            Mocker.GetMock <IDownloadClient>()
            .SetupGet(c => c.Definition)
            .Returns(new DownloadClientDefinition {
                Id = 1, Name = "testClient"
            });

            Mocker.GetMock <IProvideDownloadClient>()
            .Setup(c => c.Get(It.IsAny <int>()))
            .Returns(Mocker.GetMock <IDownloadClient>().Object);

            Mocker.GetMock <IHistoryService>()
            .Setup(s => s.MostRecentForDownloadId(_trackedDownload.DownloadItem.DownloadId))
            .Returns(new History.History());

            Mocker.GetMock <IParsingService>()
            .Setup(s => s.GetSeries("Drone.S01E01.HDTV"))
            .Returns(remoteEpisode.Series);
        }
 public BookImportIncompleteEvent(TrackedDownload trackedDownload)
 {
     TrackedDownload = trackedDownload;
 }
 public AlbumImportIncompleteEvent(TrackedDownload trackedDownload)
 {
     TrackedDownload = trackedDownload;
 }
示例#32
0
        private void Import(TrackedDownload trackedDownload)
        {
            var outputPath = trackedDownload.DownloadItem.OutputPath.FullPath;
            var importResults = _downloadedEpisodesImportService.ProcessPath(outputPath, trackedDownload.RemoteEpisode.Series, trackedDownload.DownloadItem);

            if (importResults.Empty())
            {
                trackedDownload.Warn("No files found are eligible for import in {0}", outputPath);
                return;
            }

            if (importResults.Count(c => c.Result == ImportResultType.Imported) >= Math.Max(1, trackedDownload.RemoteEpisode.Episodes.Count))
            {
                trackedDownload.State = TrackedDownloadStage.Imported;
                _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload));
                return;
            }

            if (importResults.Any(c => c.Result != ImportResultType.Imported))
            {
                var statusMessages = importResults
                    .Where(v => v.Result != ImportResultType.Imported)
                    .Select(v => new TrackedDownloadStatusMessage(Path.GetFileName(v.ImportDecision.LocalEpisode.Path), v.Errors))
                    .ToArray();

                trackedDownload.Warn(statusMessages);
            }

        }
示例#33
0
        public void Execute(ManualImportCommand message)
        {
            _logger.ProgressTrace("Manually importing {0} files using mode {1}", message.Files.Count, message.ImportMode);

            var imported = new List<ImportResult>();
            var importedTrackedDownload = new List<ManuallyImportedFile>();

            for (int i = 0; i < message.Files.Count; i++)
            {
                _logger.ProgressTrace("Processing file {0} of {1}", i + 1, message.Files.Count);

                var file = message.Files[i];
                var movie = _movieService.GetMovie(file.MovieId);
                var fileMovieInfo = Parser.Parser.ParseMoviePath(file.Path) ?? new ParsedMovieInfo();
                var existingFile = movie.Path.IsParentPath(file.Path);
                TrackedDownload trackedDownload = null;

                var localMovie = new LocalMovie
                {
                    ExistingFile = false,
                    FileMovieInfo = fileMovieInfo,
                    Path = file.Path,
                    Quality = file.Quality,
                    Languages = file.Languages,
                    Movie = movie,
                    Size = 0
                };

                if (file.DownloadId.IsNotNullOrWhiteSpace())
                {
                    trackedDownload = _trackedDownloadService.Find(file.DownloadId);
                    localMovie.DownloadClientMovieInfo = trackedDownload?.RemoteMovie?.ParsedMovieInfo;
                }

                if (file.FolderName.IsNotNullOrWhiteSpace())
                {
                    localMovie.FolderMovieInfo = Parser.Parser.ParseMovieTitle(file.FolderName);
                    localMovie.SceneSource = !existingFile;
                }

                localMovie = _aggregationService.Augment(localMovie, trackedDownload?.DownloadItem, false);

                // Apply the user-chosen values.
                localMovie.Movie = movie;
                localMovie.Quality = file.Quality;
                localMovie.Languages = file.Languages;

                //TODO: Cleanup non-tracked downloads
                var importDecision = new ImportDecision(localMovie);

                if (trackedDownload == null)
                {
                    imported.AddRange(_importApprovedMovie.Import(new List<ImportDecision> { importDecision }, !existingFile, null, message.ImportMode));
                }
                else
                {
                    var importResult = _importApprovedMovie.Import(new List<ImportDecision> { importDecision }, true, trackedDownload.DownloadItem, message.ImportMode).First();

                    imported.Add(importResult);

                    importedTrackedDownload.Add(new ManuallyImportedFile
                    {
                        TrackedDownload = trackedDownload,
                        ImportResult = importResult
                    });
                }
            }

            _logger.ProgressTrace("Manually imported {0} files", imported.Count);

            foreach (var groupedTrackedDownload in importedTrackedDownload.GroupBy(i => i.TrackedDownload.DownloadItem.DownloadId).ToList())
            {
                var trackedDownload = groupedTrackedDownload.First().TrackedDownload;

                var importMovie = groupedTrackedDownload.First().ImportResult.ImportDecision.LocalMovie.Movie;
                var outputPath = trackedDownload.ImportItem.OutputPath.FullPath;

                if (_diskProvider.FolderExists(outputPath))
                {
                    if (_downloadedMovieImportService.ShouldDeleteFolder(
                            new DirectoryInfo(outputPath),
                            importMovie) && trackedDownload.DownloadItem.CanMoveFiles)
                    {
                        _diskProvider.DeleteFolder(outputPath, true);
                    }
                }

                if (groupedTrackedDownload.Select(c => c.ImportResult).Any(c => c.Result == ImportResultType.Imported))
                {
                    trackedDownload.State = TrackedDownloadState.Imported;
                    _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload, importMovie.Id));
                }
            }
        }
示例#34
0
        public void Execute(ManualImportCommand message)
        {
            _logger.ProgressTrace("Manually importing {0} files using mode {1}", message.Files.Count, message.ImportMode);

            var imported = new List <ImportResult>();
            var importedTrackedDownload = new List <ManuallyImportedFile>();

            for (int i = 0; i < message.Files.Count; i++)
            {
                _logger.ProgressTrace("Processing file {0} of {1}", i + 1, message.Files.Count);

                var file            = message.Files[i];
                var series          = _seriesService.GetSeries(file.SeriesId);
                var episodes        = _episodeService.GetEpisodes(file.EpisodeIds);
                var fileEpisodeInfo = Parser.Parser.ParsePath(file.Path) ?? new ParsedEpisodeInfo();
                var existingFile    = series.Path.IsParentPath(file.Path);

                TrackedDownload trackedDownload = null;

                var localEpisode = new LocalEpisode
                {
                    ExistingFile    = false,
                    Episodes        = episodes,
                    FileEpisodeInfo = fileEpisodeInfo,
                    Path            = file.Path,
                    ReleaseGroup    = file.ReleaseGroup,
                    Quality         = file.Quality,
                    Language        = file.Language,
                    Series          = series,
                    Size            = 0
                };

                if (file.DownloadId.IsNotNullOrWhiteSpace())
                {
                    trackedDownload = _trackedDownloadService.Find(file.DownloadId);
                    localEpisode.DownloadClientEpisodeInfo = trackedDownload?.RemoteEpisode?.ParsedEpisodeInfo;
                }

                if (file.FolderName.IsNotNullOrWhiteSpace())
                {
                    localEpisode.FolderEpisodeInfo = Parser.Parser.ParseTitle(file.FolderName);
                    localEpisode.SceneSource       = !existingFile;
                }

                // Augment episode file so imported files have all additional information an automatic import would
                localEpisode = _aggregationService.Augment(localEpisode, trackedDownload?.DownloadItem);

                // Apply the user-chosen values.
                localEpisode.Series       = series;
                localEpisode.Episodes     = episodes;
                localEpisode.ReleaseGroup = file.ReleaseGroup;
                localEpisode.Quality      = file.Quality;
                localEpisode.Language     = file.Language;

                //TODO: Cleanup non-tracked downloads

                var importDecision = new ImportDecision(localEpisode);

                if (trackedDownload == null)
                {
                    imported.AddRange(_importApprovedEpisodes.Import(new List <ImportDecision> {
                        importDecision
                    }, !existingFile, null, message.ImportMode));
                }
                else
                {
                    var importResult = _importApprovedEpisodes.Import(new List <ImportDecision> {
                        importDecision
                    }, true, trackedDownload.DownloadItem, message.ImportMode).First();

                    imported.Add(importResult);

                    importedTrackedDownload.Add(new ManuallyImportedFile
                    {
                        TrackedDownload = trackedDownload,
                        ImportResult    = importResult
                    });
                }
            }

            if (imported.Any())
            {
                _logger.ProgressTrace("Manually imported {0} files", imported.Count);
            }

            foreach (var groupedTrackedDownload in importedTrackedDownload.GroupBy(i => i.TrackedDownload.DownloadItem.DownloadId).ToList())
            {
                var trackedDownload = groupedTrackedDownload.First().TrackedDownload;
                var importedSeries  = imported.First().ImportDecision.LocalEpisode.Series;
                var outputPath      = trackedDownload.ImportItem.OutputPath.FullPath;

                if (_diskProvider.FolderExists(outputPath))
                {
                    if (_downloadedEpisodesImportService.ShouldDeleteFolder(
                            new DirectoryInfo(outputPath), importedSeries) &&
                        trackedDownload.DownloadItem.CanMoveFiles)
                    {
                        _diskProvider.DeleteFolder(outputPath, true);
                    }
                }

                var allEpisodesImported = groupedTrackedDownload.Select(c => c.ImportResult)
                                          .Where(c => c.Result == ImportResultType.Imported)
                                          .SelectMany(c => c.ImportDecision.LocalEpisode.Episodes).Count() >=
                                          Math.Max(1, trackedDownload.RemoteEpisode?.Episodes?.Count ?? 1);

                if (allEpisodesImported)
                {
                    trackedDownload.State = TrackedDownloadState.Imported;
                    _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload, importedSeries.Id));
                }
            }
        }