Ejemplo n.º 1
0
        private void PopulateSeasonImagesFromSeriesFolder(Season season, List<LocalImageInfo> images, IDirectoryService directoryService)
        {
            var seasonNumber = season.IndexNumber;

            var series = season.Series;
            if (!seasonNumber.HasValue || series.LocationType != LocationType.FileSystem)
            {
                return;
            }

            var seriesFiles = GetFiles(series, false, directoryService).ToList();

            // Try using the season name
            var prefix = season.Name.ToLower().Replace(" ", string.Empty);

            var filenamePrefixes = new List<string> { prefix };

            var seasonMarker = seasonNumber.Value == 0
                                   ? "-specials"
                                   : seasonNumber.Value.ToString("00", _usCulture);

            // Get this one directly from the file system since we have to go up a level
            if (!string.Equals(prefix, seasonMarker, StringComparison.OrdinalIgnoreCase))
            {
                filenamePrefixes.Add("season" + seasonMarker);
            }

            foreach (var filename in filenamePrefixes)
            {
                AddImage(seriesFiles, images, filename + "-poster", ImageType.Primary);
                AddImage(seriesFiles, images, filename + "-fanart", ImageType.Backdrop);
                AddImage(seriesFiles, images, filename + "-banner", ImageType.Banner);
                AddImage(seriesFiles, images, filename + "-landscape", ImageType.Thumb);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds the season.
        /// </summary>
        /// <param name="series">The series.</param>
        /// <param name="seasonNumber">The season number.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task{Season}.</returns>
        private async Task<Season> AddSeason(Series series, int seasonNumber, CancellationToken cancellationToken)
        {
            _logger.Info("Creating Season {0} entry for {1}", seasonNumber, series.Name);

            var name = seasonNumber == 0 ? _config.Configuration.SeasonZeroDisplayName : string.Format("Season {0}", seasonNumber.ToString(UsCulture));

            var season = new Season
            {
                Name = name,
                IndexNumber = seasonNumber,
                Parent = series,
                DisplayMediaType = typeof(Season).Name,
                Id = (series.Id + seasonNumber.ToString(UsCulture) + name).GetMBId(typeof(Season))
            };

            await series.AddChild(season, cancellationToken).ConfigureAwait(false);

            await season.RefreshMetadata(new MetadataRefreshOptions(), cancellationToken).ConfigureAwait(false);

            return season;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Fetches the images.
        /// </summary>
        /// <param name="season">The season.</param>
        /// <param name="images">The images.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task.</returns>
        private async Task FetchImages(Season season, XmlDocument images, CancellationToken cancellationToken)
        {
            var seasonNumber = season.IndexNumber ?? -1;

            if (seasonNumber == -1)
            {
                return;
            }

            if (!season.HasImage(ImageType.Primary))
            {
                var n = images.SelectSingleNode("//Banner[BannerType='season'][BannerType2='season'][Season='" + seasonNumber + "'][Language='" + ConfigurationManager.Configuration.PreferredMetadataLanguage + "']") ??
                        images.SelectSingleNode("//Banner[BannerType='season'][BannerType2='season'][Season='" + seasonNumber + "'][Language='en']");
                if (n != null)
                {
                    n = n.SelectSingleNode("./BannerPath");

                    if (n != null)
                    {
                        var url = TVUtils.BannerUrl + n.InnerText;

                        await _providerManager.SaveImage(season, url, RemoteSeriesProvider.Current.TvDbResourcePool, ImageType.Primary, null, cancellationToken)
                          .ConfigureAwait(false);
                    }
                }
            }

            if (ConfigurationManager.Configuration.DownloadSeasonImages.Banner && !season.HasImage(ImageType.Banner))
            {
                var n = images.SelectSingleNode("//Banner[BannerType='season'][BannerType2='seasonwide'][Season='" + seasonNumber + "'][Language='" + ConfigurationManager.Configuration.PreferredMetadataLanguage + "']") ??
                        images.SelectSingleNode("//Banner[BannerType='season'][BannerType2='seasonwide'][Season='" + seasonNumber + "'][Language='en']");
                if (n != null)
                {
                    n = n.SelectSingleNode("./BannerPath");
                    if (n != null)
                    {
                        try
                        {
                            var url = TVUtils.BannerUrl + n.InnerText;

                            await _providerManager.SaveImage(season, url, RemoteSeriesProvider.Current.TvDbResourcePool, ImageType.Banner, null, cancellationToken)
                              .ConfigureAwait(false);
                        }
                        catch (HttpException ex)
                        {
                            Logger.ErrorException("Error downloading season banner for {0}", ex, season.Path);

                            // Sometimes banners will come up not found even though they're reported in tvdb xml
                            if (ex.StatusCode.HasValue && ex.StatusCode.Value != HttpStatusCode.NotFound)
                            {
                                throw;
                            }
                        }
                    }
                }
            }

            if (ConfigurationManager.Configuration.DownloadSeasonImages.Backdrops && season.BackdropImagePaths.Count == 0)
            {
                var n = images.SelectSingleNode("//Banner[BannerType='fanart'][Season='" + seasonNumber + "']");
                if (n != null)
                {
                    n = n.SelectSingleNode("./BannerPath");
                    if (n != null)
                    {
                        var url = TVUtils.BannerUrl + n.InnerText;

                        await _providerManager.SaveImage(season, url, RemoteSeriesProvider.Current.TvDbResourcePool, ImageType.Backdrop, 0, cancellationToken)
                          .ConfigureAwait(false);

                    }
                }
            }
        }
        private FileSystemInfo GetSeasonImageFromSeriesFolder(Season season, string imageSuffix)
        {
            var series = season.Series;
            var seriesFolderArgs = series.ResolveArgs;

            var seasonNumber = season.IndexNumber;

            string filename = null;
            FileSystemInfo image;

            if (seasonNumber.HasValue)
            {
                var seasonMarker = seasonNumber.Value == 0
                                       ? "-specials"
                                       : seasonNumber.Value.ToString("00", _usCulture);

                // Get this one directly from the file system since we have to go up a level
                filename = "season" + seasonMarker + imageSuffix;

                image = GetImage(series, seriesFolderArgs, filename);

                if (image != null && image.Exists)
                {
                    return image;
                }
            }

            var previousFilename = filename;

            // Try using the season name
            filename = season.Name.ToLower().Replace(" ", string.Empty) + imageSuffix;

            if (!string.Equals(previousFilename, filename))
            {
                image = GetImage(series, seriesFolderArgs, filename);

                if (image != null && image.Exists)
                {
                    return image;
                }
            }

            return null;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Adds the season.
        /// </summary>
        /// <param name="series">The series.</param>
        /// <param name="seasonNumber">The season number.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task{Season}.</returns>
        public async Task<Season> AddSeason(Series series,
            int? seasonNumber,
            CancellationToken cancellationToken)
        {
            var seasonName = seasonNumber == 0 ?
                _config.Configuration.SeasonZeroDisplayName :
                (seasonNumber.HasValue ? string.Format(_localization.GetLocalizedString("NameSeasonNumber"), seasonNumber.Value.ToString(_usCulture)) : _localization.GetLocalizedString("NameSeasonUnknown"));

            _logger.Info("Creating Season {0} entry for {1}", seasonName, series.Name);

            var season = new Season
            {
                Name = seasonName,
                IndexNumber = seasonNumber,
                Id = (series.Id + (seasonNumber ?? -1).ToString(_usCulture) + seasonName).GetMBId(typeof(Season))
            };

            season.SetParent(series);
            
            await series.AddChild(season, cancellationToken).ConfigureAwait(false);

            await season.RefreshMetadata(new MetadataRefreshOptions(_fileSystem), cancellationToken).ConfigureAwait(false);

            return season;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Fetches the images.
        /// </summary>
        /// <param name="season">The season.</param>
        /// <param name="doc">The doc.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task.</returns>
        private async Task FetchImages(Season season, XmlDocument doc, CancellationToken cancellationToken)
        {
            var seasonNumber = season.IndexNumber ?? -1;

            if (seasonNumber == -1)
            {
                return;
            }

            var language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower();
            
            if (ConfigurationManager.Configuration.DownloadSeasonImages.Thumb && !season.HasImage(ImageType.Thumb))
            {
                var node = doc.SelectSingleNode("//fanart/series/seasonthumbs/seasonthumb[@lang = \"" + language + "\"][@season = \"" + seasonNumber + "\"]/@url") ??
                           doc.SelectSingleNode("//fanart/series/seasonthumbs/seasonthumb[@season = \"" + seasonNumber + "\"]/@url");
                
                var path = node != null ? node.Value : null;
                
                if (!string.IsNullOrEmpty(path))
                {
                    season.SetImage(ImageType.Thumb, await _providerManager.DownloadAndSaveImage(season, path, ThumbFile, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
                }
            }
        }
Ejemplo n.º 7
0
        private bool SupportsItem(IHasImages item, ImageType type, Season season)
        {
            if (item.IsOwnedItem || item is Audio || item is User)
            {
                return false;
            }

            if (type != ImageType.Primary && item is Episode)
            {
                return false;
            }

            if (!item.SupportsLocalMetadata)
            {
                return false;
            }

            var locationType = item.LocationType;
            if (locationType == LocationType.Remote || locationType == LocationType.Virtual)
            {
                var allowSaving = false;

                // If season is virtual under a physical series, save locally if using compatible convention
                if (season != null)
                {
                    var series = season.Series;

                    if (series != null && series.SupportsLocalMetadata)
                    {
                        allowSaving = true;
                    }
                }

                if (!allowSaving)
                {
                    return false;
                }
            }

            return true;
        }
Ejemplo n.º 8
0
        public static Season Convert(MazeSeason mazeSeason)
        {
            var season = new Season();

            season.ProviderIds[MetadataProviders.TvMaze.ToString()] = mazeSeason.id.ToString();

            season.Name = mazeSeason.name;

            season.IndexNumber = mazeSeason.number;

            if (mazeSeason.network != null && !string.IsNullOrWhiteSpace(mazeSeason.network.name))
            {
                var networkName = mazeSeason.network.name;
                if (mazeSeason.network.country != null && !string.IsNullOrWhiteSpace(mazeSeason.network.country.code))
                {
                    networkName = string.Format("{0} ({1})", mazeSeason.network.name, mazeSeason.network.country.code);
                }

                season.Studios.Add(networkName);
            }

            if (mazeSeason.premiereDate.HasValue)
            {
                season.PremiereDate = mazeSeason.premiereDate.Value;
                season.ProductionYear = mazeSeason.premiereDate.Value.Year;
            }

            if (mazeSeason.endDate.HasValue)
            {
                season.EndDate = mazeSeason.endDate.Value;
            }

            season.Overview = StripHtml(mazeSeason.summary);

            return season;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Filters the episodes by season.
        /// </summary>
        public static IEnumerable <Episode> FilterEpisodesBySeason(IEnumerable <Episode> episodes, Season parentSeason, bool includeSpecials)
        {
            var seasonNumber          = parentSeason.IndexNumber;
            var seasonPresentationKey = GetUniqueSeriesKey(parentSeason);

            var supportSpecialsInSeason = includeSpecials && seasonNumber.HasValue && seasonNumber.Value != 0;

            return(episodes.Where(episode =>
            {
                var currentSeasonNumber = supportSpecialsInSeason ? episode.AiredSeasonNumber : episode.ParentIndexNumber;
                if (currentSeasonNumber.HasValue && seasonNumber.HasValue && currentSeasonNumber.Value == seasonNumber.Value)
                {
                    return true;
                }

                if (!currentSeasonNumber.HasValue && !seasonNumber.HasValue && parentSeason.LocationType == LocationType.Virtual)
                {
                    return true;
                }

                var season = episode.Season;
                return season != null && string.Equals(GetUniqueSeriesKey(season), seasonPresentationKey, StringComparison.OrdinalIgnoreCase);
            }));
        }
 /// <summary>
 /// Fetches the images.
 /// </summary>
 /// <param name="season">The season.</param>
 /// <param name="images">The images.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns>Task.</returns>
 private async Task FetchImages(Season season, List<RemoteImageInfo> images, CancellationToken cancellationToken)
 {
     if (ConfigurationManager.Configuration.DownloadSeasonImages.Thumb && !season.HasImage(ImageType.Thumb) && !season.LockedFields.Contains(MetadataFields.Images))
     {
         await SaveImage(season, images, ImageType.Thumb, cancellationToken).ConfigureAwait(false);
     }
 }
        /// <summary>
        /// Fetches the images.
        /// </summary>
        /// <param name="season">The season.</param>
        /// <param name="images">The images.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task.</returns>
        private async Task FetchImages(Season season, List<RemoteImageInfo> images, CancellationToken cancellationToken)
        {
            if (ConfigurationManager.Configuration.DownloadSeasonImages.Thumb && !season.HasImage(ImageType.Thumb))
            {
                var image = images.FirstOrDefault(i => i.Type == ImageType.Thumb);

                if (image != null)
                {
                    await _providerManager.SaveImage(season, image.Url, FanArtResourcePool, ImageType.Thumb, null, cancellationToken).ConfigureAwait(false);
                }
            }
        }