Ejemplo n.º 1
0
        private string getTheMovieDbId(DBMovieInfo movie, bool fuzzyMatch)
        {
            // check for internally stored TMDb ID
            DBSourceMovieInfo idObj = movie.GetSourceMovieInfo(SourceInfo);

            if (idObj != null && idObj.Identifier != null)
            {
                return(idObj.Identifier);
            }

            // if available, lookup based on IMDb ID
            else if (movie.ImdbID != null && movie.ImdbID.Trim().Length == 9)
            {
                string imdbId    = movie.ImdbID.Trim();
                var    movieInfo = TheMovieDbAPI.GetMovieInfo(imdbId);
                if (movieInfo != null)
                {
                    return(movieInfo.Id.ToString());
                }
            }

            // if asked for, do a fuzzy match based on title and year
            else if (fuzzyMatch)
            {
                // grab possible matches by main title + year
                List <DBMovieInfo> results = Search(movie.Title, movie.Year);
                if (results.Count == 0)
                {
                    results = Search(movie.Title);
                }

                // grab possible matches by alt titles
                foreach (string currAltTitle in movie.AlternateTitles)
                {
                    List <DBMovieInfo> tempResults = Search(movie.Title, movie.Year);
                    if (tempResults.Count == 0)
                    {
                        tempResults = Search(movie.Title);
                    }

                    results.AddRange(tempResults);
                }

                // pick a possible match if one meets our requirements
                foreach (DBMovieInfo currMatch in results)
                {
                    if (CloseEnough(currMatch, movie))
                    {
                        return(currMatch.GetSourceMovieInfo(SourceInfo).Identifier);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        private string getMovieMeterID(DBMovieInfo movie)
        {
            string            mmId  = null;
            DBSourceMovieInfo idObj = movie.GetSourceMovieInfo(SourceInfo);

            if (idObj != null && idObj.Identifier != null)
            {
                mmId = idObj.Identifier;
            }
            else
            {
                // Translate IMDb code to MovieMeter ID
                string imdbId = movie.ImdbID.Trim();
                if (imdbId != string.Empty)
                {
                    mmId = Api.GetMovieMeterId(imdbId);
                    if (mmId != null)
                    {
                        movie.GetSourceMovieInfo(SourceInfo).Identifier = mmId;
                    }
                }
            }
            return(mmId);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public bool GetBackdrop(DBMovieInfo movie)
        {
            if (scraper == null)
            {
                return(false);
            }

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

            // if we already have a backdrop move on for now
            if (movie.BackdropFullPath.Trim().Length > 0)
            {
                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_backdrop", paramList);
            if (results == null)
            {
                logger.Error(Name + " scraper script failed to execute \"get_backdrop\" node.");
                return(false);
            }


            // Loop through all the results until a valid backdrop is found
            int count = 0;

            while (results.ContainsKey("backdrop[" + count + "].url") || results.ContainsKey("backdrop[" + count + "].file"))
            {
                // attempt to load via a URL
                if (results.ContainsKey("backdrop[" + count + "].url"))
                {
                    string backdropURL = results["backdrop[" + count + "].url"];
                    if (backdropURL.Trim().Length > 0)
                    {
                        if (movie.AddBackdropFromURL(backdropURL) == ImageLoadResults.SUCCESS)
                        {
                            return(true);
                        }
                    }
                }

                // attempt to load via a file
                if (results.ContainsKey("backdrop[" + count + "].file"))
                {
                    string backdropFile = results["backdrop[" + count + "].file"];
                    if (backdropFile.Trim().Length > 0)
                    {
                        if (movie.AddBackdropFromFile(backdropFile))
                        {
                            return(true);
                        }
                    }
                }

                count++;
            }

            // no valid backdrop found
            return(false);
        }
Ejemplo n.º 5
0
        public UpdateResults Update(DBMovieInfo movie)
        {
            if (scraper == null)
            {
                return(UpdateResults.FAILED);
            }

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

            // try to load the id for the movie for this script
            // if we have no site id still continue as we might still
            // be able to grab details using another identifier such as imdb_id
            DBSourceMovieInfo idObj = movie.GetSourceMovieInfo(ScriptID);

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

            // load params
            foreach (DBField currField in DBField.GetFieldList(typeof(DBMovieInfo)))
            {
                if (currField.AutoUpdate && 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);

            // try to retrieve results
            results = scraper.Execute("get_details", paramList);
            if (results == null)
            {
                logger.Error(Name + " scraper script failed to execute \"get_details\" node.");
                return(UpdateResults.FAILED);
            }

            if (!hasSiteId)
            {
                // if we started out without a site id
                // try to get it from the details response
                string siteId;
                if (results.TryGetValue("movie.site_id", out siteId))
                {
                    movie.GetSourceMovieInfo(ScriptID).Identifier = siteId;
                }
                else
                {
                    // still no site id, so we are returning
                    return(UpdateResults.FAILED_NEED_ID);
                }
            }

            // get our new movie details
            DBMovieInfo newMovie = new DBMovieInfo();

            foreach (DBField currField in DBField.GetFieldList(typeof(DBMovieInfo)))
            {
                string value;
                bool   success = results.TryGetValue("movie." + currField.FieldName, out value);

                if (success && value.Trim().Length > 0)
                {
                    currField.SetValue(newMovie, value.Trim());
                }
            }

            // and update as necessary
            movie.CopyUpdatableValues(newMovie);

            return(UpdateResults.SUCCESS);
        }