public Movie(TmdbMovieResult movieResult, Guid mediaId) { MovieId = Guid.NewGuid(); MediaId = mediaId; ReleaseDate = movieResult.ReleaseDate; Runtime = movieResult.Runtime; }
public async Task <IActionResult> AddMovie(AddMovieViewModel addMedia) { Media media = _context.Medias.SingleOrDefault(m => m.TmdbId == addMedia.TmdbId); List <Genre> dbGenres = _context.Genres.ToList(); if (media == null) { MediaType mediaType = _context.MediaTypes.SingleOrDefault(m => m.Name == SpinningFilmHelper.MovieType); string responseBody = await _apiService.GetWithCreditsAsync(addMedia.TmdbId, SpinningFilmHelper.MovieType); TmdbMovieResult movieResult = JsonConvert.DeserializeObject <TmdbMovieResult>(responseBody); responseBody = await _apiService.GetOmdbResult(movieResult.ImdbId); RatingResult ratingResult = JsonConvert.DeserializeObject <RatingResult>(responseBody); media = new Media(movieResult, mediaType, ratingResult, movieResult.ImdbId); _context.Add(media); Movie movie = new Movie(movieResult, media.MediaId); _context.Add(movie); foreach (var item in movieResult.Genres) { var genre = dbGenres.SingleOrDefault(g => g.GenreId == item.GenreId) ?? _context.Genres.Add(item).Entity; MediaGenre mediaGenre = new MediaGenre(media.MediaId, genre); _context.Add(mediaGenre); } movieResult.Credits.Cast.ForEach(c => c.MediaId = media.MediaId); _context.Casts.AddRange(movieResult.Credits.Cast); movieResult.Credits.Crew.ForEach(c => c.MediaId = media.MediaId); _context.Crews.AddRange(movieResult.Credits.Crew); _context.SaveChanges(); } Guid userId = User.Identity.GetNameIdGuid(); if (!_context.PhysicalMedias.Any(m => m.AppUserId == userId && m.MediaId == media.MediaId)) { PhysicalMedia physicalMedia = new PhysicalMedia(media.MediaId, userId, (bool)addMedia.DigitalCopy, addMedia.DiscType); _context.PhysicalMedias.Add(physicalMedia); foreach (var genreId in addMedia.ExtraGenreIds) { var genre = dbGenres.SingleOrDefault(g => g.GenreId == genreId); ExtraGenre extraGenre = new ExtraGenre(physicalMedia.PhysicalMediaId, genre); _context.Add(extraGenre); } _context.SaveChanges(); return(View("AddMedia", media)); } return(RedirectToAction("Index", "Home")); }
public Media(TmdbMovieResult media, MediaType mediaType, RatingResult rating, string imdbId) { MediaId = Guid.NewGuid(); MediaTypeId = mediaType.MediaTypeId; ImdbId = imdbId; TmdbId = media.TmdbId; Title = media.Title; Poster = media.Poster; ImdbRating = rating.ImdbRating; Rated = rating.Rated; Metascore = rating.Metascore; PlotShort = rating.Plot; PlotLong = media.Plot; }
public async Task <IActionResult> DiscType() { string key = _apiService.GetTmdbKey(); string url = string.Format("https://api.themoviedb.org/3/genre/tv/list?api_key={0}", key); string responseBody = await _apiService.HttpGet(url); TmdbMovieResult result = JsonConvert.DeserializeObject <TmdbMovieResult>(responseBody); //foreach (var item in result.Genres) //{ // item.MediaType = "tv"; // _context.Add(item); //} _context.SaveChanges(); List <DiscType> discTypes = _context.DiscTypes.ToList(); return(View(discTypes)); }
public void GetTmdbPoster(CancellationToken cancellationToken, MyRecordingInfo recording) { cancellationToken.ThrowIfCancellationRequested(); var pluginPath = Plugin.Instance.ConfigurationFilePath.Remove(Plugin.Instance.ConfigurationFilePath.Length - 4); var localPoster = Path.Combine(pluginPath, "recordingposters", String.Join("", recording.Name.Split(Path.GetInvalidFileNameChars())) + ".jpg"); var localPosterMissing = Path.Combine(pluginPath, "recordingposters", String.Join("", recording.Name.Split(Path.GetInvalidFileNameChars())) + " [missing].jpg"); if (!Directory.Exists(Path.Combine(pluginPath, "recordingposters"))) { Directory.CreateDirectory(Path.Combine(pluginPath, "recordingposters")); } if (recording.IsMovie && !(File.Exists(localPoster) || File.Exists(localPosterMissing))) { try { using (var tmdbMovieSearch = _httpClient.Get(new HttpRequestOptions() { Url = $"https://api.themoviedb.org/3/search/movie?api_key=9dbbec013a2d32baf38ccc58006cd991&query={recording.Name}" + $"&language={_serverConfigurationManager.Configuration.PreferredMetadataLanguage}", CancellationToken = cancellationToken, BufferContent = false, EnableDefaultUserAgent = true, AcceptHeader = "application/json", EnableHttpCompression = true, DecompressionMethod = CompressionMethod.Gzip }).Result) { var movie = _json.DeserializeFromStream <TmdbMovieSearch>(tmdbMovieSearch); if (movie.total_results > 0) { TmdbMovieResult tmdbMovieResult = movie.results.Find(x => x.title.Equals(recording.Name) || x.original_title.Contains(recording.EpisodeTitle)) ?? movie.results.First(); if (recording.Year.HasValue) { tmdbMovieResult = movie.results.Find(x => x.release_date.StartsWith(recording.Year.Value.ToString())) ?? movie.results.First(); } var moviePoster = tmdbMovieResult.poster_path; if (!String.IsNullOrEmpty(moviePoster)) { using (WebClient client = new WebClient()) { client.DownloadFile(new Uri($"https://image.tmdb.org/t/p/w500{moviePoster}"), localPoster); } } else { File.Create(localPosterMissing); } } else { File.Create(localPosterMissing); } } } catch (WebException) { Plugin.Logger.Info("Could not download poster for Movie Recording: {0}", recording.Name); } } if (recording.SeasonNumber.HasValue && recording.EpisodeNumber.HasValue && !(File.Exists(localPoster) || File.Exists(localPosterMissing))) { try { using (var tmdbTvSearch = _httpClient.Get(new HttpRequestOptions() { Url = $"https://api.themoviedb.org/3/search/tv?api_key=9dbbec013a2d32baf38ccc58006cd991&query={recording.Name}" + $"&language={_serverConfigurationManager.Configuration.PreferredMetadataLanguage}", CancellationToken = cancellationToken, BufferContent = false, EnableDefaultUserAgent = true, AcceptHeader = "application/json", EnableHttpCompression = true, DecompressionMethod = CompressionMethod.Gzip }).Result) { //var posterUrl = string.Empty; //for (int i = 0; i < tvshow.results.Count; i++) //{ // TmdbTvResult tmdbTvResult = tvshow.results.ElementAt(i); // // using (var tmdbEpisode = await _httpClient.Get(new HttpRequestOptions() // { // Url = $"https://api.themoviedb.org/3/tv/{tmdbTvResult.id}/season/{recording.SeasonNumber}/episode/{recording.EpisodeNumber}?api_key=9dbbec013a2d32baf38ccc58006cd991" + $"&language={_serverConfigurationManager.Configuration.UICulture}", // CancellationToken = cancellationToken, // BufferContent = false, // EnableDefaultUserAgent = true, // AcceptHeader = "application/json", // EnableHttpCompression = true, // DecompressionMethod = CompressionMethod.Gzip // }).ConfigureAwait(true)) // { // var episode = _json.DeserializeFromStream<TmdbEpisodeResult>(tmdbEpisode); // // if (episode.name == recording.EpisodeTitle) // { // posterUrl = $"https://image.tmdb.org/t/p/original{tmdbTvResult.poster_path}"; // break; // } // } // // Thread.Sleep(400); //} var tvshow = _json.DeserializeFromStream <TmdbTvSearch>(tmdbTvSearch); if (tvshow.total_results > 0) { TmdbTvResult tmdbTvResult = tvshow.results.Find(x => x.name.Equals(recording.Name)) ?? tvshow.results.First(); var tvPoster = tmdbTvResult.poster_path; if (!String.IsNullOrEmpty(tvPoster)) { using (WebClient client = new WebClient()) { client.DownloadFile(new Uri($"https://image.tmdb.org/t/p/w500{tvPoster}"), localPoster); } } else { File.Create(localPosterMissing); } } else { File.Create(localPosterMissing); } } } catch (WebException) { Plugin.Logger.Info("Could not download poster for TV Show Recording: {0}", recording.Name); } } }
public IActionResult MovieResult(string imdbId) { WebRequest request; HttpWebResponse response; string result = null; string api = "api_key=8d8ebd7ef7cb1361e624639ac8fea328"; string finalResponse = ""; string getImdbIdUrl = String.Format("https://api.themoviedb.org/3/find/" + imdbId + "?" + api + "&external_source=imdb_id"); request = WebRequest.Create(getImdbIdUrl); request.Method = "GET"; response = (HttpWebResponse)request.GetResponse(); using (Stream streamImdb = response.GetResponseStream()) { StreamReader streamReaderImdb = new StreamReader(streamImdb); result = streamReaderImdb.ReadToEnd(); streamReaderImdb.Close(); } ImdbMovieResult imdbMovieResult = JsonConvert.DeserializeObject <ImdbMovieResult>(result); int tmdbId = imdbMovieResult.movie_results.FirstOrDefault().id; bool isThereAnyMovie = _movieService.IsItExistsByTmdbId(tmdbId); if (isThereAnyMovie) { finalResponse += "This movie already exists in the Database!"; } else { string getTmdbIdUrl = String.Format("https://api.themoviedb.org/3/movie/" + tmdbId + "?" + api + "&language=en-US"); request = WebRequest.Create(getTmdbIdUrl); response = (HttpWebResponse)request.GetResponse(); using (Stream streamTmdb = response.GetResponseStream()) { StreamReader streamReaderTmdb = new StreamReader(streamTmdb); result = streamReaderTmdb.ReadToEnd(); streamReaderTmdb.Close(); } TmdbMovieResult tmdbMovieResult = JsonConvert.DeserializeObject <TmdbMovieResult>(result); bool isMovieCreated = _movieService.Create(tmdbMovieResult); if (isMovieCreated) { finalResponse += "Movie were inserted into the Database!"; } else { finalResponse += "Some error!"; } } bool isThereAnyCredits = _creditService.IsItExistsByTmdbId(tmdbId); if (isThereAnyCredits) { finalResponse += "\nThese credits already exists in the Database!"; } else { string getCreditsIdUrl = String.Format("https://api.themoviedb.org/3/movie/" + tmdbId + "/credits?" + api); request = WebRequest.Create(getCreditsIdUrl); response = (HttpWebResponse)request.GetResponse(); using (Stream streamCredits = response.GetResponseStream()) { StreamReader streamReaderCredits = new StreamReader(streamCredits); result = streamReaderCredits.ReadToEnd(); streamReaderCredits.Close(); } MovieCredits movieCredits = JsonConvert.DeserializeObject <MovieCredits>(result); bool isCreditsCreated = _creditService.Create(movieCredits); if (isCreditsCreated) { finalResponse += "Credites were inserted into the Database!"; } else { finalResponse += "Some error!"; } //int counter = 0; //foreach (var cast in movieCredits.cast) //{ // bool isThereAnyPersonImegas = _personImagesService.IsItExistsByPersonId(cast.id); // if (isThereAnyPersonImegas) // continue; // else // counter++; // string getPersonImageIdUrl = String.Format("https://api.themoviedb.org/3/person/" + cast.id + "/images?" + api); // request = WebRequest.Create(getPersonImageIdUrl); // response = (HttpWebResponse)request.GetResponse(); // using (Stream streamPersonImages = response.GetResponseStream()) // { // StreamReader streamReaderPersonImages = new StreamReader(streamPersonImages); // result = streamReaderPersonImages.ReadToEnd(); // streamReaderPersonImages.Close(); // } // PersonImages personImages = JsonConvert.DeserializeObject<PersonImages>(result); // var orderedPersonImages = personImages.profiles.OrderByDescending(x => x.vote_average).ToList(); // personImages.profiles = orderedPersonImages; // personImages.id = cast.id; // bool isPersonImagesCreated = _personImagesService.Create(personImages); //} int personDetailsCounter = 0; foreach (var cast in movieCredits.cast) { bool isThereAnyPersonDetails = _personService.IsItExistsByPersonId(cast.id); if (isThereAnyPersonDetails) { continue; } else { personDetailsCounter++; } string getPersonDetailsIdUrl = String.Format("https://api.themoviedb.org/3/person/" + cast.id + "?" + api + "&language=en-US"); request = WebRequest.Create(getPersonDetailsIdUrl); response = (HttpWebResponse)request.GetResponse(); using (Stream streamPersonDetails = response.GetResponseStream()) { StreamReader streamReaderPersonDetails = new StreamReader(streamPersonDetails); result = streamReaderPersonDetails.ReadToEnd(); streamReaderPersonDetails.Close(); } PersonDetails personDetails = JsonConvert.DeserializeObject <PersonDetails>(result); bool isPersonImagesCreated = _personService.Create(personDetails); } finalResponse += "\n" + personDetailsCounter + " actor profiles were inserted into the Database!"; } return(Ok(JsonConvert.SerializeObject(finalResponse))); }
public void GetTmdbImage(CancellationToken cancellationToken, MyRecordingInfo recording) { cancellationToken.ThrowIfCancellationRequested(); var config = Plugin.Instance.Configuration; var pluginPath = Plugin.Instance.ConfigurationFilePath.Remove(Plugin.Instance.ConfigurationFilePath.Length - 4); var localImage = Path.Combine(pluginPath, "recordingposters", String.Join("", recording.Name.Split(Path.GetInvalidFileNameChars())) + ".jpg"); var localImageMissing = Path.Combine(pluginPath, "recordingposters", String.Join("", recording.Name.Split(Path.GetInvalidFileNameChars())) + " [missing].jpg"); if (!Directory.Exists(Path.Combine(pluginPath, "recordingposters"))) { Directory.CreateDirectory(Path.Combine(pluginPath, "recordingposters")); } if ((recording.IsMovie || (!recording.EpisodeNumber.HasValue && (recording.EndDate - recording.StartDate) > TimeSpan.FromMinutes(70))) && !(File.Exists(localImage) || File.Exists(localImageMissing))) { try { using (var tmdbMovieSearch = _httpClient.Get(new HttpRequestOptions() { Url = $"https://api.themoviedb.org/3/search/movie?api_key=9dbbec013a2d32baf38ccc58006cd991&query={recording.MovieName}" + $"&language={_serverConfigurationManager.Configuration.PreferredMetadataLanguage}", CancellationToken = cancellationToken, BufferContent = false, EnableDefaultUserAgent = true, AcceptHeader = "application/json", EnableHttpCompression = true, DecompressionMethod = CompressionMethod.Gzip }).Result) { var movie = _json.DeserializeFromStream <TmdbMovieSearch>(tmdbMovieSearch); if (movie.total_results > 0) { TmdbMovieResult tmdbMovieResult = movie.results.Find(x => x.title.Equals(recording.MovieName) || x.original_title.Contains(recording.EpisodeTitle)) ?? movie.results.First(); if (recording.MovieYear.HasValue) { tmdbMovieResult = movie.results.Find(x => x.release_date.StartsWith(recording.MovieYear.Value.ToString())) ?? movie.results.First(); } var moviePoster = tmdbMovieResult.poster_path; var movieBackdrop = tmdbMovieResult.backdrop_path; if (config.RecGenreMapping) { if (!String.IsNullOrEmpty(moviePoster)) { using (WebClient client = new WebClient()) { client.DownloadFile(new Uri($"https://image.tmdb.org/t/p/w500{moviePoster}"), localImage); } } else { File.Create(localImageMissing); } } if (!config.RecGenreMapping) { if (!String.IsNullOrEmpty(movieBackdrop)) { using (WebClient client = new WebClient()) { client.DownloadFile(new Uri($"https://image.tmdb.org/t/p/w500{movieBackdrop}"), localImage); } } else { File.Create(localImageMissing); } } } else { File.Create(localImageMissing); } } } catch (WebException) { Plugin.Logger.Info("Could not download poster for Movie Recording: {0}", recording.Name); } } if ((recording.IsSeries || recording.EpisodeNumber.HasValue) && !(File.Exists(localImage) || File.Exists(localImageMissing))) { try { using (var tmdbTvSearch = _httpClient.Get(new HttpRequestOptions() { Url = $"https://api.themoviedb.org/3/search/tv?api_key=9dbbec013a2d32baf38ccc58006cd991&query={recording.Name}" + $"&language={_serverConfigurationManager.Configuration.PreferredMetadataLanguage}", CancellationToken = cancellationToken, BufferContent = false, EnableDefaultUserAgent = true, AcceptHeader = "application/json", EnableHttpCompression = true, DecompressionMethod = CompressionMethod.Gzip }).Result) { var tvshow = _json.DeserializeFromStream <TmdbTvSearch>(tmdbTvSearch); if (tvshow.total_results > 0) { TmdbTvResult tmdbTvResult = tvshow.results.Find(x => x.name.Equals(recording.Name)) ?? tvshow.results.First(); var tvPoster = tmdbTvResult.poster_path; var tvBackdrop = tmdbTvResult.backdrop_path; if (config.RecGenreMapping) { if (!String.IsNullOrEmpty(tvPoster)) { using (WebClient client = new WebClient()) { client.DownloadFile(new Uri($"https://image.tmdb.org/t/p/w500{tvPoster}"), localImage); } } else { File.Create(localImageMissing); } } if (!config.RecGenreMapping) { if (!String.IsNullOrEmpty(tvBackdrop)) { using (WebClient client = new WebClient()) { client.DownloadFile(new Uri($"https://image.tmdb.org/t/p/w500{tvBackdrop}"), localImage); } } else { File.Create(localImageMissing); } } } else { File.Create(localImageMissing); } } } catch (WebException) { Plugin.Logger.Info("Could not download poster for TV Show Recording: {0}", recording.Name); } } }
public bool Create(TmdbMovieResult movie) { _movies.InsertOne(movie); return(true); }