Esempio n. 1
0
        public bool GetArtwork(DBMovieInfo movie)
        {
            if (movie == null)
            {
                return(false);
            }

            string mmId = getMovieMeterID(movie);

            if (mmId != null)
            {
                FilmDetail film = Api.GetMovieDetails(mmId);
                if (film != null)
                {
                    if (film.thumbnail != null)
                    {
                        string coverPath = film.thumbnail.Replace(@"/thumbs/", @"/");
                        if (movie.AddCoverFromURL(coverPath) == ImageLoadResults.SUCCESS)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Esempio n. 2
0
        public bool GetArtwork(DBMovieInfo movie)
        {
            if (movie == null)
            {
                return(false);
            }

            // do we have an id?
            string tmdbID = getTheMovieDbId(movie, true);

            if (tmdbID == null)
            {
                return(false);
            }

            // try to get movie artwork
            var movieArtwork = TheMovieDbAPI.GetMovieImages(tmdbID);

            if (movieArtwork == null || movieArtwork.Posters == null || movieArtwork.Posters.Count == 0)
            {
                return(false);
            }

            // filter out minimum size images
            int minWidth  = MovingPicturesCore.Settings.MinimumCoverWidth;
            int minHeight = MovingPicturesCore.Settings.MinimumCoverHeight;

            movieArtwork.Posters.RemoveAll(p => p.Width < minWidth || p.Height < minHeight);
            if (movieArtwork.Posters.Count == 0)
            {
                return(false);
            }

            // filter posters by language
            var langPosters = movieArtwork.Posters.Where(p => p.LanguageCode == MovingPicturesCore.Settings.DataProviderLanguageCode);

            if (MovingPicturesCore.Settings.DataProviderLanguageCode == "en")
            {
                // include no language posters with english (sometimes language is not assigned)
                langPosters = langPosters.Union(movieArtwork.Posters.Where(p => p.LanguageCode == null));
            }
            // if no localised posters available use all posters
            if (langPosters.Count() == 0)
            {
                langPosters = movieArtwork.Posters;
            }

            // sort by highest rated / most popular
            langPosters = langPosters.OrderByDescending(p => p.Score);

            // grab coverart loading settings
            int maxCovers          = MovingPicturesCore.Settings.MaxCoversPerMovie;
            int maxCoversInSession = MovingPicturesCore.Settings.MaxCoversPerSession;
            int coversAdded        = 0;

            // get the base url for images
            string baseImageUrl = getImageBaseUrl();

            if (string.IsNullOrEmpty(baseImageUrl))
            {
                return(false);
            }

            // download posters
            foreach (var poster in langPosters)
            {
                // if we have hit our limit quit
                if (movie.AlternateCovers.Count >= maxCovers || coversAdded >= maxCoversInSession)
                {
                    return(true);
                }

                // get url for cover and load it via the movie object
                string coverPath = baseImageUrl + poster.FilePath;
                if (coverPath.Trim() != string.Empty)
                {
                    if (movie.AddCoverFromURL(coverPath) == ImageLoadResults.SUCCESS)
                    {
                        coversAdded++;
                    }
                }
            }

            if (coversAdded > 0)
            {
                // Update source info
                movie.GetSourceMovieInfo(SourceInfo).Identifier = tmdbID;
                return(true);
            }

            return(false);
        }
Esempio n. 3
0
        public bool GetArtwork(DBMovieInfo movie)
        {
            if (movie == null)
            {
                return(false);
            }

            // do we have an id?
            string movieId = getMovieId(movie);

            if (string.IsNullOrEmpty(movieId))
            {
                return(false);
            }

            string url = apiMovieArtwork;

            if (!string.IsNullOrEmpty(MovingPicturesCore.Settings.FanartTVClientKey))
            {
                url = url + "&client_key=" + MovingPicturesCore.Settings.FanartTVClientKey;
            }

            // try to get movie artwork
            string response = getJson(string.Format(apiMovieArtwork, movieId));

            if (response == null)
            {
                return(false);
            }

            // de-serialize json response
            var movieImages = response.FromJson <Artwork>();

            if (movieImages == null)
            {
                return(false);
            }

            // check if we have any posters
            if (movieImages.movieposter == null || movieImages.movieposter.Count == 0)
            {
                return(false);
            }

            // filter posters by language
            var langPosters = movieImages.movieposter.Where(p => p.lang == MovingPicturesCore.Settings.DataProviderLanguageCode);

            // if no localised posters available use all posters
            if (langPosters.Count() == 0)
            {
                langPosters = movieImages.movieposter;
            }

            // sort by highest rated / most popular
            langPosters = langPosters.OrderByDescending(p => p.likes);

            // grab coverart loading settings
            int maxCovers          = MovingPicturesCore.Settings.MaxCoversPerMovie;
            int maxCoversInSession = MovingPicturesCore.Settings.MaxCoversPerSession;
            int coversAdded        = 0;

            // download posters
            foreach (var poster in langPosters)
            {
                // if we have hit our limit quit
                if (movie.AlternateCovers.Count >= maxCovers || coversAdded >= maxCoversInSession)
                {
                    return(true);
                }

                // get url for cover and load it via the movie object
                string coverPath = poster.url;
                if (coverPath.Trim() != string.Empty)
                {
                    if (movie.AddCoverFromURL(coverPath) == ImageLoadResults.SUCCESS)
                    {
                        coversAdded++;
                    }
                }
            }

            if (coversAdded > 0)
            {
                // Update source info
                movie.GetSourceMovieInfo(SourceInfo).Identifier = movieId;
                return(true);
            }

            return(false);
        }
Esempio n. 4
0
        public bool GetArtwork(DBMovieInfo movie)
        {
            if (scraper == null)
            {
                return(false);
            }

            Dictionary <string, string> paramList = new Dictionary <string, string>();
            Dictionary <string, string> results;

            // grab coverart loading settings
            int maxCovers          = MovingPicturesCore.Settings.MaxCoversPerMovie;
            int maxCoversInSession = MovingPicturesCore.Settings.MaxCoversPerSession;

            // if we have already hit our limit for the number of covers to load, quit
            if (movie.AlternateCovers.Count >= maxCovers)
            {
                return(true);
            }

            // try to load the id for the movie for this script
            DBSourceMovieInfo idObj = movie.GetSourceMovieInfo(ScriptID);

            if (idObj != null && idObj.Identifier != null)
            {
                paramList["movie.site_id"] = idObj.Identifier;
            }

            // load params for scraper
            foreach (DBField currField in DBField.GetFieldList(typeof(DBMovieInfo)))
            {
                if (currField.GetValue(movie) != null)
                {
                    paramList["movie." + currField.FieldName] = currField.GetValue(movie).ToString().Trim();
                }
            }

            //set higher level settings for script to use
            paramList["settings.defaultuseragent"] = MovingPicturesCore.Settings.UserAgent;
            paramList["settings.mepo_data"]        = Config.GetFolder(Config.Dir.Config);

            // run the scraper
            results = scraper.Execute("get_cover_art", paramList);
            if (results == null)
            {
                logger.Error(Name + " scraper script failed to execute \"get_cover_art\" node.");
                return(false);
            }

            int coversAdded = 0;
            int count       = 0;

            while (results.ContainsKey("cover_art[" + count + "].url") || results.ContainsKey("cover_art[" + count + "].file"))
            {
                // if we have hit our limit quit
                if (movie.AlternateCovers.Count >= maxCovers || coversAdded >= maxCoversInSession)
                {
                    return(true);
                }

                // get url for cover and load it via the movie object
                if (results.ContainsKey("cover_art[" + count + "].url"))
                {
                    string coverPath = results["cover_art[" + count + "].url"];
                    if (coverPath.Trim() != string.Empty)
                    {
                        if (movie.AddCoverFromURL(coverPath) == ImageLoadResults.SUCCESS)
                        {
                            coversAdded++;
                        }
                    }
                }

                // get file for cover and load it via the movie object
                if (results.ContainsKey("cover_art[" + count + "].file"))
                {
                    string coverPath = results["cover_art[" + count + "].file"];
                    if (coverPath.Trim() != string.Empty)
                    {
                        if (movie.AddCoverFromFile(coverPath))
                        {
                            coversAdded++;
                        }
                    }
                }

                count++;
            }

            if (coversAdded > 0)
            {
                return(true);
            }

            return(false);
        }