/// <inheritdoc /> public async Task Run(TaskParameters arguments, IProgress <float> progress, CancellationToken cancellationToken) { float percent = 0; progress.Report(0); foreach (IMetadataProvider provider in _metadataProviders) { if (string.IsNullOrEmpty(provider.Provider.Slug)) { throw new TaskFailedException($"Empty provider slug (name: {provider.Provider.Name})."); } await _providers.CreateIfNotExists(provider.Provider); await _thumbnails.DownloadImages(provider.Provider); percent += 100f / _metadataProviders.Count; progress.Report(percent); } progress.Report(100); }
/// <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); } }