示例#1
0
        /// <inheritdoc />
        public async Task Run(TaskParameters arguments, IProgress <float> progress, CancellationToken cancellationToken)
        {
            string path = arguments["path"].As <string>();

            try
            {
                progress.Report(0);
                Track track = await _identifier.IdentifyTrack(path);

                progress.Report(25);

                if (track.Episode == null)
                {
                    throw new TaskFailedException($"No episode identified for the track at {path}");
                }
                if (track.Episode.ID == 0)
                {
                    if (track.Episode.Slug != null)
                    {
                        track.Episode = await _libraryManager.Get <Episode>(track.Episode.Slug);
                    }
                    else if (track.Episode.Path != null)
                    {
                        track.Episode = await _libraryManager.GetOrDefault <Episode>(x => x.Path.StartsWith(track.Episode.Path));

                        if (track.Episode == null)
                        {
                            throw new TaskFailedException($"No episode found for the track at: {path}.");
                        }
                    }
                    else
                    {
                        throw new TaskFailedException($"No episode identified for the track at {path}");
                    }
                }

                progress.Report(50);
                await _libraryManager.Create(track);

                progress.Report(100);
            }
            catch (IdentificationFailedException ex)
            {
                throw new TaskFailedException(ex);
            }
        }
示例#2
0
        /// <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);
            }
        }