public async Task EpisodeIdentification() { _manager.Setup(x => x.GetAll(null, new Sort <Library>(), default)).ReturnsAsync(new[] { new Library { Paths = new [] { "/kyoo/Library/" } } }); (Collection collection, Show show, Season season, Episode episode) = await _identifier.Identify( "/kyoo/Library/Collection/Show (2000)/Show S01E01.extension"); Assert.Equal("Collection", collection.Name); Assert.Equal("collection", collection.Slug); Assert.Equal("Show", show.Title); Assert.Equal("show", show.Slug); Assert.Equal(2000, show.StartAir !.Value.Year); Assert.Equal(1, season.SeasonNumber); Assert.Equal(1, episode.SeasonNumber); Assert.Equal(1, episode.EpisodeNumber); Assert.Null(episode.AbsoluteNumber); }
/// <inheritdoc /> public async Task Run(TaskParameters arguments, IProgress <float> progress, CancellationToken cancellationToken) { string path = arguments["path"].As <string>(); Library library = arguments["library"].As <Library>(); progress.Report(0); if (library != null) { if (library.Providers == null) { await _libraryManager.Load(library, x => x.Providers); } _metadataProvider.UseProviders(library.Providers); } try { (Collection collection, Show show, Season season, Episode episode) = await _identifier.Identify(path); progress.Report(15); collection = await _RegisterAndFill(collection); progress.Report(20); Show registeredShow = await _RegisterAndFill(show); if (registeredShow.Path != show.Path) { if (show.StartAir.HasValue) { show.Slug += $"-{show.StartAir.Value.Year}"; show = await _libraryManager.Create(show); } else { throw new TaskFailedException($"Duplicated show found ({show.Slug}) " + $"at {registeredShow.Path} and {show.Path}"); } } else { show = registeredShow; } progress.Report(50); if (season != null) { season.Show = show; } season = await _RegisterAndFill(season); progress.Report(60); episode.Show = show; episode.Season = season; if (!show.IsMovie) { episode = await _metadataProvider.Get(episode); } progress.Report(70); episode.Tracks = await _transcoder.ExtractInfos(episode, false); await _thumbnailsManager.DownloadImages(episode); progress.Report(90); await _libraryManager.Create(episode); progress.Report(95); await _libraryManager.AddShowLink(show, library, collection); progress.Report(100); } catch (IdentificationFailedException ex) { throw new TaskFailedException(ex); } catch (DuplicatedItemException ex) { throw new TaskFailedException(ex); } }