private static List <Song> GetSoundtrackFromTunefind(int id, Tunefind tf) { List <Song> soundtrack = new List <Song>(); var response = tf.GetSoundtracks(id); if (response != null) { foreach (var song in response.songs) { soundtrack.Add(new Song { Id = song.id, Name = song.name, TunefindUrl = song.tunefind_url, Artist = new Artist { Id = song.artist.id, Name = song.artist.name, TunefindUrl = song.artist.tunefind_url } }); } } return(soundtrack); }
static void Main(string[] args) { MongoClient client = CreateClient(); IMongoDatabase db = client.GetDatabase(_databaseName); IMongoCollection <TMDBAPIResponse> movieCollection = db.GetCollection <TMDBAPIResponse>(_moviesCollection); IMongoCollection <Id> ids = db.GetCollection <Id>("ids"); Tunefind tf = new Tunefind(); TraktTV ttv = new TraktTV(); FreeTrialInitializationTunefind(movieCollection, tf, ttv); InitializeGenres(db.GetCollection <Genre>(_genresCollection)); var latestFound = ids.Find(x => true).FirstOrDefault(); var latestId = (latestFound == null) ? 0 : latestFound.id; var latestIdReal = GetLatestIdFromTmdb(); for (int i = latestId + 1; i < latestIdReal; i++) { var movieDetails = FetchMovieDetailsById(i); if (ids.CountDocuments(x => true) == 1) { ids.FindOneAndDelete(x => true); } ids.InsertOne(new Id(i)); if (movieDetails != null && !String.IsNullOrEmpty(movieDetails.release_date) && movieDetails.original_language.Equals("en")) { if (movieDetails.runtime == null) { movieDetails.runtime = 0; } List <TraktTVSimilar> traktTVSimilars = new List <TraktTVSimilar>(); foreach (var ts in ttv.GetTraktTVResponse(movieDetails.imdb_id)) { traktTVSimilars.Add(new TraktTVSimilar { Title = ts.title, ImdbId = ts.ids.imdb, TmdbId = ts.ids.tmdb }); } movieDetails.TraktSimilars = traktTVSimilars; movieDetails.Ratings = GetRatingsFromImdbId(movieDetails.imdb_id); movieDetails.Soundtrack = GetSoundtrackFromTunefind(movieDetails.id, tf); movieDetails.AppRating = new AppRating(); SafeInsert(movieDetails, movieCollection); } } }
private static void FreeTrialInitializationTunefind(IMongoCollection <TMDBAPIResponse> movieCollection, Tunefind tf, TraktTV ttv) { int[] ids = new int[] { 431530, 400106, 483104, 459954, 446791, 436459, 486859, 301337, 353486, 141052 }; for (int i = 0; i < ids.Length; i++) { var movieDetails = FetchMovieDetailsById(ids[i]); List <TraktTVSimilar> traktTVSimilars = new List <TraktTVSimilar>(); foreach (var ts in ttv.GetTraktTVResponse(movieDetails.imdb_id)) { traktTVSimilars.Add(new TraktTVSimilar { Title = ts.title, ImdbId = ts.ids.imdb, TmdbId = ts.ids.tmdb }); } movieDetails.TraktSimilars = traktTVSimilars; movieDetails.Ratings = GetRatingsFromImdbId(movieDetails.imdb_id); movieDetails.Soundtrack = GetSoundtrackFromTunefind(movieDetails.id, tf); movieDetails.AppRating = new AppRating(); SafeInsert(movieDetails, movieCollection); } }