public List <string> GetBackdrops(MovieInfo movie) { if (Scraper == null) { return(null); } if (!ProvidesBackdrops) { return(null); } Dictionary <string, string> paramList = new Dictionary <string, string>(); Dictionary <string, string> results; List <string> rtn = new List <string>(); // grab backdrop loading settings int maxBackdropsInSession = 5; // try to load the id for the movie for this script if (movie.CustomIds.ContainsKey(Name)) { paramList["movie.site_id"] = movie.CustomIds[Name]; } else { return(null); } foreach (string property in _supportedMoviePoperties) { if (TryGetMovieProperty(property, movie, out string val)) { paramList["movie." + property] = val.Trim(); } } //set higher level settings for script to use paramList["settings.mepo_data"] = ServiceRegistration.Get <IPathManager>().GetPath(@"<CONFIG>\ScriptableScraperProvider\"); if (!Directory.Exists(paramList["settings.mepo_data"])) { Directory.CreateDirectory(paramList["settings.mepo_data"]); } BaseScriptableMovieMetadataExtractor.AddOrUpdateParamsFromCustomSettings(paramList); // run the scraper results = Scraper.Execute("get_backdrop", paramList); if (results == null) { Logger.Error("ScriptableScraperProvider: " + Name + " scraper script failed to execute \"get_backdrop\" node."); return(null); } // 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")) { // if we have hit our limit quit if (rtn.Count >= maxBackdropsInSession) { return(rtn); } // attempt to load via a URL if (results.ContainsKey("backdrop[" + count + "].url")) { string backdropURL = results["backdrop[" + count + "].url"]; if (backdropURL.Trim().Length > 0) { rtn.Add(new Uri(backdropURL).ToString()); } } // attempt to load via a file if (results.ContainsKey("backdrop[" + count + "].file")) { string backdropFile = results["backdrop[" + count + "].file"]; if (backdropFile.Trim().Length > 0) { rtn.Add(new Uri(backdropFile).ToString()); } } count++; } if (rtn.Count > 0) { return(rtn); } return(null); }
public bool UpdateMovie(MovieInfo movie) { if (Scraper == null) { return(false); } if (!ProvidesDetails) { return(false); } Dictionary <string, string> paramList = new Dictionary <string, string>(); Dictionary <string, string> results; bool hasSiteId = false; string siteId = null; // 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 // try to load the id for the movie for this script if (movie.CustomIds.ContainsKey(Name)) { paramList["movie.site_id"] = movie.CustomIds[Name]; siteId = movie.CustomIds[Name]; hasSiteId = true; } // load params foreach (string property in _supportedMoviePoperties) { if (TryGetMovieProperty(property, movie, out string val)) { paramList["movie." + property] = val.Trim(); } } //set higher level settings for script to use paramList["settings.mepo_data"] = ServiceRegistration.Get <IPathManager>().GetPath(@"<CONFIG>\ScriptableScraperProvider\"); if (!Directory.Exists(paramList["settings.mepo_data"])) { Directory.CreateDirectory(paramList["settings.mepo_data"]); } BaseScriptableMovieMetadataExtractor.AddOrUpdateParamsFromCustomSettings(paramList); // try to retrieve results results = Scraper.Execute("get_details", paramList); if (results == null) { Logger.Error("ScriptableScraperProvider: " + Name + " scraper script failed to execute \"get_details\" node."); return(false); } if (!hasSiteId) { // if we started out without a site id // try to get it from the details response if (results.TryGetValue("movie.site_id", out siteId)) { movie.CustomIds.Add(Name, siteId); } else { // still no site id, so we are returning Logger.Debug("ScriptableScraperProvider: " + Name + " scraper script failed to execute \"get_details\" because of missing site ID."); return(false); } } // get our new movie details foreach (string property in _supportedMoviePoperties) { string value; if (results.TryGetValue("movie." + property, out value)) { TrySetMovieProperty(property, value.Trim(), movie); } } return(true); }
public List <string> GetArtwork(MovieInfo movie) { if (Scraper == null) { return(null); } if (!ProvidesCoverArt) { return(null); } Dictionary <string, string> paramList = new Dictionary <string, string>(); Dictionary <string, string> results; List <string> rtn = new List <string>(); // grab coverart loading settings int maxCoversInSession = 5; // try to load the id for the movie for this script if (movie.CustomIds.ContainsKey(Name)) { paramList["movie.site_id"] = movie.CustomIds[Name]; } else { return(null); } // load params for scraper foreach (string property in _supportedMoviePoperties) { if (TryGetMovieProperty(property, movie, out string val)) { paramList["movie." + property] = val.Trim(); } } //set higher level settings for script to use paramList["settings.mepo_data"] = ServiceRegistration.Get <IPathManager>().GetPath(@"<CONFIG>\ScriptableScraperProvider\"); if (!Directory.Exists(paramList["settings.mepo_data"])) { Directory.CreateDirectory(paramList["settings.mepo_data"]); } BaseScriptableMovieMetadataExtractor.AddOrUpdateParamsFromCustomSettings(paramList); // run the scraper results = Scraper.Execute("get_cover_art", paramList); if (results == null) { Logger.Error("ScriptableScraperProvider: " + Name + " scraper script failed to execute \"get_cover_art\" node."); return(null); } int count = 0; while (results.ContainsKey("cover_art[" + count + "].url") || results.ContainsKey("cover_art[" + count + "].file")) { // if we have hit our limit quit if (rtn.Count >= maxCoversInSession) { return(rtn); } // get url for cover if (results.ContainsKey("cover_art[" + count + "].url")) { string coverPath = results["cover_art[" + count + "].url"]; if (coverPath.Trim() != string.Empty) { rtn.Add(new Uri(coverPath).ToString()); } } // get file for cover if (results.ContainsKey("cover_art[" + count + "].file")) { string coverPath = results["cover_art[" + count + "].file"]; if (coverPath.Trim() != string.Empty) { rtn.Add(new Uri(coverPath).ToString()); } } count++; } if (rtn.Count > 0) { return(rtn); } return(null); }
public List <MovieInfo> SearchMovie(MovieInfo movieSearch) { if (Scraper == null) { return(null); } List <MovieInfo> rtn = new List <MovieInfo>(); Dictionary <string, string> paramList = new Dictionary <string, string>(); Dictionary <string, string> results; var mediaFile = movieSearch.SearchFilePath; string file = mediaFile != null?Path.GetFileName(mediaFile) : null; string folderPath = mediaFile != null?Path.GetDirectoryName(mediaFile) : null; string folder = folderPath != null ? new DirectoryInfo(folderPath).Name : null; if (!movieSearch.MovieName.IsEmpty) { paramList["search.title"] = movieSearch.MovieName.Text; } if (!movieSearch.MovieName.IsEmpty) { paramList["search.keywords"] = GetKeywords(movieSearch.MovieName.Text); } if (movieSearch.ReleaseDate.HasValue) { paramList["search.year"] = movieSearch.ReleaseDate.Value.Year.ToString(); } if (movieSearch.ImdbId != null) { paramList["search.imdb_id"] = movieSearch.ImdbId; } //if (movieSignature.DiscId != null) paramList["search.disc_id"] = movieSignature.DiscId; //String version of the Disc ID (16 character hash of a DVD) //if (movieSignature.MovieHash != null) paramList["search.moviehash"] = movieSignature.MovieHash; //String version of the filehash of the first movie file (16 characters) if (folderPath != null) { paramList["search.basepath"] = folderPath; //Complete path to the base folder } if (folder != null) { paramList["search.foldername"] = folder; //The base folder name of the movie } if (file != null) { paramList["search.filename"] = file; //The filename of the movie } //set higher level settings for script to use paramList["settings.mepo_data"] = ServiceRegistration.Get <IPathManager>().GetPath(@"<CONFIG>\ScriptableScraperProvider\"); if (!Directory.Exists(paramList["settings.mepo_data"])) { Directory.CreateDirectory(paramList["settings.mepo_data"]); } BaseScriptableMovieMetadataExtractor.AddOrUpdateParamsFromCustomSettings(paramList); // this variable is the filename without extension (and a second one without stackmarkers) if (!String.IsNullOrEmpty(file)) { paramList["search.filename_noext"] = Path.GetFileNameWithoutExtension(file); paramList["search.clean_filename"] = GetFileNameWithoutExtensionAndStackMarkers(file); } results = Scraper.Execute("search", paramList); if (results == null) { Logger.Error("ScriptableScraperProvider: " + Name + " scraper script failed to execute \"search\" node."); return(rtn); } int count = 0; // The movie result is only valid if the script supplies a unique site while (results.ContainsKey("movie[" + count + "].site_id")) { string siteId; string prefix = "movie[" + count + "]."; count++; // if the result does not yield a site id it's not valid so skip it if (!results.TryGetValue(prefix + "site_id", out siteId)) { continue; } string existingId = null; if (movieSearch.CustomIds.ContainsKey(Name)) { existingId = movieSearch.CustomIds[Name]; } // if this movie was already identified skip it if (existingId != null && existingId != siteId) { continue; } // if this movie does not have a valid title, don't bother if (!results.ContainsKey(prefix + "title")) { continue; } // We passed all checks so create a new movie object MovieInfo newMovie = new MovieInfo(); // store the site id in the new movie object newMovie.CustomIds.Add(Name, siteId); newMovie.DataProviders.Add(Name); // Try to store all other fields in the new movie object foreach (string property in _supportedMoviePoperties) { string value; if (results.TryGetValue(prefix + property, out value)) { TrySetMovieProperty(property, value.Trim(), newMovie); } } // add the movie to our movie results list rtn.Add(newMovie); } return(rtn); }