private const int MY_API_SEARCH_LIMIT = 10; // Max number of results that can be returned in a single search /// <summary> /// Downloads the information for a movie or series episode (no matching) given the IMDB ID for the movie or episode (not show) /// Uses OMDBApi /// </summary> /// <param name="videoTags">Video Tags structure with the IMDB ID</param> /// <returns>True if successful</returns> static public bool BootStrapByIMDBId(VideoTags videoTags) { try { OMDBApi.SearchResult result = new OMDBApi.SearchResult(); if (String.IsNullOrWhiteSpace(videoTags.imdbId)) // do we have a valid ID to begin with return false; try { WebClient client = new WebClient(); client.Headers.Add("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"); string response = client.DownloadString(new Uri("http://www.omdbapi.com/?i=" + videoTags.imdbId)); result = JsonConvert.DeserializeObject<OMDBApi.SearchResult>(response); } catch { return false; // invalid JSON string } if (String.IsNullOrWhiteSpace(result.Title)) // Check if got a valid result return false; // Check if it's a movie if (result.Type.ToLower().Contains("movie")) { videoTags.Title = result.Title; // Take what is forced for the imdb movie id videoTags.IsMovie = true; // Get Overview string overview = result.Plot; if (!String.IsNullOrWhiteSpace(overview) && String.IsNullOrWhiteSpace(videoTags.Description)) videoTags.Description = overview; // Get original release date DateTime releaseDate = GlobalDefs.NO_BROADCAST_TIME; if (DateTime.TryParseExact(result.Released, "dd MMM yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out releaseDate)) { if (releaseDate > GlobalDefs.NO_BROADCAST_TIME) if ((videoTags.OriginalBroadcastDateTime <= GlobalDefs.NO_BROADCAST_TIME) || (videoTags.OriginalBroadcastDateTime.Date > releaseDate.Date)) // Sometimes the metadata from the video recordings are incorrect and report the recorded date (which is more recent than the release date) then use IMDB dates, IMDB Dates are more reliable than video metadata usually videoTags.OriginalBroadcastDateTime = releaseDate; // IMDB stores time in network (local) timezone } string[] genres = result.Genre.Split(','); // Get Genres if (genres != null) { if (genres.Length > 0) { if (videoTags.Genres != null) { if (videoTags.Genres.Length == 0) videoTags.Genres = genres; } else videoTags.Genres = genres; } } // Download the banner file VideoMetaData.DownloadBannerFile(videoTags, result.Poster); // Get bannerfile return true; // We found it, get out home free } else // Process as a series { DateTime seriesPremiereDate = GlobalDefs.NO_BROADCAST_TIME; DateTime.TryParseExact(result.Released, "dd MMM yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out seriesPremiereDate); string episodeName = result.Title; // Title here is the episode name since we are forcing a IMDB ID leading directly to a episode (the Showname is taken from the filename or metadata) string bannerUrl = result.Poster; // Get Poster URL string[] genres = result.Genre.Split(','); // Get Genres string episodeOverview = result.Plot; // Get Overview if (!String.IsNullOrWhiteSpace(episodeName) && String.IsNullOrWhiteSpace(videoTags.SubTitle)) videoTags.SubTitle = episodeName; if (!String.IsNullOrWhiteSpace(episodeOverview) && String.IsNullOrWhiteSpace(videoTags.Description)) videoTags.Description = episodeOverview; else if (!String.IsNullOrWhiteSpace(episodeOverview) && (String.IsNullOrWhiteSpace(videoTags.Description))) videoTags.Description = episodeOverview; if (seriesPremiereDate > GlobalDefs.NO_BROADCAST_TIME) if ((videoTags.SeriesPremiereDate <= GlobalDefs.NO_BROADCAST_TIME) || (videoTags.SeriesPremiereDate.Date > seriesPremiereDate.Date)) // Sometimes the metadata from the video recordings are incorrect and report the recorded date (which is more recent than the release date) then use IMDB dates, IMDB Dates are more reliable than video metadata usually videoTags.SeriesPremiereDate = seriesPremiereDate; // IMDB stores time in network (local) timezone if (genres != null) { if (genres.Length > 0) { if (videoTags.Genres != null) { if (videoTags.Genres.Length == 0) videoTags.Genres = genres; } else videoTags.Genres = genres; } } // Check if it's a sport series if (videoTags.Genres != null) if (videoTags.Genres.Length > 0) if (videoTags.Genres.Contains("sport", StringComparer.OrdinalIgnoreCase)) videoTags.IsSports = true; // Download the banner file VideoMetaData.DownloadBannerFile(videoTags, bannerUrl); // Get bannerfile return true; // Golden } } catch { return false; } }
private const int MY_API_SEARCH_LIMIT = 10; // Max number of results that can be returned in a single search /// <summary> /// Downloads the information for a movie or series episode (no matching) given the IMDB ID for the movie or episode (not show) /// Uses OMDBApi /// </summary> /// <param name="videoTags">Video Tags structure with the IMDB ID</param> /// <returns>True if successful</returns> static public bool BootStrapByIMDBId(VideoTags videoTags, Log jobLog) { try { OMDBApi.SearchResult result = new OMDBApi.SearchResult(); if (String.IsNullOrWhiteSpace(videoTags.imdbId)) // do we have a valid ID to begin with { return(false); } try { WebClient client = new WebClient(); client.Headers.Add("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"); string response = client.DownloadString(new Uri("http://www.omdbapi.com/?i=" + videoTags.imdbId + "&r=json")); result = JsonConvert.DeserializeObject <OMDBApi.SearchResult>(response); } catch (Exception e) { jobLog.WriteEntry("Unable to bootstrap from IMDB\r\nError -> " + e.ToString(), Log.LogEntryType.Warning); return(false); // invalid JSON string } if (String.IsNullOrWhiteSpace(result.Title)) // Check if got a valid result { jobLog.WriteEntry("Unable to boot strap, IMDB returned empty Title", Log.LogEntryType.Debug); return(false); } // Check if it's a movie if (result.Type.ToLower().Contains("movie")) { videoTags.Title = result.Title; // Take what is forced for the imdb movie id videoTags.IsMovie = true; // Get Overview string overview = result.Plot; if (!String.IsNullOrWhiteSpace(overview) && String.IsNullOrWhiteSpace(videoTags.Description)) { videoTags.Description = overview; } // Get original release date DateTime releaseDate = GlobalDefs.NO_BROADCAST_TIME; if (DateTime.TryParseExact(result.Released, "dd MMM yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out releaseDate)) { if (releaseDate > GlobalDefs.NO_BROADCAST_TIME) { if ((videoTags.OriginalBroadcastDateTime <= GlobalDefs.NO_BROADCAST_TIME) || (videoTags.OriginalBroadcastDateTime.Date > releaseDate.Date)) // Sometimes the metadata from the video recordings are incorrect and report the recorded date (which is more recent than the release date) then use IMDB dates, IMDB Dates are more reliable than video metadata usually { videoTags.OriginalBroadcastDateTime = releaseDate; // IMDB stores time in network (local) timezone } } } string[] genres = result.Genre.Split(','); // Get Genres if (genres != null) { if (genres.Length > 0) { if (videoTags.Genres != null) { if (videoTags.Genres.Length == 0) { videoTags.Genres = genres; } } else { videoTags.Genres = genres; } } } // Download the banner file VideoMetaData.DownloadBannerFile(videoTags, result.Poster); // Get bannerfile return(true); // We found it, get out home free } else // Process as a series { DateTime seriesPremiereDate = GlobalDefs.NO_BROADCAST_TIME; DateTime.TryParseExact(result.Released, "dd MMM yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out seriesPremiereDate); string episodeName = result.Title; // Title here is the episode name since we are forcing a IMDB ID leading directly to a episode (the Showname is taken from the filename or metadata) string bannerUrl = result.Poster; // Get Poster URL string[] genres = result.Genre.Split(','); // Get Genres string episodeOverview = result.Plot; // Get Overview if (!String.IsNullOrWhiteSpace(episodeName) && String.IsNullOrWhiteSpace(videoTags.SubTitle)) { videoTags.SubTitle = episodeName; } if (!String.IsNullOrWhiteSpace(episodeOverview) && String.IsNullOrWhiteSpace(videoTags.Description)) { videoTags.Description = episodeOverview; } else if (!String.IsNullOrWhiteSpace(episodeOverview) && (String.IsNullOrWhiteSpace(videoTags.Description))) { videoTags.Description = episodeOverview; } if (seriesPremiereDate > GlobalDefs.NO_BROADCAST_TIME) { if ((videoTags.SeriesPremiereDate <= GlobalDefs.NO_BROADCAST_TIME) || (videoTags.SeriesPremiereDate.Date > seriesPremiereDate.Date)) // Sometimes the metadata from the video recordings are incorrect and report the recorded date (which is more recent than the release date) then use IMDB dates, IMDB Dates are more reliable than video metadata usually { videoTags.SeriesPremiereDate = seriesPremiereDate; // IMDB stores time in network (local) timezone } } if (genres != null) { if (genres.Length > 0) { if (videoTags.Genres != null) { if (videoTags.Genres.Length == 0) { videoTags.Genres = genres; } } else { videoTags.Genres = genres; } } } // Check if it's a sport series if (videoTags.Genres != null) { if (videoTags.Genres.Length > 0) { if (videoTags.Genres.Contains("sport", StringComparer.OrdinalIgnoreCase)) { videoTags.IsSports = true; } } } // Download the banner file VideoMetaData.DownloadBannerFile(videoTags, bannerUrl); // Get bannerfile return(true); // Golden } } catch (Exception e) { jobLog.WriteEntry("Unable to use IMDB\r\nError -> " + e.ToString(), Log.LogEntryType.Warning); return(false); } }