public void MoviesImageAssertion() { List <string> listOfMovies = new List <string>(); for (int i = 0; i < MovieImages.Count(); i++) { listOfMovies.Add(MovieImages[i].GetAttribute("src").ToString().Substring(0, 1)); Assert.AreEqual("d", listOfMovies[i]); } }
public void AddImage(List <IFormFile> files, int Id) { var movies = movieRepository.Get(x => x.Id == Id); string uploadDir = Path.Combine(Environment.WebRootPath, "media/movie"); if (!Directory.Exists(uploadDir)) { Directory.CreateDirectory(uploadDir); } foreach (IFormFile postedFile in files) { string fileName = Path.GetFileName(postedFile.FileName); using (FileStream stream = new FileStream(Path.Combine(uploadDir, fileName), FileMode.Create)) { MovieImages movieImages = new MovieImages(); postedFile.CopyTo(stream); _movieImageService.Add(movieImages, movies.Id, fileName); } } }
/// <summary> /// Processes the images. /// </summary> /// <param name="item">The item.</param> /// <param name="images">The images.</param> /// <param name="cancellationToken">The cancellation token</param> /// <returns>Task.</returns> protected virtual async Task <ProviderRefreshStatus> ProcessImages(BaseItem item, MovieImages images, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var status = ProviderRefreshStatus.Success; // poster if (images.posters != null && images.posters.Count > 0 && !item.HasImage(ImageType.Primary)) { var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false); var tmdbImageUrl = tmdbSettings.images.base_url + ConfigurationManager.Configuration.TmdbFetchedPosterSize; // get highest rated poster for our language var postersSortedByVote = images.posters.OrderByDescending(i => i.vote_average); var poster = postersSortedByVote.FirstOrDefault(p => p.iso_639_1 != null && p.iso_639_1.Equals(ConfigurationManager.Configuration.PreferredMetadataLanguage, StringComparison.OrdinalIgnoreCase)); if (poster == null && !ConfigurationManager.Configuration.PreferredMetadataLanguage.Equals("en")) { // couldn't find our specific language, find english (if that wasn't our language) poster = postersSortedByVote.FirstOrDefault(p => p.iso_639_1 != null && p.iso_639_1.Equals("en", StringComparison.OrdinalIgnoreCase)); } if (poster == null) { //still couldn't find it - try highest rated null one poster = postersSortedByVote.FirstOrDefault(p => p.iso_639_1 == null); } if (poster == null) { //finally - just get the highest rated one poster = postersSortedByVote.FirstOrDefault(); } if (poster != null) { var img = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions { Url = tmdbImageUrl + poster.file_path, CancellationToken = cancellationToken }).ConfigureAwait(false); await _providerManager.SaveImage(item, img, MimeTypes.GetMimeType(poster.file_path), ImageType.Primary, null, cancellationToken) .ConfigureAwait(false); } } cancellationToken.ThrowIfCancellationRequested(); // backdrops - only download if earlier providers didn't find any (fanart) if (images.backdrops != null && images.backdrops.Count > 0 && ConfigurationManager.Configuration.DownloadMovieImages.Backdrops && item.BackdropImagePaths.Count == 0) { var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false); var tmdbImageUrl = tmdbSettings.images.base_url + ConfigurationManager.Configuration.TmdbFetchedBackdropSize; for (var i = 0; i < images.backdrops.Count; i++) { var bdName = "backdrop" + (i == 0 ? "" : i.ToString(CultureInfo.InvariantCulture)); var hasLocalBackdrop = item.LocationType == LocationType.FileSystem && ConfigurationManager.Configuration.SaveLocalMeta ? item.HasLocalImage(bdName) : item.BackdropImagePaths.Count > i; if (!hasLocalBackdrop) { var img = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions { Url = tmdbImageUrl + images.backdrops[i].file_path, CancellationToken = cancellationToken }).ConfigureAwait(false); await _providerManager.SaveImage(item, img, MimeTypes.GetMimeType(images.backdrops[i].file_path), ImageType.Backdrop, item.BackdropImagePaths.Count, cancellationToken) .ConfigureAwait(false); } if (item.BackdropImagePaths.Count >= ConfigurationManager.Configuration.MaxBackdrops) { break; } } } return(status); }
/// <summary> /// Processes the images. /// </summary> /// <param name="item">The item.</param> /// <param name="images">The images.</param> /// <param name="cancellationToken">The cancellation token</param> /// <returns>Task.</returns> protected virtual async Task<ProviderRefreshStatus> ProcessImages(BaseItem item, MovieImages images, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var status = ProviderRefreshStatus.Success; // poster if (images.posters != null && images.posters.Count > 0 && !item.HasImage(ImageType.Primary)) { var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false); var tmdbImageUrl = tmdbSettings.images.base_url + ConfigurationManager.Configuration.TmdbFetchedPosterSize; // get highest rated poster for our language var postersSortedByVote = images.posters.OrderByDescending(i => i.vote_average); var poster = postersSortedByVote.FirstOrDefault(p => p.iso_639_1 != null && p.iso_639_1.Equals(ConfigurationManager.Configuration.PreferredMetadataLanguage, StringComparison.OrdinalIgnoreCase)); if (poster == null && !ConfigurationManager.Configuration.PreferredMetadataLanguage.Equals("en")) { // couldn't find our specific language, find english (if that wasn't our language) poster = postersSortedByVote.FirstOrDefault(p => p.iso_639_1 != null && p.iso_639_1.Equals("en", StringComparison.OrdinalIgnoreCase)); } if (poster == null) { //still couldn't find it - try highest rated null one poster = postersSortedByVote.FirstOrDefault(p => p.iso_639_1 == null); } if (poster == null) { //finally - just get the highest rated one poster = postersSortedByVote.FirstOrDefault(); } if (poster != null) { var img = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions { Url = tmdbImageUrl + poster.file_path, CancellationToken = cancellationToken }).ConfigureAwait(false); await _providerManager.SaveImage(item, img, MimeTypes.GetMimeType(poster.file_path), ImageType.Primary, null, cancellationToken) .ConfigureAwait(false); } } cancellationToken.ThrowIfCancellationRequested(); // backdrops - only download if earlier providers didn't find any (fanart) if (images.backdrops != null && images.backdrops.Count > 0 && ConfigurationManager.Configuration.DownloadMovieImages.Backdrops && item.BackdropImagePaths.Count == 0) { var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false); var tmdbImageUrl = tmdbSettings.images.base_url + ConfigurationManager.Configuration.TmdbFetchedBackdropSize; for (var i = 0; i < images.backdrops.Count; i++) { var bdName = "backdrop" + (i == 0 ? "" : i.ToString(CultureInfo.InvariantCulture)); var hasLocalBackdrop = item.LocationType == LocationType.FileSystem && ConfigurationManager.Configuration.SaveLocalMeta ? item.HasLocalImage(bdName) : item.BackdropImagePaths.Count > i; if (!hasLocalBackdrop) { var img = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions { Url = tmdbImageUrl + images.backdrops[i].file_path, CancellationToken = cancellationToken }).ConfigureAwait(false); await _providerManager.SaveImage(item, img, MimeTypes.GetMimeType(images.backdrops[i].file_path), ImageType.Backdrop, item.BackdropImagePaths.Count, cancellationToken) .ConfigureAwait(false); } if (item.BackdropImagePaths.Count >= ConfigurationManager.Configuration.MaxBackdrops) { break; } } } return status; }
public void Add(MovieImages image, int movieId, string path) { image.Path = path; image.MovieId = movieId; _movieImageRepository.Add(image); }
public IActionResult Add(MovieVM model, int[] genres, int[] directorarray, int[] scenaristarray, int[] stararray) { string imagepath = ""; if (model.movieposter != null) { var guid = Guid.NewGuid().ToString(); var path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot/adminsite/movieposter", guid + ".jpg"); using (var stream = new FileStream(path, FileMode.Create)) { model.movieposter.CopyTo(stream); } imagepath = guid + ".jpg"; } List <string> paths = new List <string>(); string imgpaths = ""; if (model.movieImages != null) { foreach (var item in model.movieImages) { var guid = Guid.NewGuid().ToString(); var path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot/adminsite/movieimages", guid + ".jpg"); using (var stream = new FileStream(path, FileMode.Create)) { item.CopyTo(stream); } imgpaths = guid + ".jpg"; paths.Add(imgpaths); } } model.imagepaths = paths; if (ModelState.IsValid) { Movie movie = new Movie(); movie.Name = model.name; movie.Duration = model.duration; movie.ReleaseDate = model.releasedate; movie.PosterURL = imagepath; movie.Description = model.description; _context.Movies.Add(movie); _context.SaveChanges(); int MovieID = movie.ID; foreach (var item in genres) { MovieGenre movieGenre = new MovieGenre(); movieGenre.MovieID = MovieID; movieGenre.GenreID = item; _context.MovieGenres.Add(movieGenre); } foreach (var item in directorarray) { MoviePerson moviePerson = new MoviePerson(); moviePerson.MovieID = MovieID; moviePerson.PersonID = item; moviePerson.JobID = 1; _context.MoviePeople.Add(moviePerson); } foreach (var item in scenaristarray) { MoviePerson moviePerson = new MoviePerson(); moviePerson.MovieID = MovieID; moviePerson.PersonID = item; moviePerson.JobID = 2; _context.MoviePeople.Add(moviePerson); } foreach (var item in stararray) { MoviePerson moviePerson = new MoviePerson(); moviePerson.MovieID = MovieID; moviePerson.PersonID = item; moviePerson.JobID = 3; _context.MoviePeople.Add(moviePerson); } foreach (var item in model.imagepaths) { MovieImages image = new MovieImages(); image.ImagePath = item; image.MovieID = MovieID; _context.MovieImages.Add(image); } _context.SaveChanges(); //return RedirectToAction("Index", "Movie"); return(Redirect("/Admin/Movie/Index")); } else { return(View(getGenresJob())); } }