private static void FetchMovieExample(TMDbClient client) { string query = "Thor"; // This example shows the fetching of a movie. // Say the user searches for "Thor" in order to find "Thor: The Dark World" or "Thor" SearchContainer<SearchMovie> results = client.SearchMovie(query); // The results is a list, currently on page 1 because we didn't specify any page. Console.WriteLine("Searched for movies: '" + query + "', found " + results.TotalResults + " results in " + results.TotalPages + " pages"); // Let's iterate the first few hits foreach (SearchMovie result in results.Results.Take(3)) { // Print out each hit Console.WriteLine(result.Id + ": " + result.Title); Console.WriteLine("\t Original Title: " + result.OriginalTitle); Console.WriteLine("\t Release date : " + result.ReleaseDate); Console.WriteLine("\t Popularity : " + result.Popularity); Console.WriteLine("\t Vote Average : " + result.VoteAverage); Console.WriteLine("\t Vote Count : " + result.VoteCount); Console.WriteLine(); Console.WriteLine("\t Backdrop Path : " + result.BackdropPath); Console.WriteLine("\t Poster Path : " + result.PosterPath); Console.WriteLine(); } Spacer(); }
// This code is to get Movies from THE Movie Database (http://www.themoviedb.org) public static MovieModel getSingleFromTMDB(string title) { // Year int year = DateTime.Now.Year; MovieModel expectedMovie = new MovieModel(); TMDbClient client = new TMDbClient("34c356b1eb1a362f5a3b958a9e94a113"); SearchContainer<SearchMovie> results = client.SearchMovie(title); if(results.Results.Count> 0) { try { int id = results.Results[0].Id; Movie movie = client.GetMovie(id); if (movie.OriginalLanguage.Equals("hi")) return null; List<Genre> genres = movie.Genres; var credits = client.GetMovieCredits(id); List<string> credit = getStringFromCrewList(credits); expectedMovie.Title = title; expectedMovie.Year = movie.ReleaseDate.Value.Year.ToString(); expectedMovie.Released = movie.ReleaseDate.Value.Date.ToString(); expectedMovie.Runtime = movie.Runtime.ToString() + " Minutes"; expectedMovie.Genre = getStringFromGenereList(movie.Genres); expectedMovie.Actors = credit[0].ToString(); expectedMovie.Director = credit[1].ToString(); expectedMovie.Writer = credit[2].ToString(); expectedMovie.Plot = movie.Overview; expectedMovie.Language = movie.OriginalLanguage; if(movie.ProductionCountries.Count>0) expectedMovie.Country = movie.ProductionCountries[0].Name; expectedMovie.Poster = Constants.POSTER_LINK_HOST_PATH + movie.PosterPath; expectedMovie.imdbRating = movie.VoteAverage.ToString(); expectedMovie.imdbVotes = movie.VoteCount.ToString(); expectedMovie.imdbID = movie.ImdbId.ToString(); expectedMovie.Showtype = "2D"; return expectedMovie; } catch (Exception e) { return null; } } else return null; }
private void MediaInfoLoadButton_Click(object sender, RoutedEventArgs e) { string searchMedia = MediaTitleInfo.Text; if (string.IsNullOrEmpty(searchMedia)) return; string selectedLang = (string) SearchLanguage.SelectedValue; if (string.IsNullOrEmpty(selectedLang)) selectedLang = "en"; string selectedCertCountry = (string) RatingCountry.SelectedValue; if (string.IsNullOrEmpty(selectedCertCountry)) selectedCertCountry = "us"; AppSettings.MovieDBLastLanguage = selectedLang; AppSettings.MovieDBLastRatingCountry = selectedCertCountry; TMDbClient client = new TMDbClient(MovieDBApiKey); FileInfo configXml = new FileInfo("TMDbconfig.xml"); if (configXml.Exists && configXml.LastWriteTimeUtc >= DateTime.UtcNow.AddHours(-1)) { Log.Info("TMDbClient: Using stored config"); string xml = File.ReadAllText(configXml.FullName, Encoding.Unicode); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); client.SetConfig(TMDbSerializer.Deserialize<TMDbConfig>(xmlDoc)); } else { Log.Info("TMDbClient: Getting new config"); client.GetConfig(); Log.Info("TMDbClient: Storing config"); XmlDocument xmlDoc = TMDbSerializer.Serialize(client.Config); File.WriteAllText(configXml.FullName, xmlDoc.OuterXml, Encoding.Unicode); } SearchContainer<SearchMovie> movieList = client.SearchMovie(searchMedia, selectedLang); if (movieList == null || movieList.TotalResults <= 0) return; SearchMovie resultMovie = new SearchMovie(); if (movieList.TotalResults > 1) { MovieDBMultipleSelection selectWindow = new MovieDBMultipleSelection { Owner = this, SearchResults = movieList }; if (selectWindow.ShowDialog() == true) resultMovie = selectWindow.SelectionResult; } else resultMovie = movieList.Results.First(); if (resultMovie.Id == 0) return; Movie searchResult = client.GetMovie(resultMovie.Id, selectedLang); ImagesWithId imageList = client.GetMovieImages(resultMovie.Id); Casts movieCasts = client.GetMovieCasts(resultMovie.Id); KeywordsContainer movieKeywords = client.GetMovieKeywords(resultMovie.Id); Trailers movieTrailers = client.GetMovieTrailers(resultMovie.Id); Releases movieReleases = client.GetMovieReleases(resultMovie.Id); if (searchResult == null) return; MovieTitle.Text = searchResult.Title; MovieOriginalTitle.Text = searchResult.OriginalTitle; Genre.Text = searchResult.Genres != null ? string.Join(" / ", searchResult.Genres.ConvertAll(input => input.Name)) : string.Empty; Rating.Text = searchResult.VoteAverage.ToString("g"); Runtime.Text = searchResult.Runtime.ToString("g"); Votes.Text = searchResult.VoteCount.ToString("g"); Year.Text = searchResult.ReleaseDate.Year.ToString("g"); Tagline.Text = searchResult.Tagline; Plot.Text = searchResult.Overview; if (movieKeywords != null && movieKeywords.Keywords != null) Keywords.Text = string.Join(", ", movieKeywords.Keywords.ConvertAll(input => input.Name)); else Keywords.Text = string.Empty; ImdbId.Text = searchResult.ImdbId; Country.Text = searchResult.ProductionCountries != null ? string.Join(" / ", searchResult.ProductionCountries.ConvertAll(input => input.Name)) : string.Empty; if (movieCasts != null && movieCasts.Crew != null) { Director.Text = string.Join(" / ", movieCasts.Crew.Where(crew => crew.Job == "Director") .ToList() .ConvertAll(input => input.Name)); Writers.Text = string.Join(" / ", movieCasts.Crew.Where(crew => crew.Job == "Writer" || crew.Job == "Screenplay") .ToList() .ConvertAll(input => input.Name)); } else { Director.Text = string.Empty; Writers.Text = string.Empty; } Studio.Text = searchResult.ProductionCompanies != null ? string.Join(" / ", searchResult.ProductionCompanies.ConvertAll(input => input.Name)) : string.Empty; SetName.Text = searchResult.BelongsToCollection != null ? string.Join(" / ", searchResult.BelongsToCollection.ConvertAll(input => input.Name)) : string.Empty; if (movieTrailers != null && movieTrailers.Youtube != null && movieTrailers.Youtube.Count > 0) Trailer.Text = "plugin://plugin.video.youtube/?action=play_video&videoid=" + movieTrailers.Youtube.First().Source; else Trailer.Text = string.Empty; Country selCountry = movieReleases.Countries.Single(country => country.Iso_3166_1.ToLowerInvariant() == selectedCertCountry) ?? movieReleases.Countries.Single(country => country.Iso_3166_1.ToLowerInvariant() == "us"); MovieDBCertCountry certCountry = MovieDBCertCountries.CountryList.Single(country => country.CountryName == selectedCertCountry); MPAARating.Text = certCountry.Prefix + selCountry.Certification; // loading image sizes string posterOriginal = client.Config.Images.PosterSizes.Last(); string posterPreview = client.Config.Images.PosterSizes.Count >= 2 ? client.Config.Images.PosterSizes[client.Config.Images.PosterSizes.Count - 2] : client.Config.Images.PosterSizes.Last(); string backdropOriginal = client.Config.Images.BackdropSizes.Last(); string backdropPreview = client.Config.Images.BackdropSizes.Count >= 3 ? client.Config.Images.BackdropSizes[ client.Config.Images.BackdropSizes.Count - 3] : client.Config.Images.BackdropSizes.Last(); // remove duplicate entries imageList.Backdrops.RemoveAt(imageList.Backdrops.FindIndex(data => data.FilePath == searchResult.BackdropPath)); imageList.Posters.RemoveAt(imageList.Posters.FindIndex(data => data.FilePath == searchResult.PosterPath)); // create image lists _postersList.Add(new MovieDBPosterImage { Title = "Default", UrlOriginal = client.GetImageUrl(posterOriginal, searchResult.PosterPath).AbsoluteUri, UrlPreview = client.GetImageUrl(posterPreview, searchResult.PosterPath).AbsoluteUri }); _backdropsList.Add(new MovieDBImageInfo { Title = "Default", UrlOriginal = client.GetImageUrl(backdropOriginal, searchResult.BackdropPath).AbsoluteUri, UrlPreview = client.GetImageUrl(backdropPreview, searchResult.BackdropPath).AbsoluteUri }); int cnt = 1; foreach (ImageData poster in imageList.Posters) { _postersList.Add(new MovieDBPosterImage { Title = "Online image " + cnt, UrlOriginal = client.GetImageUrl(posterOriginal, poster.FilePath).AbsoluteUri, UrlPreview = client.GetImageUrl(posterPreview, poster.FilePath).AbsoluteUri }); cnt++; } PosterList.ItemsSource = _postersList; PosterList.SelectedIndex = 0; cnt = 1; foreach (ImageData backdrop in imageList.Backdrops) { _backdropsList.Add(new MovieDBImageInfo { Title = "Online image " + cnt, UrlOriginal = client.GetImageUrl(backdropOriginal, backdrop.FilePath).AbsoluteUri, UrlPreview = client.GetImageUrl(backdropPreview, backdrop.FilePath).AbsoluteUri }); cnt++; } BackdropList.ItemsSource = _backdropsList; BackdropList.SelectedIndex = 0; foreach (Cast cast in movieCasts.Cast) { _castList.Casts.Add(new MovieDBCast { Name = cast.Name, Role = cast.Character, Thumbnail = client.GetImageUrl("original", cast.ProfilePath).AbsoluteUri }); } CastListView.ItemsSource = _castList.Casts; }
//Search TMDB for movies to add depending on Search String public List<SearchTMDBResult> RetrieveTMDBSearchResults(string movieName) { List<SearchTMDBResult> listOfSearchTMDBResults = new List<SearchTMDBResult>(); TMDbClient client = new TMDbClient("1fee8f2397ff73412985de2bb825f020"); SearchContainer<SearchMovie> initResults = client.SearchMovie("\"" + movieName + "\""); if (initResults.TotalPages >= 1) { for (int i = 1; i < initResults.TotalPages + 1; i++) { SearchContainer<SearchMovie> results = client.SearchMovie("\"" + movieName + "\"", i); foreach (SearchMovie r in results.Results) { SearchTMDBResult newResult = new SearchTMDBResult(); newResult.MovieTitle = r.Title; newResult.TMDBNum = r.Id; if (r.ReleaseDate != null) { newResult.ReleaseDate = r.ReleaseDate.Value; } if (r.Overview != null) { newResult.Synopsis = r.Overview; } if (r.PosterPath != null) { newResult.PosterUrl = "http://image.tmdb.org/t/p/w185" + r.PosterPath; } else { newResult.PosterUrl = "http://assets.tmdb.org/assets/7f29bd8b3370c71dd379b0e8b570887c/images/no-poster-w185-v2.png"; } listOfSearchTMDBResults.Add(newResult); } } } return listOfSearchTMDBResults; }
public static List<MovieDB_Movie_Result> Search(string criteria) { List<MovieDB_Movie_Result> results = new List<MovieDB_Movie_Result>(); try { TMDbClient client = new TMDbClient(apiKey); SearchContainer<SearchMovie> resultsTemp = client.SearchMovie(criteria); Console.WriteLine("Got {0} of {1} results", resultsTemp.Results.Count, resultsTemp.TotalResults); foreach (SearchMovie result in resultsTemp.Results) { MovieDB_Movie_Result searchResult = new MovieDB_Movie_Result(); Movie movie = client.GetMovie(result.Id); ImagesWithId imgs = client.GetMovieImages(result.Id); searchResult.Populate(movie, imgs); results.Add(searchResult); SaveMovieToDatabase(searchResult, false); } } catch (Exception ex) { logger.Error("Error in MovieDB Search: " + ex.Message); } return results; }
private void TmdbComplete(TMDbClient tmdb) { try { String[] split = Title.Split(new char[] { ' ', '.', '_', '-' }); TMDbLib.Objects.General.SearchContainer<SearchMovie> results = tmdb.SearchMovie(this.Title); for (int i = split.Length; results.TotalResults == 0 && i > 0 ; --i) { String name = null; for (int j = 0; j < i; ++j) name += " " + split[j]; results = tmdb.SearchMovie(name); } Movie mov = tmdb.GetMovie(results.Results[0].Id); this.Adult = mov.Adult; this.Url = mov.Homepage; this.Title = mov.Title; if (mov != null && this.Picture == @"/WindowsMediaPlayer;component/assets/video_cover.png") SetImage(@"https://image.tmdb.org/t/p/w185" + mov.PosterPath, Lastfm.Utilities.md5(Path)); } catch (Exception e) { Debug.Add(e.ToString() + "\n"); } }
// take name of selected item in listBox1 and send it to TheMovieDb and retrieve possible movies private void identifySelectedMovie() { string selectedItem = listBox1.SelectedItem.ToString(); // read API key from textfile (see above) string key = ""; try { key = File.ReadAllText(_tmdbKeyFile); } catch (Exception e) { MessageBox.Show("Something went wrong while reading the TheMovieDb API key from \n" + _tmdbKeyFile + "\n" + e.Message, "Error", MessageBoxButtons.OK); } TMDbClient client = new TMDbClient(key); var results = client.SearchMovie(selectedItem).Results; // loop over all the found movies, and put the titles in a list var movies = new List<Movie>(); foreach (SearchMovie mov in results) { Movie m = new Movie(); m.MovieObject = mov; m.DisplayName = mov.Title; movies.Add(m); } // send all movies to the dialog listbox SelectMovie dialog; dialog = new SelectMovie(movies.ToArray() ); DialogResult res = dialog.ShowDialog(); if ( res == DialogResult.OK ) { // ask the dialog which item was selected Movie selectedMovieObject = dialog.GetSelectedItem(); listBox1.Items[listBox1.SelectedIndex] = selectedMovieObject; } }
public static void Search() { Console.Write("Please enter the name of the movie that you want to add: "); string input = Console.ReadLine(); TMDbClient client = new TMDbClient("1fee8f2397ff73412985de2bb825f020"); SearchContainer<SearchMovie> results = client.SearchMovie("\"" + input + "\""); Console.WriteLine("Page: {0}", results.Page); Console.WriteLine("Total Pages: {0}", results.TotalPages); Console.WriteLine(); Console.WriteLine("Got {0} of {1} results", results.Results.Count, results.TotalResults); foreach (SearchMovie result in results.Results) { Console.WriteLine(result.Title); Console.WriteLine(result.Id); Console.WriteLine(result.ReleaseDate); Console.WriteLine(result.Overview); Console.WriteLine(result.PosterPath); Console.WriteLine(result.GenreIds[0]); Console.WriteLine(); } Console.WriteLine(results.TotalPages); }
internal static string IdentifyFilmByTMDbFilmTitleMatchingEngine (IMLItem item) { string filmTitle = item.Name; string filmImdbId = Helpers.GetTagValueFromItem(item, "ImdbID"); //MessageBox.Show("Film title: " + filmTitle); if (String.IsNullOrEmpty(filmTitle)) return filmImdbId; if (!String.IsNullOrEmpty(filmImdbId)) return filmImdbId; int filmReleaseYear = -1; string filmReleaseYearString = Helpers.GetTagValueFromItem(item, "Year").Trim(); if (!String.IsNullOrEmpty(filmReleaseYearString)) { bool yarStringIsValidNumber = true; foreach (var digit in filmReleaseYearString) { if (!Char.IsNumber(digit)) yarStringIsValidNumber = false; } if (yarStringIsValidNumber) { filmReleaseYear = Convert.ToInt16(filmReleaseYearString); } } Helpers.UpdateProgress ("Updating Movies Section...", "Attempting to identify film by title using TMDb...", item); TMDbClient tmDbClient = new TMDbClient(MeediFier.Settings.TMDbApiKey); SearchContainer<SearchMovie> filmSearchResults = tmDbClient.SearchMovie (filmTitle, "", -1, false, filmReleaseYear); //SearchContainer<SearchMovie> filmSearchResults = tmDbClient.SearchMovie(filmTitle); if (filmSearchResults.Results.Count <= 0) return filmImdbId; SearchMovie firstMovieInSearchResults = filmSearchResults.Results[0]; TMDbLib.Objects.Movies.Movie movie = tmDbClient.GetMovie(firstMovieInSearchResults.Id); filmImdbId = movie.ImdbId; //MessageBox.Show(filmImdbId); if (String.IsNullOrEmpty(filmImdbId)) return filmImdbId; item.Tags["ImdbID"] = filmImdbId; item.SaveTags(); return filmImdbId; }
static public bool DownloadMovieDetails(VideoTags videoTags) { // The new v3 database is accessed via the TMDbLib API's try { TMDbClient client = new TMDbClient(MCEBUDDY_TMDB_APIKey); List<SearchMovie> movieSearch = new List<SearchMovie>(); Movie movieMatch = null; // TODO: Add support for multiple language searches if (String.IsNullOrWhiteSpace(videoTags.imdbId)) // If dont' have a specific movieId specified, look up the movie details { if (videoTags.OriginalBroadcastDateTime > GlobalDefs.NO_BROADCAST_TIME) // Release date narrow down { // The information is stored on the server using the network timezone // So we assume that the show being converted was recorded locally and is converted locally so the timezones match DateTime dt = videoTags.OriginalBroadcastDateTime.ToLocalTime(); movieSearch = client.SearchMovie(videoTags.Title.Trim().ToLower(), 0, true, dt.Year).Results; } else // Title Check movieSearch = client.SearchMovie(videoTags.Title.Trim().ToLower(), 0, true, 0).Results; } else // Specific ID { movieMatch = client.GetMovie(videoTags.imdbId); // We have a specific movie to work with } if (movieMatch == null) // If we haven't forced a movie match { foreach (SearchMovie movieResult in movieSearch) // Cycle through all possible combinations { Movie movie = client.GetMovie(movieResult.Id); List<AlternativeTitle> akaValues = null; if (movie.AlternativeTitles != null) akaValues = movie.AlternativeTitles.Titles; bool akaMatch = false; string title = videoTags.Title; if (akaValues != null) // Check if there are any AKA names to match akaMatch = akaValues.Any(s => (String.Compare(s.Title.Trim(), title.Trim(), CultureInfo.InvariantCulture, (CompareOptions.IgnoreSymbols | CompareOptions.IgnoreCase)) == 0 ? true : false)); // Get and match Movie name (check both titles and aka values) if (String.Compare(movie.Title.Trim(), videoTags.Title.Trim(), CultureInfo.InvariantCulture, (CompareOptions.IgnoreSymbols | CompareOptions.IgnoreCase)) != 0) // ignore white space and special characters if (String.Compare(movie.OriginalTitle.Trim(), videoTags.Title.Trim(), CultureInfo.InvariantCulture, (CompareOptions.IgnoreSymbols | CompareOptions.IgnoreCase)) != 0) // ignore white space and special characters if (!akaMatch) // check for aka value matches continue; // No match in name // If we got here, then we found a match movieMatch = movie; break; // We are done here } } if (movieMatch != null) // We have a match { if (!String.IsNullOrWhiteSpace(videoTags.imdbId)) // Match names only if the movie imdb id is not forced, else take what is returned by moviedb videoTags.Title = movieMatch.Title; // Take what is forced for the imdb movie id // Get Movie Id videoTags.tmdbId = movieMatch.Id.ToString(); videoTags.IsMovie = true; // this is a movie // Get Overview string overview = movieMatch.Overview; if (!String.IsNullOrWhiteSpace(overview) && String.IsNullOrWhiteSpace(videoTags.Description)) videoTags.Description = overview; // Get original release date if (movieMatch.ReleaseDate != null) { DateTime releaseDate = (DateTime)movieMatch.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 MovieDB dates, MovieDB Dates are more reliable than video metadata usually videoTags.OriginalBroadcastDateTime = releaseDate; // MovieDB stores time in network (local) timezone } // Get Genres List<string> genres = new List<string>(); foreach (Genre genre in movieMatch.Genres) { genres.Add(genre.Name); } if (genres.Count > 0) { if (videoTags.Genres != null) { if (videoTags.Genres.Length == 0) videoTags.Genres = genres.ToArray(); } else videoTags.Genres = genres.ToArray(); } // Download the banner file client.GetConfig(); // First we need to get the config VideoMetaData.DownloadBannerFile(videoTags, client.GetImageUrl("original", movieMatch.PosterPath).OriginalString); // Get bannerfile return true; // home free, we're good } return false; } catch { return false; } }
private void GetMovieInformations(string movieName) { const string baseUrl = @"https://d3gtl9l2a4fn1j.cloudfront.net/t/p/w185"; var client = new TMDbClient("9c51453ba783de3ed91ec927fe4b1ad3"); SearchContainer<SearchMovie> results = client.SearchMovie(movieName); var backPathOfPoster = results.Results[0].PosterPath; ImageSourceUrl = baseUrl + backPathOfPoster; MovieTitle = results.Results[0].Title; MovieReleaseDate = results.Results[0].ReleaseDate; MovieMaxRating = "/ 10"; MovieVoteAverage = results.Results[0].VoteAverage.ToString(); }