Example #1
0
        // if flagged, check for backdrops in the movie folder based on the user defined pattern
        private bool getBackdropsFromMovieFolder(DBMovieInfo movie)
        {
            // should never really happen, but if the database is corrupt,
            // we dont want to crash, so just quit.
            if (movie.LocalMedia.Count == 0)
            {
                return(false);
            }

            bool found = false;

            bool   useMovieFolderBackdrops = MovingPicturesCore.Settings.SearchMovieFolderForBackdrops;
            string pattern = MovingPicturesCore.Settings.MovieFolderBackdropFilenamePattern;

            if (useMovieFolderBackdrops)
            {
                List <string> movieFolderFilenames = getPossibleNamesFromPattern(pattern, movie);
                foreach (string currFile in movieFolderFilenames)
                {
                    FileInfo newBackdrop = new FileInfo(Utility.GetMovieBaseDirectory(movie.LocalMedia[0].File.Directory).FullName + "\\" + currFile);
                    if (newBackdrop.Exists)
                    {
                        found |= movie.AddBackdropFromFile(newBackdrop.FullName);
                    }
                }
            }

            return(found);
        }
Example #2
0
        // check for backdrops in the backdrop folder loaded from previous installs
        private bool getOldBackdrops(DBMovieInfo movie)
        {
            bool found = false;

            string        backdropFolderPath = MovingPicturesCore.Settings.BackdropFolder;
            DirectoryInfo backdropFolder     = new DirectoryInfo(backdropFolderPath);

            string safeName         = movie.Title.Replace(' ', '.').ToValidFilename() + "-" + movie.Year;
            Regex  oldBackdropRegex = new Regex("^{?" + Regex.Escape(safeName) + "}? \\[-?\\d+\\]\\.(jpg|png)");

            foreach (FileInfo currFile in backdropFolder.GetFiles())
            {
                if (oldBackdropRegex.IsMatch(currFile.Name))
                {
                    found |= movie.AddBackdropFromFile(currFile.FullName);
                }
            }

            return(found);
        }
Example #3
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);
        }