public Movie AddMovie(Movie newMovie) { Ensure.That(newMovie, () => newMovie).IsNotNull(); MoviePathState defaultState = MoviePathState.Static; if (!_configService.PathsDefaultStatic) { defaultState = MoviePathState.Dynamic; } if (string.IsNullOrWhiteSpace(newMovie.Path)) { var folderName = _fileNameBuilder.GetMovieFolder(newMovie); newMovie.Path = Path.Combine(newMovie.RootFolderPath, folderName); newMovie.PathState = defaultState; } else { newMovie.PathState = defaultState == MoviePathState.Dynamic ? MoviePathState.StaticOnce : MoviePathState.Static; } _logger.Info("Adding Movie {0} Path: [{1}]", newMovie, newMovie.Path); newMovie.CleanTitle = newMovie.Title.CleanSeriesTitle(); newMovie.SortTitle = MovieTitleNormalizer.Normalize(newMovie.Title, newMovie.TmdbId); newMovie.Added = DateTime.UtcNow; _movieRepository.Insert(newMovie); _eventAggregator.PublishEvent(new MovieAddedEvent(GetMovie(newMovie.Id))); return(newMovie); }
protected override bool IsValid(PropertyValidatorContext context) { if (context.PropertyValue == null) { return(true); } var movieResource = context.Instance as MovieResource; if (movieResource == null) { return(true); } var rootFolderPath = context.PropertyValue.ToString(); if (rootFolderPath.IsNullOrWhiteSpace()) { return(true); } var rootFolder = new DirectoryInfo(rootFolderPath).Name; var movie = movieResource.ToModel(); var movieFolder = _fileNameBuilder.GetMovieFolder(movie); if (movieFolder == rootFolder) { return(false); } var distance = movieFolder.LevenshteinDistance(rootFolder); return(distance >= Math.Max(1, movieFolder.Length * 0.2)); }
public void Execute(MoveMovieCommand message) { var movie = _movieService.GetMovie(message.MovieId); var source = message.SourcePath; var destination = message.DestinationPath; if (!message.DestinationRootFolder.IsNullOrWhiteSpace()) { _logger.Debug("Buiding destination path using root folder: {0} and the movie title", message.DestinationRootFolder); destination = Path.Combine(message.DestinationRootFolder, _filenameBuilder.GetMovieFolder(movie)); } _logger.ProgressInfo("Moving {0} from '{1}' to '{2}'", movie.Title, source, destination); //TODO: Move to transactional disk operations try { _diskTransferService.TransferFolder(source, destination, TransferMode.Move); } catch (IOException ex) { var errorMessage = string.Format("Unable to move movie from '{0}' to '{1}'", source, destination); _logger.Error(ex, errorMessage); throw; } _logger.ProgressInfo("{0} moved successfully to {1}", movie.Title, movie.Path); //Update the movie path to the new path movie.Path = destination; movie = _movieService.UpdateMovie(movie); _eventAggregator.PublishEvent(new MovieMovedEvent(movie, source, destination)); }
private IEnumerable <ImportListMoviesResource> MapToResource(IEnumerable <Movie> movies, Language language) { foreach (var currentMovie in movies) { var resource = DiscoverMoviesResourceMapper.ToResource(currentMovie); var poster = currentMovie.Images.FirstOrDefault(c => c.CoverType == MediaCoverTypes.Poster); if (poster != null) { resource.RemotePoster = poster.Url; } var translation = currentMovie.Translations.FirstOrDefault(t => t.Language == language); resource.Title = translation?.Title ?? resource.Title; resource.Overview = translation?.Overview ?? resource.Overview; resource.Folder = _fileNameBuilder.GetMovieFolder(currentMovie); yield return(resource); } }
public string BuildPath(Movie movie, bool useExistingRelativeFolder) { if (movie.RootFolderPath.IsNullOrWhiteSpace()) { throw new ArgumentException("Root folder was not provided", nameof(movie)); } if (useExistingRelativeFolder && movie.Path.IsNotNullOrWhiteSpace()) { var relativePath = GetExistingRelativePath(movie); return(Path.Combine(movie.RootFolderPath, relativePath)); } return(Path.Combine(movie.RootFolderPath, _fileNameBuilder.GetMovieFolder(movie))); }
// Add Movie: // Called whenever a movie is added from the GUI (and i assume via RSS feeds also) // Reason for patch: // Movie.Path must be root directory, not a sub folder. public static bool AddMovie(ref Movie newMovie, ref NzbDrone.Core.Movies.MovieService __instance, ref Logger ____logger, ref IConfigService ____configService, ref IMovieRepository ____movieRepository, ref IBuildFileNames ____fileNameBuilder, ref IEventAggregator ____eventAggregator, ref Movie __result) { var movie = newMovie; Ensure.That(newMovie, () => movie).IsNotNull(); Utility.WriteToConsole("Patched AddMovie called!", ConsoleColor.Green); Utility.WriteToConsole($"New movie {movie.Title} added, patching file path to not have sub folders...", ConsoleColor.Green); MoviePathState defaultState = MoviePathState.Static; if (!____configService.PathsDefaultStatic) { defaultState = MoviePathState.Dynamic; } if (string.IsNullOrWhiteSpace(movie.Path)) { // Call the original GetMovieFolder as it does other stuff too. var folderName = ____fileNameBuilder.GetMovieFolder(movie); // But replace our movie path with the root folder path, nothing more. movie.Path = newMovie.RootFolderPath; movie.PathState = defaultState; } else { movie.PathState = defaultState == MoviePathState.Dynamic ? MoviePathState.StaticOnce : MoviePathState.Static; } ____logger.Info("Adding Movie {0} Path: [{1}]", newMovie, newMovie.Path); movie.CleanTitle = newMovie.Title.CleanSeriesTitle(); movie.SortTitle = MovieTitleNormalizer.Normalize(movie.Title, movie.TmdbId); movie.Added = DateTime.UtcNow; ____movieRepository.Insert(newMovie); ____eventAggregator.PublishEvent(new MovieAddedEvent(__instance.GetMovie(movie.Id))); __result = movie; Utility.WriteToConsole($"Patching complete, new root directory of movie {movie.Title} is {movie.Path}", ConsoleColor.Green); Utility.WriteToConsole("Patching complete.", ConsoleColor.Green); return(false); }
public void Execute(BulkMoveMovieCommand message) { var moviesToMove = message.Movies; var destinationRootFolder = message.DestinationRootFolder; _logger.ProgressInfo("Moving {0} movies to '{1}'", moviesToMove.Count, destinationRootFolder); for (var index = 0; index < moviesToMove.Count; index++) { var s = moviesToMove[index]; var movie = _movieService.GetMovie(s.MovieId); var destinationPath = Path.Combine(destinationRootFolder, _filenameBuilder.GetMovieFolder(movie)); MoveSingleMovie(movie, s.SourcePath, destinationPath, index, moviesToMove.Count); } _logger.ProgressInfo("Finished moving {0} movies to '{1}'", moviesToMove.Count, destinationRootFolder); }
private Movie SetPropertiesAndValidate(Movie newMovie) { if (string.IsNullOrWhiteSpace(newMovie.Path)) { var folderName = _fileNameBuilder.GetMovieFolder(newMovie); newMovie.Path = Path.Combine(newMovie.RootFolderPath, folderName); } newMovie.CleanTitle = newMovie.Title.CleanMovieTitle(); newMovie.SortTitle = MovieTitleNormalizer.Normalize(newMovie.Title, newMovie.TmdbId); newMovie.Added = DateTime.UtcNow; var validationResult = _addMovieValidator.Validate(newMovie); if (!validationResult.IsValid) { throw new ValidationException(validationResult.Errors); } return(newMovie); }
private IEnumerable <MovieResource> MapToResource(IEnumerable <Movie> movies) { foreach (var currentMovie in movies) { var availDelay = _configService.AvailabilityDelay; var translation = currentMovie.Translations.FirstOrDefault(t => t.Language == (Language)_configService.MovieInfoLanguage); var resource = currentMovie.ToResource(availDelay, translation); _coverMapper.ConvertToLocalUrls(resource.Id, resource.Images); var poster = currentMovie.Images.FirstOrDefault(c => c.CoverType == MediaCoverTypes.Poster); if (poster != null) { resource.RemotePoster = poster.RemoteUrl; } resource.Folder = _fileNameBuilder.GetMovieFolder(currentMovie); yield return(resource); } }
public string GetMovieFolderSample(NamingConfig nameSpec) { return(_buildFileNames.GetMovieFolder(_movie, nameSpec)); }