Пример #1
0
        /// <summary>
        /// Gets the TMDB settings.
        /// </summary>
        /// <returns>Task{TmdbSettingsResult}.</returns>
        internal async Task <TmdbSettingsResult> GetTmdbSettings(CancellationToken cancellationToken)
        {
            if (_tmdbSettings != null)
            {
                return(_tmdbSettings);
            }

            using (var response = await GetMovieDbResponse(new HttpRequestOptions
            {
                Url = string.Format(TmdbConfigUrl, ApiKey),
                CancellationToken = cancellationToken,
                AcceptHeader = AcceptHeader
            }).ConfigureAwait(false))
            {
                using (var json = response.Content)
                {
                    _tmdbSettings = await _jsonSerializer.DeserializeFromStreamAsync <TmdbSettingsResult>(json).ConfigureAwait(false);

                    return(_tmdbSettings);
                }
            }
        }
Пример #2
0
        private void ProcessMainInfo(MetadataResult <Series> seriesResult, RootObject seriesInfo, string preferredCountryCode, TmdbSettingsResult settings)
        {
            var series = seriesResult.Item;

            series.Name = seriesInfo.name;
            series.SetProviderId(MetadataProviders.Tmdb, seriesInfo.id.ToString(_usCulture));

            //series.VoteCount = seriesInfo.vote_count;

            string voteAvg = seriesInfo.vote_average.ToString(CultureInfo.InvariantCulture);
            float  rating;

            if (float.TryParse(voteAvg, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out rating))
            {
                series.CommunityRating = rating;
            }

            series.Overview = seriesInfo.overview;

            if (seriesInfo.networks != null)
            {
                series.Studios = seriesInfo.networks.Select(i => i.name).ToArray(seriesInfo.networks.Count);
            }

            if (seriesInfo.genres != null)
            {
                series.Genres = seriesInfo.genres.Select(i => i.name).ToArray();
            }

            //series.HomePageUrl = seriesInfo.homepage;

            series.RunTimeTicks = seriesInfo.episode_run_time.Select(i => TimeSpan.FromMinutes(i).Ticks).FirstOrDefault();

            if (string.Equals(seriesInfo.status, "Ended", StringComparison.OrdinalIgnoreCase))
            {
                series.Status  = SeriesStatus.Ended;
                series.EndDate = seriesInfo.last_air_date;
            }
            else
            {
                series.Status = SeriesStatus.Continuing;
            }

            series.PremiereDate = seriesInfo.first_air_date;

            var ids = seriesInfo.external_ids;

            if (ids != null)
            {
                if (!string.IsNullOrWhiteSpace(ids.imdb_id))
                {
                    series.SetProviderId(MetadataProviders.Imdb, ids.imdb_id);
                }
                if (ids.tvrage_id > 0)
                {
                    series.SetProviderId(MetadataProviders.TvRage, ids.tvrage_id.ToString(_usCulture));
                }
                if (ids.tvdb_id > 0)
                {
                    series.SetProviderId(MetadataProviders.Tvdb, ids.tvdb_id.ToString(_usCulture));
                }
            }

            var contentRatings = (seriesInfo.content_ratings ?? new ContentRatings()).results ?? new List <ContentRating>();

            var ourRelease     = contentRatings.FirstOrDefault(c => string.Equals(c.iso_3166_1, preferredCountryCode, StringComparison.OrdinalIgnoreCase));
            var usRelease      = contentRatings.FirstOrDefault(c => string.Equals(c.iso_3166_1, "US", StringComparison.OrdinalIgnoreCase));
            var minimumRelease = contentRatings.FirstOrDefault();

            if (ourRelease != null)
            {
                series.OfficialRating = ourRelease.rating;
            }
            else if (usRelease != null)
            {
                series.OfficialRating = usRelease.rating;
            }
            else if (minimumRelease != null)
            {
                series.OfficialRating = minimumRelease.rating;
            }

            if (seriesInfo.videos != null && seriesInfo.videos.results != null)
            {
                foreach (var video in seriesInfo.videos.results)
                {
                    if (video.type.Equals("trailer", System.StringComparison.OrdinalIgnoreCase) ||
                        video.type.Equals("clip", System.StringComparison.OrdinalIgnoreCase))
                    {
                        if (video.site.Equals("youtube", System.StringComparison.OrdinalIgnoreCase))
                        {
                            var videoUrl = string.Format("http://www.youtube.com/watch?v={0}", video.key);
                            series.AddTrailerUrl(videoUrl);
                        }
                    }
                }
            }

            seriesResult.ResetPeople();
            var tmdbImageUrl = settings.images.GetImageUrl("original");

            if (seriesInfo.credits != null && seriesInfo.credits.cast != null)
            {
                foreach (var actor in seriesInfo.credits.cast.OrderBy(a => a.order))
                {
                    var personInfo = new PersonInfo
                    {
                        Name = actor.name.Trim(),
                        Role = actor.character,
                        Type = PersonType.Actor
                    };

                    if (!string.IsNullOrWhiteSpace(actor.profile_path))
                    {
                        personInfo.ImageUrl = tmdbImageUrl + actor.profile_path;
                    }

                    if (actor.id > 0)
                    {
                        personInfo.SetProviderId(MetadataProviders.Tmdb, actor.id.ToString(CultureInfo.InvariantCulture));
                    }

                    seriesResult.AddPerson(personInfo);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Processes the main info.
        /// </summary>
        /// <param name="resultItem">The result item.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="preferredCountryCode">The preferred country code.</param>
        /// <param name="movieData">The movie data.</param>
        private void ProcessMainInfo(MetadataResult <T> resultItem, TmdbSettingsResult settings, string preferredCountryCode, MovieDbProvider.CompleteMovieData movieData)
        {
            var movie = resultItem.Item;

            movie.Name = movieData.GetTitle() ?? movie.Name;

            movie.OriginalTitle = movieData.GetOriginalTitle();

            movie.Overview = string.IsNullOrWhiteSpace(movieData.overview) ? null : WebUtility.HtmlDecode(movieData.overview);
            movie.Overview = movie.Overview != null?movie.Overview.Replace("\n\n", "\n") : null;

            //movie.HomePageUrl = movieData.homepage;

            if (!string.IsNullOrEmpty(movieData.tagline))
            {
                movie.Tagline = movieData.tagline;
            }

            if (movieData.production_countries != null)
            {
                movie.ProductionLocations = movieData
                                            .production_countries
                                            .Select(i => i.name)
                                            .ToArray(movieData.production_countries.Count);
            }

            movie.SetProviderId(MetadataProviders.Tmdb, movieData.id.ToString(_usCulture));
            movie.SetProviderId(MetadataProviders.Imdb, movieData.imdb_id);

            if (movieData.belongs_to_collection != null)
            {
                movie.SetProviderId(MetadataProviders.TmdbCollection,
                                    movieData.belongs_to_collection.id.ToString(CultureInfo.InvariantCulture));

                var movieItem = movie as Movie;

                if (movieItem != null)
                {
                    movieItem.CollectionName = movieData.belongs_to_collection.name;
                }
            }

            float  rating;
            string voteAvg = movieData.vote_average.ToString(CultureInfo.InvariantCulture);

            if (float.TryParse(voteAvg, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out rating))
            {
                movie.CommunityRating = rating;
            }

            //movie.VoteCount = movieData.vote_count;

            if (movieData.releases != null && movieData.releases.countries != null)
            {
                var releases = movieData.releases.countries.Where(i => !string.IsNullOrWhiteSpace(i.certification)).ToList();

                var ourRelease = releases.FirstOrDefault(c => string.Equals(c.iso_3166_1, preferredCountryCode, StringComparison.OrdinalIgnoreCase));
                var usRelease  = releases.FirstOrDefault(c => string.Equals(c.iso_3166_1, "US", StringComparison.OrdinalIgnoreCase));

                if (ourRelease != null)
                {
                    var ratingPrefix = string.Equals(preferredCountryCode, "us", StringComparison.OrdinalIgnoreCase) ? "" : preferredCountryCode + "-";
                    var newRating    = ratingPrefix + ourRelease.certification;

                    newRating = newRating.Replace("de-", "FSK-", StringComparison.OrdinalIgnoreCase);

                    movie.OfficialRating = newRating;
                }
                else if (usRelease != null)
                {
                    movie.OfficialRating = usRelease.certification;
                }
            }

            if (!string.IsNullOrWhiteSpace(movieData.release_date))
            {
                DateTimeOffset r;

                // These dates are always in this exact format
                if (DateTimeOffset.TryParse(movieData.release_date, _usCulture, DateTimeStyles.None, out r))
                {
                    movie.PremiereDate   = r.ToUniversalTime();
                    movie.ProductionYear = movie.PremiereDate.Value.Year;
                }
            }

            //studios
            if (movieData.production_companies != null)
            {
                movie.SetStudios(movieData.production_companies.Select(c => c.name));
            }

            // genres
            // Movies get this from imdb
            var genres = movieData.genres ?? new List <MovieDbProvider.GenreItem>();

            foreach (var genre in genres.Select(g => g.name))
            {
                movie.AddGenre(genre);
            }

            resultItem.ResetPeople();
            var tmdbImageUrl = settings.images.GetImageUrl("original");

            //Actors, Directors, Writers - all in People
            //actors come from cast
            if (movieData.casts != null && movieData.casts.cast != null)
            {
                foreach (var actor in movieData.casts.cast.OrderBy(a => a.order))
                {
                    var personInfo = new PersonInfo
                    {
                        Name = actor.name.Trim(),
                        Role = actor.character,
                        Type = PersonType.Actor
                    };

                    if (!string.IsNullOrWhiteSpace(actor.profile_path))
                    {
                        personInfo.ImageUrl = tmdbImageUrl + actor.profile_path;
                    }

                    if (actor.id > 0)
                    {
                        personInfo.SetProviderId(MetadataProviders.Tmdb, actor.id.ToString(CultureInfo.InvariantCulture));
                    }

                    resultItem.AddPerson(personInfo);
                }
            }

            //and the rest from crew
            if (movieData.casts != null && movieData.casts.crew != null)
            {
                var keepTypes = new[]
                {
                    PersonType.Director,
                    //PersonType.Writer,
                    //PersonType.Producer
                };

                foreach (var person in movieData.casts.crew)
                {
                    // Normalize this
                    PersonType type       = PersonType.Lyricist;
                    var        department = person.department;
                    if (string.Equals(department, "writing", StringComparison.OrdinalIgnoreCase))
                    {
                        type = PersonType.Writer;
                    }

                    PersonType parsedType;
                    if (Enum.TryParse(department, true, out parsedType))
                    {
                        type = parsedType;
                    }
                    else if (Enum.TryParse(person.job, true, out parsedType))
                    {
                        type = parsedType;
                    }

                    if (!keepTypes.Contains(type))
                    {
                        continue;
                    }

                    var personInfo = new PersonInfo
                    {
                        Name = person.name.Trim(),
                        Role = person.job,
                        Type = type
                    };

                    if (!string.IsNullOrWhiteSpace(person.profile_path))
                    {
                        personInfo.ImageUrl = tmdbImageUrl + person.profile_path;
                    }

                    if (person.id > 0)
                    {
                        personInfo.SetProviderId(MetadataProviders.Tmdb, person.id.ToString(CultureInfo.InvariantCulture));
                    }

                    resultItem.AddPerson(personInfo);
                }
            }

            //if (movieData.keywords != null && movieData.keywords.keywords != null)
            //{
            //    movie.Keywords = movieData.keywords.keywords.Select(i => i.name).ToList();
            //}

            if (movieData.trailers != null && movieData.trailers.youtube != null)
            {
                movie.RemoteTrailers = movieData.trailers.youtube.Select(i => new MediaUrl
                {
                    Url  = string.Format("https://www.youtube.com/watch?v={0}", i.source),
                    Name = i.name
                }).ToArray();
            }
        }