Esempio n. 1
0
        public ManualImportItem ReprocessItem(string path, string downloadId, int seriesId, int?seasonNumber, List <int> episodeIds, string releaseGroup, QualityModel quality, Language language)
        {
            var rootFolder = Path.GetDirectoryName(path);
            var series     = _seriesService.GetSeries(seriesId);

            if (episodeIds.Any())
            {
                var downloadClientItem = GetTrackedDownload(downloadId)?.DownloadItem;

                var localEpisode = new LocalEpisode
                {
                    Series                    = series,
                    Episodes                  = _episodeService.GetEpisodes(episodeIds),
                    FileEpisodeInfo           = Parser.Parser.ParsePath(path),
                    DownloadClientEpisodeInfo = downloadClientItem == null ? null : Parser.Parser.ParseTitle(downloadClientItem.Title),
                    Path         = path,
                    SceneSource  = SceneSource(series, rootFolder),
                    ExistingFile = series.Path.IsParentPath(path),
                    Size         = _diskProvider.GetFileSize(path),
                    ReleaseGroup = releaseGroup.IsNullOrWhiteSpace() ? Parser.Parser.ParseReleaseGroup(path) : releaseGroup,
                    Language     = language == Language.Unknown ? LanguageParser.ParseLanguage(path) : language,
                    Quality      = quality.Quality == Quality.Unknown ? QualityParser.ParseQuality(path) : quality
                };

                return(MapItem(_importDecisionMaker.GetDecision(localEpisode, downloadClientItem), rootFolder, downloadId, null));
            }

            // This case will happen if the user selected a season, but didn't select the episodes in the season then changed the language or quality.
            // Instead of overriding their season selection let it persist and reject it with an appropriate error.

            if (seasonNumber.HasValue)
            {
                var downloadClientItem = GetTrackedDownload(downloadId)?.DownloadItem;

                var localEpisode = new LocalEpisode
                {
                    Series                    = series,
                    Episodes                  = new List <Episode>(),
                    FileEpisodeInfo           = Parser.Parser.ParsePath(path),
                    DownloadClientEpisodeInfo = downloadClientItem == null
                                           ? null
                                           : Parser.Parser.ParseTitle(downloadClientItem.Title),
                    Path         = path,
                    SceneSource  = SceneSource(series, rootFolder),
                    ExistingFile = series.Path.IsParentPath(path),
                    Size         = _diskProvider.GetFileSize(path),
                    ReleaseGroup = releaseGroup.IsNullOrWhiteSpace() ? Parser.Parser.ParseReleaseGroup(path) : releaseGroup,
                    Language     = language == Language.Unknown ? LanguageParser.ParseLanguage(path) : language,
                    Quality      = quality.Quality == Quality.Unknown ? QualityParser.ParseQuality(path) : quality
                };

                return(MapItem(new ImportDecision(localEpisode, new Rejection("Episodes not selected")), rootFolder, downloadId, null));
            }

            return(ProcessFile(rootFolder, rootFolder, path, downloadId, series));
        }
Esempio n. 2
0
        public void GetEpisodes_ValidId_ReturnEpisodes()
        {
            //Arrange
            _episodeService.GetEpisodes(Arg.Any <int>(), Arg.Any <bool>()).Returns(_jsonSerializeService.SerializeObject(_mockEpisodeDto));

            //Act
            var episode = _apiClientMock.GetEpisodes(1, true);

            episode.Wait();

            //Assert
            Assert.AreEqual(_jsonSerializeService.SerializeObject(_mockEpisodeDto), _jsonSerializeService.SerializeObject(episode.Result));
        }
Esempio n. 3
0
        public async Task <IEnumerable <EpisodeDto> > GetEpisodes(int showId, bool includeSpecials = true)
        {
            var json = await _episodeService.GetEpisodes(showId, includeSpecials);

            var episodes = _jsonSerializeService.TryDeserializeObject <IEnumerable <EpisodeDto> >(json);

            if (episodes.success)
            {
                return(episodes.obj);
            }

            throw new InvalidEpisodeException($"Show id: {showId}; Include specials: {includeSpecials}");
        }
Esempio n. 4
0
        public ActionResult NextEpisode()
        {
            var episodes = episodeService.GetEpisodes();

            TvShowViewModel model = converter.Convert(episodes);

            return(View(model));
        }
Esempio n. 5
0
 public RemoteEpisode Map(ParsedEpisodeInfo parsedEpisodeInfo, int seriesId, IEnumerable <int> episodeIds)
 {
     return(new RemoteEpisode
     {
         ParsedEpisodeInfo = parsedEpisodeInfo,
         Series = _seriesService.GetSeries(seriesId),
         Episodes = _episodeService.GetEpisodes(episodeIds)
     });
 }
Esempio n. 6
0
        public RemoteEpisode Map(ParsedEpisodeInfo parsedEpisodeInfo, Int32 seriesId, IEnumerable <Int32> episodeIds)
        {
            var remoteEpisode = new RemoteEpisode
            {
                ParsedEpisodeInfo = parsedEpisodeInfo,
                Series            = _seriesService.GetSeries(seriesId),
                Episodes          = _episodeService.GetEpisodes(episodeIds)
            };

            return(remoteEpisode);
        }
Esempio n. 7
0
        public async Task <IActionResult> GetEpisodes(int seasonId)
        {
            var result = await _episodeService.GetEpisodes(seasonId);

            if (result.ErrorOccurred)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
Esempio n. 8
0
        public void Execute(ManualImportCommand message)
        {
            _logger.ProgressTrace("Manually importing {0} files", message.Files.Count);

            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 parsedEpisodeInfo = Parser.Parser.ParsePath(file.Path) ?? new ParsedEpisodeInfo();
                var mediaInfo         = _videoFileInfoReader.GetMediaInfo(file.Path);
                var existingFile      = series.Path.IsParentPath(file.Path);

                var localEpisode = new LocalEpisode
                {
                    ExistingFile      = false,
                    Episodes          = episodes,
                    MediaInfo         = mediaInfo,
                    ParsedEpisodeInfo = parsedEpisodeInfo,
                    Path    = file.Path,
                    Quality = file.Quality,
                    Series  = series,
                    Size    = 0
                };

                //TODO: Option to copy instead of import
                //TODO: Cleanup non-tracked downloads

                var importDecision = new ImportDecision(localEpisode);

                if (file.DownloadId.IsNullOrWhiteSpace())
                {
                    imported.AddRange(_importApprovedEpisodes.Import(new List <ImportDecision> {
                        importDecision
                    }, !existingFile));
                }

                else
                {
                    var trackedDownload = _trackedDownloadService.Find(file.DownloadId);
                    var importResult    = _importApprovedEpisodes.Import(new List <ImportDecision> {
                        importDecision
                    }, true, trackedDownload.DownloadItem).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;

                if (_diskProvider.FolderExists(trackedDownload.DownloadItem.OutputPath.FullPath))
                {
                    if (_downloadedEpisodesImportService.ShouldDeleteFolder(
                            new DirectoryInfo(trackedDownload.DownloadItem.OutputPath.FullPath),
                            trackedDownload.RemoteEpisode.Series) && !trackedDownload.DownloadItem.IsReadOnly)
                    {
                        _diskProvider.DeleteFolder(trackedDownload.DownloadItem.OutputPath.FullPath, true);
                    }
                }

                if (groupedTrackedDownload.Select(c => c.ImportResult).Count(c => c.Result == ImportResultType.Imported) >= Math.Max(1, trackedDownload.RemoteEpisode.Episodes.Count))
                {
                    trackedDownload.State = TrackedDownloadStage.Imported;
                    _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload));
                }
            }
        }
Esempio n. 9
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,
                    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 = _aggregationService.Augment(localEpisode, trackedDownload?.DownloadItem, false);

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

                //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
                    });
                }
            }

            _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;

                if (_diskProvider.FolderExists(trackedDownload.DownloadItem.OutputPath.FullPath))
                {
                    if (_downloadedEpisodesImportService.ShouldDeleteFolder(
                            new DirectoryInfo(trackedDownload.DownloadItem.OutputPath.FullPath), importedSeries) &&
                        trackedDownload.DownloadItem.CanMoveFiles)
                    {
                        _diskProvider.DeleteFolder(trackedDownload.DownloadItem.OutputPath.FullPath, 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);

                if (allEpisodesImported)
                {
                    trackedDownload.State = TrackedDownloadState.Imported;
                    _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload, importedSeries.Id));
                }
            }
        }
Esempio n. 10
0
 public void GetEpisodes()
 {
     _episodeService.GetEpisodes("next-episode.csv");
 }
Esempio n. 11
0
 // GET: Episode
 public ActionResult Index()
 {
     return(View(_episodeService.GetEpisodes()));
 }