Ejemplo n.º 1
0
        public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken)
        {
            var episode = (Controller.Entities.TV.Episode)item;
            var series  = episode.Series;

            var seriesTmdbId = Convert.ToInt32(series?.GetProviderId(MetadataProvider.Tmdb), CultureInfo.InvariantCulture);

            if (seriesTmdbId <= 0)
            {
                return(Enumerable.Empty <RemoteImageInfo>());
            }

            var seasonNumber  = episode.ParentIndexNumber;
            var episodeNumber = episode.IndexNumber;

            if (!seasonNumber.HasValue || !episodeNumber.HasValue)
            {
                return(Enumerable.Empty <RemoteImageInfo>());
            }

            var language = item.GetPreferredMetadataLanguage();

            // TODO use image languages if All Languages isn't toggled, but there's currently no way to get that value in here
            var episodeResult = await _tmdbClientManager
                                .GetEpisodeAsync(seriesTmdbId, seasonNumber.Value, episodeNumber.Value, null, null, cancellationToken)
                                .ConfigureAwait(false);

            var stills = episodeResult?.Images?.Stills;

            if (stills == null)
            {
                return(Enumerable.Empty <RemoteImageInfo>());
            }

            var remoteImages = new RemoteImageInfo[stills.Count];

            for (var i = 0; i < stills.Count; i++)
            {
                var image = stills[i];
                remoteImages[i] = new RemoteImageInfo
                {
                    Url             = _tmdbClientManager.GetStillUrl(image.FilePath),
                    CommunityRating = image.VoteAverage,
                    VoteCount       = image.VoteCount,
                    Width           = image.Width,
                    Height          = image.Height,
                    Language        = TmdbUtils.AdjustImageLanguage(image.Iso_639_1, language),
                    ProviderName    = Name,
                    Type            = ImageType.Primary,
                    RatingType      = RatingType.Score
                };
            }

            return(remoteImages.OrderByLanguageDescending(language));
        }
Ejemplo n.º 2
0
        public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken)
        {
            var episode = (Controller.Entities.TV.Episode)item;
            var series  = episode.Series;

            var seriesTmdbId = Convert.ToInt32(series?.GetProviderId(MetadataProvider.Tmdb), CultureInfo.InvariantCulture);

            if (seriesTmdbId <= 0)
            {
                return(Enumerable.Empty <RemoteImageInfo>());
            }

            var seasonNumber  = episode.ParentIndexNumber;
            var episodeNumber = episode.IndexNumber;

            if (!seasonNumber.HasValue || !episodeNumber.HasValue)
            {
                return(Enumerable.Empty <RemoteImageInfo>());
            }

            var language = item.GetPreferredMetadataLanguage();

            // TODO use image languages if All Languages isn't toggled, but there's currently no way to get that value in here
            var episodeResult = await _tmdbClientManager
                                .GetEpisodeAsync(seriesTmdbId, seasonNumber.Value, episodeNumber.Value, series.EpisodeGroupId, null, null, cancellationToken)
                                .ConfigureAwait(false);

            var stills = episodeResult?.Images?.Stills;

            if (stills == null)
            {
                return(Enumerable.Empty <RemoteImageInfo>());
            }

            var remoteImages = new List <RemoteImageInfo>(stills.Count);

            _tmdbClientManager.ConvertStillsToRemoteImageInfo(stills, language, remoteImages);

            return(remoteImages);
        }
Ejemplo n.º 3
0
        public async Task <MetadataResult <Episode> > GetMetadata(EpisodeInfo info, CancellationToken cancellationToken)
        {
            var metadataResult = new MetadataResult <Episode>();

            // Allowing this will dramatically increase scan times
            if (info.IsMissingEpisode)
            {
                return(metadataResult);
            }

            info.SeriesProviderIds.TryGetValue(MetadataProvider.Tmdb.ToString(), out string tmdbId);

            var seriesTmdbId = Convert.ToInt32(tmdbId, CultureInfo.InvariantCulture);

            if (seriesTmdbId <= 0)
            {
                return(metadataResult);
            }

            var seasonNumber  = info.ParentIndexNumber;
            var episodeNumber = info.IndexNumber;

            if (!seasonNumber.HasValue || !episodeNumber.HasValue)
            {
                return(metadataResult);
            }

            var episodeResult = await _tmdbClientManager
                                .GetEpisodeAsync(seriesTmdbId, seasonNumber.Value, episodeNumber.Value, info.MetadataLanguage, TmdbUtils.GetImageLanguagesParam(info.MetadataLanguage), cancellationToken)
                                .ConfigureAwait(false);

            if (episodeResult == null)
            {
                return(metadataResult);
            }

            metadataResult.HasMetadata = true;
            metadataResult.QueriedById = true;

            if (!string.IsNullOrEmpty(episodeResult.Overview))
            {
                // if overview is non-empty, we can assume that localized data was returned
                metadataResult.ResultLanguage = info.MetadataLanguage;
            }

            var item = new Episode
            {
                Name              = info.Name,
                IndexNumber       = info.IndexNumber,
                ParentIndexNumber = info.ParentIndexNumber,
                IndexNumberEnd    = info.IndexNumberEnd
            };

            if (!string.IsNullOrEmpty(episodeResult.ExternalIds?.TvdbId))
            {
                item.SetProviderId(MetadataProvider.Tvdb, episodeResult.ExternalIds.TvdbId);
            }

            item.PremiereDate   = episodeResult.AirDate;
            item.ProductionYear = episodeResult.AirDate?.Year;

            item.Name     = episodeResult.Name;
            item.Overview = episodeResult.Overview;

            item.CommunityRating = Convert.ToSingle(episodeResult.VoteAverage);

            if (episodeResult.Videos?.Results != null)
            {
                foreach (var video in episodeResult.Videos.Results)
                {
                    if (TmdbUtils.IsTrailerType(video))
                    {
                        item.AddTrailerUrl("https://www.youtube.com/watch?v=" + video.Key);
                    }
                }
            }

            var credits = episodeResult.Credits;

            if (credits?.Cast != null)
            {
                foreach (var actor in credits.Cast.OrderBy(a => a.Order).Take(TmdbUtils.MaxCastMembers))
                {
                    metadataResult.AddPerson(new PersonInfo
                    {
                        Name      = actor.Name.Trim(),
                        Role      = actor.Character,
                        Type      = PersonType.Actor,
                        SortOrder = actor.Order
                    });
                }
            }

            if (credits?.GuestStars != null)
            {
                foreach (var guest in credits.GuestStars.OrderBy(a => a.Order).Take(TmdbUtils.MaxCastMembers))
                {
                    metadataResult.AddPerson(new PersonInfo
                    {
                        Name      = guest.Name.Trim(),
                        Role      = guest.Character,
                        Type      = PersonType.GuestStar,
                        SortOrder = guest.Order
                    });
                }
            }

            // and the rest from crew
            if (credits?.Crew != null)
            {
                foreach (var person in credits.Crew)
                {
                    // Normalize this
                    var type = TmdbUtils.MapCrewToPersonType(person);

                    if (!TmdbUtils.WantedCrewTypes.Contains(type, StringComparer.OrdinalIgnoreCase) &&
                        !TmdbUtils.WantedCrewTypes.Contains(person.Job ?? string.Empty, StringComparer.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    metadataResult.AddPerson(new PersonInfo
                    {
                        Name = person.Name.Trim(),
                        Role = person.Job,
                        Type = type
                    });
                }
            }

            metadataResult.Item = item;

            return(metadataResult);
        }