mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-05 02:22:31 +01:00
Merge pull request #74 from fedoranimus/develop
Taking a pass at Library import and rename/organize
This commit is contained in:
commit
f1914082b8
@ -107,8 +107,8 @@ public static ReleaseResource ToResource(this DownloadDecision model)
|
||||
ReleaseGroup = parsedMovieInfo.ReleaseGroup,
|
||||
ReleaseHash = parsedMovieInfo.ReleaseHash,
|
||||
Title = releaseInfo.Title,
|
||||
FullSeason = parsedMovieInfo.FullSeason,
|
||||
SeasonNumber = parsedMovieInfo.SeasonNumber,
|
||||
//FullSeason = parsedMovieInfo.FullSeason,
|
||||
//SeasonNumber = parsedMovieInfo.SeasonNumber,
|
||||
Language = parsedMovieInfo.Language,
|
||||
AirDate = "",
|
||||
SeriesTitle = parsedMovieInfo.MovieTitle,
|
||||
@ -138,7 +138,7 @@ public static ReleaseResource ToResource(this DownloadDecision model)
|
||||
IsDaily = false,
|
||||
IsAbsoluteNumbering = false,
|
||||
IsPossibleSpecialEpisode = false,
|
||||
Special = parsedMovieInfo.Special,
|
||||
//Special = parsedMovieInfo.Special,
|
||||
};
|
||||
}
|
||||
|
||||
|
11
src/NzbDrone.Api/Movies/MovieModule.cs
Normal file
11
src/NzbDrone.Api/Movies/MovieModule.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Api.Movies
|
||||
{
|
||||
class MovieModule
|
||||
{
|
||||
}
|
||||
}
|
35
src/NzbDrone.Api/Movies/RenameMovieModule.cs
Normal file
35
src/NzbDrone.Api/Movies/RenameMovieModule.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using NzbDrone.Api.REST;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Api.Movies
|
||||
{
|
||||
public class RenameMovieModule : NzbDroneRestModule<RenameMovieResource>
|
||||
{
|
||||
private readonly IRenameMovieFileService _renameMovieFileService;
|
||||
|
||||
public RenameMovieModule(IRenameMovieFileService renameMovieFileService)
|
||||
: base("rename")
|
||||
{
|
||||
_renameMovieFileService = renameMovieFileService;
|
||||
|
||||
GetResourceAll = GetMovies; //TODO: GetResourceSingle?
|
||||
}
|
||||
|
||||
private List<RenameMovieResource> GetMovies()
|
||||
{
|
||||
if(!Request.Query.MovieId.HasValue)
|
||||
{
|
||||
throw new BadRequestException("movieId is missing");
|
||||
}
|
||||
|
||||
var movieId = (int)Request.Query.MovieId;
|
||||
|
||||
return _renameMovieFileService.GetRenamePreviews(movieId).ToResource();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
35
src/NzbDrone.Api/Movies/RenameMovieResource.cs
Normal file
35
src/NzbDrone.Api/Movies/RenameMovieResource.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using NzbDrone.Api.REST;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Api.Movies
|
||||
{
|
||||
public class RenameMovieResource : RestResource
|
||||
{
|
||||
public int MovieId { get; set; }
|
||||
public int MovieFileId { get; set; }
|
||||
public string ExistingPath { get; set; }
|
||||
public string NewPath { get; set; }
|
||||
}
|
||||
|
||||
public static class RenameMovieResourceMapper
|
||||
{
|
||||
public static RenameMovieResource ToResource(this Core.MediaFiles.RenameMovieFilePreview model)
|
||||
{
|
||||
if (model == null) return null;
|
||||
|
||||
return new RenameMovieResource
|
||||
{
|
||||
MovieId = model.MovieId,
|
||||
MovieFileId = model.MovieFileId,
|
||||
ExistingPath = model.ExistingPath,
|
||||
NewPath = model.NewPath
|
||||
};
|
||||
}
|
||||
|
||||
public static List<RenameMovieResource> ToResource(this IEnumerable<Core.MediaFiles.RenameMovieFilePreview> models)
|
||||
{
|
||||
return models.Select(ToResource).ToList();
|
||||
}
|
||||
}
|
||||
}
|
@ -116,6 +116,9 @@
|
||||
<Compile Include="Frontend\Mappers\RobotsTxtMapper.cs" />
|
||||
<Compile Include="Indexers\ReleaseModuleBase.cs" />
|
||||
<Compile Include="Indexers\ReleasePushModule.cs" />
|
||||
<Compile Include="Movies\MovieModule.cs" />
|
||||
<Compile Include="Movies\RenameMovieModule.cs" />
|
||||
<Compile Include="Movies\RenameMovieResource.cs" />
|
||||
<Compile Include="Parse\ParseModule.cs" />
|
||||
<Compile Include="Parse\ParseResource.cs" />
|
||||
<Compile Include="ManualImport\ManualImportModule.cs" />
|
||||
|
@ -18,7 +18,7 @@ public MovieResource()
|
||||
//Todo: Sorters should be done completely on the client
|
||||
//Todo: Is there an easy way to keep IgnoreArticlesWhenSorting in sync between, Series, History, Missing?
|
||||
//Todo: We should get the entire Profile instead of ID and Name separately
|
||||
|
||||
|
||||
//View Only
|
||||
public string Title { get; set; }
|
||||
public List<AlternateTitleResource> AlternateTitles { get; set; }
|
||||
@ -33,6 +33,7 @@ public MovieResource()
|
||||
public bool Downloaded { get; set; }
|
||||
public string RemotePoster { get; set; }
|
||||
public int Year { get; set; }
|
||||
public bool HasFile { get; set; }
|
||||
|
||||
//View & Edit
|
||||
public string Path { get; set; }
|
||||
@ -84,12 +85,17 @@ public static MovieResource ToResource(this Core.Tv.Movie model)
|
||||
long size = 0;
|
||||
bool downloaded = false;
|
||||
|
||||
|
||||
if(model.MovieFile != null)
|
||||
{
|
||||
model.MovieFile.LazyLoad();
|
||||
}
|
||||
|
||||
if (model.MovieFile != null && model.MovieFile.IsLoaded && model.MovieFile.Value != null)
|
||||
{
|
||||
size = model.MovieFile.Value.Size;
|
||||
downloaded = true;
|
||||
}
|
||||
//long Size = model.MovieFile != null ? model.MovieFile.Value.Size : 0;
|
||||
|
||||
return new MovieResource
|
||||
{
|
||||
@ -100,7 +106,7 @@ public static MovieResource ToResource(this Core.Tv.Movie model)
|
||||
SortTitle = model.SortTitle,
|
||||
InCinemas = model.InCinemas,
|
||||
PhysicalRelease = model.PhysicalRelease,
|
||||
|
||||
HasFile = model.HasFile,
|
||||
Downloaded = downloaded,
|
||||
//TotalEpisodeCount
|
||||
//EpisodeCount
|
||||
|
@ -111,6 +111,18 @@ public void Handle(MediaCoversUpdatedEvent message)
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Implementing this will fix a lot of our warning exceptions
|
||||
//public void Handle(MediaCoversUpdatedEvent message)
|
||||
//{
|
||||
// var movie = message.Movie;
|
||||
// var movieFiles = GetMovieFiles(movie.Id);
|
||||
|
||||
// foreach (var extraFileManager in _extraFileManagers)
|
||||
// {
|
||||
// extraFileManager.CreateAfterMovieScan(movie, movieFiles);
|
||||
// }
|
||||
//}
|
||||
|
||||
public void Handle(EpisodeFolderCreatedEvent message)
|
||||
{
|
||||
var series = message.Series;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles.Commands
|
||||
|
19
src/NzbDrone.Core/MediaFiles/Commands/RenameMovieCommand.cs
Normal file
19
src/NzbDrone.Core/MediaFiles/Commands/RenameMovieCommand.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles.Commands
|
||||
{
|
||||
public class RenameMovieCommand : Command
|
||||
{
|
||||
public List<int> MovieIds { get; set; }
|
||||
|
||||
public override bool SendUpdatesToClient => true;
|
||||
|
||||
public RenameMovieCommand()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles.Commands
|
||||
{
|
||||
public class RenameMovieFilesCommand : Command
|
||||
{
|
||||
public int MovieId { get; set; }
|
||||
public List<int> Files { get; set; }
|
||||
|
||||
public override bool SendUpdatesToClient => true;
|
||||
|
||||
public RenameMovieFilesCommand()
|
||||
{
|
||||
}
|
||||
|
||||
public RenameMovieFilesCommand(int movieId, List<int> files)
|
||||
{
|
||||
MovieId = movieId;
|
||||
Files = files;
|
||||
}
|
||||
}
|
||||
}
|
@ -38,6 +38,7 @@ public class DiskScanService :
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IMakeImportDecision _importDecisionMaker;
|
||||
private readonly IImportApprovedEpisodes _importApprovedEpisodes;
|
||||
private readonly IImportApprovedMovie _importApprovedMovies;
|
||||
private readonly IConfigService _configService;
|
||||
private readonly ISeriesService _seriesService;
|
||||
private readonly IMediaFileTableCleanupService _mediaFileTableCleanupService;
|
||||
@ -48,6 +49,7 @@ public class DiskScanService :
|
||||
public DiskScanService(IDiskProvider diskProvider,
|
||||
IMakeImportDecision importDecisionMaker,
|
||||
IImportApprovedEpisodes importApprovedEpisodes,
|
||||
IImportApprovedMovie importApprovedMovies,
|
||||
IConfigService configService,
|
||||
ISeriesService seriesService,
|
||||
IMediaFileTableCleanupService mediaFileTableCleanupService,
|
||||
@ -58,6 +60,7 @@ public DiskScanService(IDiskProvider diskProvider,
|
||||
_diskProvider = diskProvider;
|
||||
_importDecisionMaker = importDecisionMaker;
|
||||
_importApprovedEpisodes = importApprovedEpisodes;
|
||||
_importApprovedMovies = importApprovedMovies;
|
||||
_configService = configService;
|
||||
_seriesService = seriesService;
|
||||
_mediaFileTableCleanupService = mediaFileTableCleanupService;
|
||||
@ -179,7 +182,8 @@ public void Scan(Movie movie)
|
||||
decisionsStopwatch.Stop();
|
||||
_logger.Trace("Import decisions complete for: {0} [{1}]", movie, decisionsStopwatch.Elapsed);
|
||||
|
||||
_importApprovedEpisodes.Import(decisions, false);
|
||||
//_importApprovedEpisodes.Import(decisions, false);
|
||||
_importApprovedMovies.Import(decisions, false);
|
||||
|
||||
_logger.Info("Completed scanning disk for {0}", movie.Title);
|
||||
_eventAggregator.PublishEvent(new MovieScannedEvent(movie));
|
||||
|
@ -159,7 +159,7 @@ private List<ImportResult> ProcessFolder(DirectoryInfo directoryInfo, ImportMode
|
||||
}
|
||||
|
||||
var cleanedUpName = GetCleanedUpFolderName(directoryInfo.Name);
|
||||
var folderInfo = Parser.Parser.ParseTitle(directoryInfo.Name);
|
||||
var folderInfo = Parser.Parser.ParseMovieTitle(directoryInfo.Name);
|
||||
|
||||
if (folderInfo != null)
|
||||
{
|
||||
|
@ -47,6 +47,8 @@ public ImportApprovedMovie(IUpgradeMediaFiles episodeFileUpgrader,
|
||||
|
||||
public List<ImportResult> Import(List<ImportDecision> decisions, bool newDownload, DownloadClientItem downloadClientItem = null, ImportMode importMode = ImportMode.Auto)
|
||||
{
|
||||
_logger.Debug("Decisions: {0}", decisions.Count);
|
||||
|
||||
var qualifiedImports = decisions.Where(c => c.Approved)
|
||||
.GroupBy(c => c.LocalMovie.Movie.Id, (i, s) => s
|
||||
.OrderByDescending(c => c.LocalMovie.Quality, new QualityModelComparer(s.First().LocalMovie.Movie.Profile))
|
||||
@ -80,7 +82,7 @@ public List<ImportResult> Import(List<ImportDecision> decisions, bool newDownloa
|
||||
episodeFile.Quality = localMovie.Quality;
|
||||
episodeFile.MediaInfo = localMovie.MediaInfo;
|
||||
episodeFile.Movie = localMovie.Movie;
|
||||
episodeFile.ReleaseGroup = localMovie.ParsedEpisodeInfo.ReleaseGroup;
|
||||
episodeFile.ReleaseGroup = localMovie.ParsedMovieInfo.ReleaseGroup;
|
||||
|
||||
bool copyOnly;
|
||||
switch (importMode)
|
||||
|
@ -24,15 +24,15 @@ public ImportDecision(LocalMovie localMovie, params Rejection[] rejections)
|
||||
{
|
||||
LocalMovie = localMovie;
|
||||
Rejections = rejections.ToList();
|
||||
LocalEpisode = new LocalEpisode
|
||||
{
|
||||
Quality = localMovie.Quality,
|
||||
ExistingFile = localMovie.ExistingFile,
|
||||
MediaInfo = localMovie.MediaInfo,
|
||||
ParsedEpisodeInfo = localMovie.ParsedEpisodeInfo,
|
||||
Path = localMovie.Path,
|
||||
Size = localMovie.Size
|
||||
};
|
||||
//LocalMovie = new LocalMovie
|
||||
//{
|
||||
// Quality = localMovie.Quality,
|
||||
// ExistingFile = localMovie.ExistingFile,
|
||||
// MediaInfo = localMovie.MediaInfo,
|
||||
// ParsedMovieInfo = localMovie.ParsedMovieInfo,
|
||||
// Path = localMovie.Path,
|
||||
// Size = localMovie.Size
|
||||
//};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ public interface IMakeImportDecision
|
||||
{
|
||||
List<ImportDecision> GetImportDecisions(List<string> videoFiles, Series series);
|
||||
List<ImportDecision> GetImportDecisions(List<string> videoFiles, Movie movie);
|
||||
List<ImportDecision> GetImportDecisions(List<string> videoFiles, Movie movie, ParsedEpisodeInfo folderInfo, bool sceneSource); //TODO: Needs changing to ParsedMovieInfo!!
|
||||
List<ImportDecision> GetImportDecisions(List<string> videoFiles, Movie movie, ParsedMovieInfo folderInfo, bool sceneSource); //TODO: Needs changing to ParsedMovieInfo!!
|
||||
List<ImportDecision> GetImportDecisions(List<string> videoFiles, Series series, ParsedEpisodeInfo folderInfo, bool sceneSource);
|
||||
}
|
||||
|
||||
@ -77,7 +77,7 @@ public List<ImportDecision> GetImportDecisions(List<string> videoFiles, Series s
|
||||
return decisions;
|
||||
}
|
||||
|
||||
public List<ImportDecision> GetImportDecisions(List<string> videoFiles, Movie movie, ParsedEpisodeInfo folderInfo, bool sceneSource)
|
||||
public List<ImportDecision> GetImportDecisions(List<string> videoFiles, Movie movie, ParsedMovieInfo folderInfo, bool sceneSource)
|
||||
{
|
||||
var newFiles = _mediaFileService.FilterExistingFiles(videoFiles.ToList(), movie);
|
||||
|
||||
@ -94,7 +94,7 @@ public List<ImportDecision> GetImportDecisions(List<string> videoFiles, Movie mo
|
||||
return decisions;
|
||||
}
|
||||
|
||||
private ImportDecision GetDecision(string file, Movie movie, ParsedEpisodeInfo folderInfo, bool sceneSource, bool shouldUseFolderName)
|
||||
private ImportDecision GetDecision(string file, Movie movie, ParsedMovieInfo folderInfo, bool sceneSource, bool shouldUseFolderName)
|
||||
{
|
||||
ImportDecision decision = null;
|
||||
|
||||
@ -123,18 +123,18 @@ private ImportDecision GetDecision(string file, Movie movie, ParsedEpisodeInfo f
|
||||
|
||||
else
|
||||
{
|
||||
var localEpisode = new LocalEpisode();
|
||||
localEpisode.Path = file;
|
||||
localMovie = new LocalMovie();
|
||||
localMovie.Path = file;
|
||||
|
||||
decision = new ImportDecision(localEpisode, new Rejection("Unable to parse file"));
|
||||
decision = new ImportDecision(localMovie, new Rejection("Unable to parse file"));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error(e, "Couldn't import file. " + file);
|
||||
|
||||
var localEpisode = new LocalEpisode { Path = file };
|
||||
decision = new ImportDecision(localEpisode, new Rejection("Unexpected error processing file"));
|
||||
var localMovie = new LocalMovie { Path = file };
|
||||
decision = new ImportDecision(localMovie, new Rejection("Unexpected error processing file"));
|
||||
}
|
||||
|
||||
//LocalMovie nullMovie = null;
|
||||
@ -291,17 +291,17 @@ private bool ShouldUseFolderName(List<string> videoFiles, Series series, ParsedE
|
||||
}) == 1;
|
||||
}
|
||||
|
||||
private bool ShouldUseFolderName(List<string> videoFiles, Movie movie, ParsedEpisodeInfo folderInfo)
|
||||
private bool ShouldUseFolderName(List<string> videoFiles, Movie movie, ParsedMovieInfo folderInfo)
|
||||
{
|
||||
if (folderInfo == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (folderInfo.FullSeason)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//if (folderInfo.FullSeason)
|
||||
//{
|
||||
// return false;
|
||||
//}
|
||||
|
||||
return videoFiles.Count(file =>
|
||||
{
|
||||
@ -325,7 +325,7 @@ private bool ShouldUseFolderName(List<string> videoFiles, Movie movie, ParsedEpi
|
||||
}) == 1;
|
||||
}
|
||||
|
||||
private QualityModel GetQuality(ParsedEpisodeInfo folderInfo, QualityModel fileQuality, Movie movie)
|
||||
private QualityModel GetQuality(ParsedMovieInfo folderInfo, QualityModel fileQuality, Movie movie)
|
||||
{
|
||||
if (UseFolderQuality(folderInfo, fileQuality, movie))
|
||||
{
|
||||
@ -347,7 +347,7 @@ private QualityModel GetQuality(ParsedEpisodeInfo folderInfo, QualityModel fileQ
|
||||
return fileQuality;
|
||||
}
|
||||
|
||||
private bool UseFolderQuality(ParsedEpisodeInfo folderInfo, QualityModel fileQuality, Movie movie)
|
||||
private bool UseFolderQuality(ParsedMovieInfo folderInfo, QualityModel fileQuality, Movie movie)
|
||||
{
|
||||
if (folderInfo == null)
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
@ -13,9 +13,9 @@ namespace NzbDrone.Core.MediaFiles
|
||||
{
|
||||
public interface IMediaFileService
|
||||
{
|
||||
MovieFile Add(MovieFile episodeFile);
|
||||
void Update(MovieFile episodeFile);
|
||||
void Delete(MovieFile episodeFile, DeleteMediaFileReason reason);
|
||||
MovieFile Add(MovieFile movieFile);
|
||||
void Update(MovieFile movieFile);
|
||||
void Delete(MovieFile movieFile, DeleteMediaFileReason reason);
|
||||
EpisodeFile Add(EpisodeFile episodeFile);
|
||||
void Update(EpisodeFile episodeFile);
|
||||
void Delete(EpisodeFile episodeFile, DeleteMediaFileReason reason);
|
||||
@ -27,7 +27,9 @@ public interface IMediaFileService
|
||||
List<string> FilterExistingFiles(List<string> files, Movie movie);
|
||||
EpisodeFile Get(int id);
|
||||
List<EpisodeFile> Get(IEnumerable<int> ids);
|
||||
List<MovieFile> GetMovies(IEnumerable<int> ids);
|
||||
|
||||
//List<MovieFile> Get(IEnumerable<int> ids);
|
||||
}
|
||||
|
||||
public class MediaFileService : IMediaFileService, IHandleAsync<SeriesDeletedEvent>
|
||||
@ -125,6 +127,11 @@ public List<EpisodeFile> Get(IEnumerable<int> ids)
|
||||
return _mediaFileRepository.Get(ids).ToList();
|
||||
}
|
||||
|
||||
public List<MovieFile> GetMovies(IEnumerable<int> ids)
|
||||
{
|
||||
return _movieFileRepository.Get(ids).ToList();
|
||||
}
|
||||
|
||||
public void HandleAsync(SeriesDeletedEvent message)
|
||||
{
|
||||
var files = GetFilesBySeries(message.Series.Id);
|
||||
|
15
src/NzbDrone.Core/MediaFiles/RenameMovieFilePreview.cs
Normal file
15
src/NzbDrone.Core/MediaFiles/RenameMovieFilePreview.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles
|
||||
{
|
||||
public class RenameMovieFilePreview
|
||||
{
|
||||
public int MovieId { get; set; }
|
||||
public int MovieFileId { get; set; }
|
||||
public string ExistingPath { get; set; }
|
||||
public string NewPath { get; set; }
|
||||
}
|
||||
}
|
138
src/NzbDrone.Core/MediaFiles/RenameMovieFileService.cs
Normal file
138
src/NzbDrone.Core/MediaFiles/RenameMovieFileService.cs
Normal file
@ -0,0 +1,138 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.MediaFiles.Commands;
|
||||
using NzbDrone.Core.MediaFiles.Events;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Instrumentation.Extensions;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using NzbDrone.Core.Tv;
|
||||
|
||||
namespace NzbDrone.Core.MediaFiles
|
||||
{
|
||||
public interface IRenameMovieFileService
|
||||
{
|
||||
List<RenameMovieFilePreview> GetRenamePreviews(int movieId);
|
||||
}
|
||||
|
||||
public class RenameMovieFileService : IRenameMovieFileService,
|
||||
IExecute<RenameMovieFilesCommand>,
|
||||
IExecute<RenameMovieCommand>
|
||||
{
|
||||
private readonly IMovieService _movieService;
|
||||
private readonly IMediaFileService _mediaFileService;
|
||||
private readonly IMoveMovieFiles _movieFileMover;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly IBuildFileNames _filenameBuilder;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public RenameMovieFileService(IMovieService movieService,
|
||||
IMediaFileService mediaFileService,
|
||||
IMoveMovieFiles movieFileMover,
|
||||
IEventAggregator eventAggregator,
|
||||
IBuildFileNames filenameBuilder,
|
||||
Logger logger)
|
||||
{
|
||||
_movieService = movieService;
|
||||
_mediaFileService = mediaFileService;
|
||||
_movieFileMover = movieFileMover;
|
||||
_eventAggregator = eventAggregator;
|
||||
_filenameBuilder = filenameBuilder;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public List<RenameMovieFilePreview> GetRenamePreviews(int movieId)
|
||||
{
|
||||
var movie = _movieService.GetMovie(movieId);
|
||||
var file = _mediaFileService.GetFilesByMovie(movieId);
|
||||
|
||||
return GetPreviews(movie, file).OrderByDescending(m => m.MovieId).ToList(); //TODO: Would really like to not have these be lists
|
||||
|
||||
}
|
||||
|
||||
private IEnumerable<RenameMovieFilePreview> GetPreviews(Movie movie, List<MovieFile> files)
|
||||
{
|
||||
foreach(var file in files)
|
||||
{
|
||||
var movieFilePath = Path.Combine(movie.Path, file.RelativePath);
|
||||
|
||||
var newName = _filenameBuilder.BuildFileName(movie, file);
|
||||
var newPath = _filenameBuilder.BuildFilePath(movie, newName, Path.GetExtension(movieFilePath));
|
||||
|
||||
if(!movieFilePath.PathEquals(newPath, StringComparison.Ordinal))
|
||||
{
|
||||
yield return new RenameMovieFilePreview
|
||||
{
|
||||
MovieId = movie.Id,
|
||||
MovieFileId = file.Id,
|
||||
ExistingPath = file.RelativePath,
|
||||
NewPath = movie.Path.GetRelativePath(newPath)
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void RenameFiles(List<MovieFile> movieFiles, Movie movie)
|
||||
{
|
||||
var renamed = new List<MovieFile>();
|
||||
|
||||
foreach(var movieFile in movieFiles)
|
||||
{
|
||||
var movieFilePath = Path.Combine(movie.Path, movieFile.RelativePath);
|
||||
|
||||
try
|
||||
{
|
||||
_logger.Debug("Renaming movie file: {0}", movieFile);
|
||||
_movieFileMover.MoveMovieFile(movieFile, movie);
|
||||
|
||||
_mediaFileService.Update(movieFile);
|
||||
renamed.Add(movieFile);
|
||||
|
||||
_logger.Debug("Renamed movie file: {0}", movieFile);
|
||||
|
||||
}
|
||||
catch(SameFilenameException ex)
|
||||
{
|
||||
_logger.Debug("File not renamed, source and destination are the same: {0}", ex.Filename);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
_logger.Error(ex, "Failed to rename file: " + movieFilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Execute(RenameMovieFilesCommand message)
|
||||
{
|
||||
var movie = _movieService.GetMovie(message.MovieId);
|
||||
var movieFiles = _mediaFileService.GetMovies(message.Files);
|
||||
|
||||
_logger.ProgressInfo("Renaming {0} files for {1}", movieFiles.Count, movie.Title);
|
||||
RenameFiles(movieFiles, movie);
|
||||
_logger.ProgressInfo("Selected movie files renamed for {0}", movie.Title);
|
||||
}
|
||||
|
||||
public void Execute(RenameMovieCommand message)
|
||||
{
|
||||
_logger.Debug("Renaming all files for selected movie");
|
||||
var moviesToRename = _movieService.GetMovies(message.MovieIds);
|
||||
|
||||
foreach(var movie in moviesToRename)
|
||||
{
|
||||
var movieFiles = _mediaFileService.GetFilesByMovie(movie.Id);
|
||||
_logger.ProgressInfo("Renaming all files in movie: {0}", movie.Title);
|
||||
RenameFiles(movieFiles, movie);
|
||||
_logger.ProgressInfo("All movie files renamed for {0}", movie.Title);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -707,6 +707,8 @@
|
||||
<Compile Include="MediaFiles\Commands\BackendCommandAttribute.cs" />
|
||||
<Compile Include="MediaFiles\Commands\CleanUpRecycleBinCommand.cs" />
|
||||
<Compile Include="MediaFiles\Commands\DownloadedEpisodesScanCommand.cs" />
|
||||
<Compile Include="MediaFiles\Commands\RenameMovieCommand.cs" />
|
||||
<Compile Include="MediaFiles\Commands\RenameMovieFilesCommand.cs" />
|
||||
<Compile Include="MediaFiles\Commands\RescanMovieCommand.cs" />
|
||||
<Compile Include="MediaFiles\DownloadedMovieCommandService.cs" />
|
||||
<Compile Include="MediaFiles\MovieFileMovingService.cs" />
|
||||
@ -780,6 +782,8 @@
|
||||
<Compile Include="MediaFiles\RecycleBinProvider.cs" />
|
||||
<Compile Include="MediaFiles\RenameEpisodeFilePreview.cs" />
|
||||
<Compile Include="MediaFiles\RenameEpisodeFileService.cs" />
|
||||
<Compile Include="MediaFiles\RenameMovieFilePreview.cs" />
|
||||
<Compile Include="MediaFiles\RenameMovieFileService.cs" />
|
||||
<Compile Include="MediaFiles\SameFilenameException.cs" />
|
||||
<Compile Include="MediaFiles\UpdateMovieFileService.cs" />
|
||||
<Compile Include="MediaFiles\UpdateEpisodeFileService.cs" />
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
@ -14,7 +14,7 @@ public LocalMovie()
|
||||
|
||||
public string Path { get; set; }
|
||||
public long Size { get; set; }
|
||||
public ParsedEpisodeInfo ParsedEpisodeInfo { get; set; }
|
||||
public ParsedMovieInfo ParsedMovieInfo { get; set; }
|
||||
public Movie Movie { get; set; }
|
||||
public QualityModel Quality { get; set; }
|
||||
public MediaInfoModel MediaInfo { get; set; }
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Qualities;
|
||||
|
||||
@ -9,10 +9,10 @@ public class ParsedMovieInfo
|
||||
public string MovieTitle { get; set; }
|
||||
public SeriesTitleInfo MovieTitleInfo { get; set; }
|
||||
public QualityModel Quality { get; set; }
|
||||
public int SeasonNumber { get; set; }
|
||||
//public int SeasonNumber { get; set; }
|
||||
public Language Language { get; set; }
|
||||
public bool FullSeason { get; set; }
|
||||
public bool Special { get; set; }
|
||||
//public bool FullSeason { get; set; }
|
||||
//public bool Special { get; set; }
|
||||
public string ReleaseGroup { get; set; }
|
||||
public string ReleaseHash { get; set; }
|
||||
public string Edition { get; set;}
|
||||
|
@ -323,6 +323,28 @@ public static ParsedEpisodeInfo ParsePath(string path)
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ParsedMovieInfo ParseMoviePath(string path)
|
||||
{
|
||||
var fileInfo = new FileInfo(path);
|
||||
|
||||
var result = ParseMovieTitle(fileInfo.Name);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
Logger.Debug("Attempting to parse episode info using directory and file names. {0}", fileInfo.Directory.Name);
|
||||
result = ParseMovieTitle(fileInfo.Directory.Name + " " + fileInfo.Name);
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
Logger.Debug("Attempting to parse episode info using directory name. {0}", fileInfo.Directory.Name);
|
||||
result = ParseMovieTitle(fileInfo.Directory.Name + fileInfo.Extension);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public static ParsedMovieInfo ParseMovieTitle(string title)
|
||||
{
|
||||
|
||||
|
@ -16,7 +16,7 @@ public interface IParsingService
|
||||
LocalEpisode GetLocalEpisode(string filename, Series series);
|
||||
LocalEpisode GetLocalEpisode(string filename, Series series, ParsedEpisodeInfo folderInfo, bool sceneSource);
|
||||
LocalMovie GetLocalMovie(string filename, Movie movie);
|
||||
LocalMovie GetLocalMovie(string filename, Movie movie, ParsedEpisodeInfo folderInfo, bool sceneSource);
|
||||
LocalMovie GetLocalMovie(string filename, Movie movie, ParsedMovieInfo folderInfo, bool sceneSource);
|
||||
Series GetSeries(string title);
|
||||
Movie GetMovie(string title);
|
||||
RemoteEpisode Map(ParsedEpisodeInfo parsedEpisodeInfo, int tvdbId, int tvRageId, SearchCriteriaBase searchCriteria = null);
|
||||
@ -120,26 +120,26 @@ public LocalMovie GetLocalMovie(string filename, Movie movie)
|
||||
return GetLocalMovie(filename, movie, null, false);
|
||||
}
|
||||
|
||||
public LocalMovie GetLocalMovie(string filename, Movie movie, ParsedEpisodeInfo folderInfo, bool sceneSource)
|
||||
public LocalMovie GetLocalMovie(string filename, Movie movie, ParsedMovieInfo folderInfo, bool sceneSource)
|
||||
{
|
||||
ParsedEpisodeInfo parsedEpisodeInfo;
|
||||
ParsedMovieInfo parsedMovieInfo;
|
||||
|
||||
if (folderInfo != null)
|
||||
{
|
||||
parsedEpisodeInfo = folderInfo.JsonClone();
|
||||
parsedEpisodeInfo.Quality = QualityParser.ParseQuality(Path.GetFileName(filename));
|
||||
parsedMovieInfo = folderInfo.JsonClone();
|
||||
parsedMovieInfo.Quality = QualityParser.ParseQuality(Path.GetFileName(filename));
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
parsedEpisodeInfo = Parser.ParsePath(filename);
|
||||
parsedMovieInfo = Parser.ParseMoviePath(filename);
|
||||
}
|
||||
|
||||
if (parsedEpisodeInfo == null)
|
||||
if (parsedMovieInfo == null)
|
||||
{
|
||||
if (MediaFileExtensions.Extensions.Contains(Path.GetExtension(filename)))
|
||||
{
|
||||
_logger.Warn("Unable to parse episode info from path {0}", filename);
|
||||
_logger.Warn("Unable to parse movie info from path {0}", filename);
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -148,9 +148,9 @@ public LocalMovie GetLocalMovie(string filename, Movie movie, ParsedEpisodeInfo
|
||||
return new LocalMovie
|
||||
{
|
||||
Movie = movie,
|
||||
Quality = parsedEpisodeInfo.Quality,
|
||||
Quality = parsedMovieInfo.Quality,
|
||||
Path = filename,
|
||||
ParsedEpisodeInfo = parsedEpisodeInfo,
|
||||
ParsedMovieInfo = parsedMovieInfo,
|
||||
ExistingFile = movie.Path.IsParentPath(filename)
|
||||
};
|
||||
}
|
||||
|
@ -48,6 +48,9 @@ public Movie()
|
||||
public LazyLoaded<MovieFile> MovieFile { get; set; }
|
||||
public int MovieFileId { get; set; }
|
||||
public List<string> AlternativeTitles { get; set; }
|
||||
|
||||
public bool HasFile => MovieFileId > 0;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("[{0}][{1}]", ImdbId, Title.NullSafe());
|
||||
|
@ -52,7 +52,7 @@
|
||||
{{> ProfileSelectionPartial profiles}}
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-2">
|
||||
{{!--<div class="form-group col-md-2">
|
||||
<label>Season Folders</label>
|
||||
|
||||
<div class="input-group">
|
||||
@ -65,7 +65,7 @@
|
||||
<div class="btn btn-primary slide-button"/>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>--}}
|
||||
{{/unless}}
|
||||
|
||||
{{#unless existing}}
|
||||
|
@ -4,8 +4,8 @@ module.exports = TemplatedCell.extend({
|
||||
className : 'series-title-cell',
|
||||
template : 'Cells/SeriesTitleTemplate',
|
||||
|
||||
render : function() {
|
||||
this.$el.html(this.model.get("movie").get("title")); //Hack, but somehow handlebar helper does not work.
|
||||
return this;
|
||||
}
|
||||
// render : function() {
|
||||
// this.$el.html(this.model.get("movie").get("title")); //Hack, but somehow handlebar helper does not work.
|
||||
// return this;
|
||||
// }
|
||||
});
|
||||
|
@ -11,6 +11,7 @@ var ReleaseLayout = require('./Release/ReleaseLayout');
|
||||
var SystemLayout = require('./System/SystemLayout');
|
||||
var SeasonPassLayout = require('./SeasonPass/SeasonPassLayout');
|
||||
var SeriesEditorLayout = require('./Series/Editor/SeriesEditorLayout');
|
||||
var MovieEditorLayout = require('./Movies/Editor/MovieEditorLayout');
|
||||
|
||||
module.exports = NzbDroneController.extend({
|
||||
addSeries : function(action) {
|
||||
@ -61,5 +62,10 @@ module.exports = NzbDroneController.extend({
|
||||
seriesEditor : function() {
|
||||
this.setTitle('Series Editor');
|
||||
this.showMainRegion(new SeriesEditorLayout());
|
||||
},
|
||||
|
||||
movieEditor : function() {
|
||||
this.setTitle('Movie Editor');
|
||||
this.showMainRegion(new MovieEditorLayout());
|
||||
}
|
||||
});
|
||||
|
@ -97,7 +97,7 @@ module.exports = Marionette.Layout.extend({
|
||||
CommandController.bindToCommand({
|
||||
element : this.ui.rename,
|
||||
command : {
|
||||
name : 'renameFiles',
|
||||
name : 'renameMovieFiles',
|
||||
movieId : this.model.id,
|
||||
seasonNumber : -1
|
||||
}
|
||||
@ -237,7 +237,7 @@ module.exports = Marionette.Layout.extend({
|
||||
},
|
||||
|
||||
_commandComplete : function(options) {
|
||||
if (options.command.get('name') === 'renamefiles') {
|
||||
if (options.command.get('name') === 'renameMoviefiles') {
|
||||
if (options.command.get('moviesId') === this.model.get('id')) {
|
||||
this._refresh();
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
<i class="icon-sonarr-refresh icon-can-spin" title="Update movie info and scan disk"/>
|
||||
</div>
|
||||
<div class="x-rename">
|
||||
<i class="icon-sonarr-rename" title="Preview rename for all episodes"/>
|
||||
<i class="icon-sonarr-rename" title="Preview rename for movie"/>
|
||||
</div>
|
||||
<div class="x-search">
|
||||
<i class="icon-sonarr-search" title="Search for movie"/>
|
||||
|
126
src/UI/Movies/Editor/MovieEditorFooterView.js
Normal file
126
src/UI/Movies/Editor/MovieEditorFooterView.js
Normal file
@ -0,0 +1,126 @@
|
||||
var _ = require('underscore');
|
||||
var Marionette = require('marionette');
|
||||
var vent = require('vent');
|
||||
var Profiles = require('../../Profile/ProfileCollection');
|
||||
var RootFolders = require('../../AddMovies/RootFolders/RootFolderCollection');
|
||||
var RootFolderLayout = require('../../AddMovies/RootFolders/RootFolderLayout');
|
||||
var UpdateFilesMoviesView = require('./Organize/OrganizeFilesView');
|
||||
var Config = require('../../Config');
|
||||
|
||||
module.exports = Marionette.ItemView.extend({
|
||||
template : 'Movies/Editor/MovieEditorFooterViewTemplate',
|
||||
|
||||
ui : {
|
||||
monitored : '.x-monitored',
|
||||
profile : '.x-profiles',
|
||||
seasonFolder : '.x-season-folder',
|
||||
rootFolder : '.x-root-folder',
|
||||
selectedCount : '.x-selected-count',
|
||||
container : '.series-editor-footer',
|
||||
actions : '.x-action'
|
||||
},
|
||||
|
||||
events : {
|
||||
'click .x-save' : '_updateAndSave',
|
||||
'change .x-root-folder' : '_rootFolderChanged',
|
||||
'click .x-organize-files' : '_organizeFiles'
|
||||
},
|
||||
|
||||
templateHelpers : function() {
|
||||
return {
|
||||
profiles : Profiles,
|
||||
rootFolders : RootFolders.toJSON()
|
||||
};
|
||||
},
|
||||
|
||||
initialize : function(options) {
|
||||
this.moviesCollection = options.collection;
|
||||
|
||||
RootFolders.fetch().done(function() {
|
||||
RootFolders.synced = true;
|
||||
});
|
||||
|
||||
this.editorGrid = options.editorGrid;
|
||||
this.listenTo(this.moviesCollection, 'backgrid:selected', this._updateInfo);
|
||||
this.listenTo(RootFolders, 'all', this.render);
|
||||
},
|
||||
|
||||
onRender : function() {
|
||||
this._updateInfo();
|
||||
},
|
||||
|
||||
_updateAndSave : function() {
|
||||
var selected = this.editorGrid.getSelectedModels();
|
||||
|
||||
var monitored = this.ui.monitored.val();
|
||||
var profile = this.ui.profile.val();
|
||||
var seasonFolder = this.ui.seasonFolder.val();
|
||||
var rootFolder = this.ui.rootFolder.val();
|
||||
|
||||
_.each(selected, function(model) {
|
||||
if (monitored === 'true') {
|
||||
model.set('monitored', true);
|
||||
} else if (monitored === 'false') {
|
||||
model.set('monitored', false);
|
||||
}
|
||||
|
||||
if (profile !== 'noChange') {
|
||||
model.set('profileId', parseInt(profile, 10));
|
||||
}
|
||||
|
||||
if (seasonFolder === 'true') {
|
||||
model.set('seasonFolder', true);
|
||||
} else if (seasonFolder === 'false') {
|
||||
model.set('seasonFolder', false);
|
||||
}
|
||||
|
||||
if (rootFolder !== 'noChange') {
|
||||
var rootFolderPath = RootFolders.get(parseInt(rootFolder, 10));
|
||||
|
||||
model.set('rootFolderPath', rootFolderPath.get('path'));
|
||||
}
|
||||
|
||||
model.edited = true;
|
||||
});
|
||||
|
||||
this.moviesCollection.save();
|
||||
},
|
||||
|
||||
_updateInfo : function() {
|
||||
var selected = this.editorGrid.getSelectedModels();
|
||||
var selectedCount = selected.length;
|
||||
|
||||
this.ui.selectedCount.html('{0} movies selected'.format(selectedCount));
|
||||
|
||||
if (selectedCount === 0) {
|
||||
this.ui.actions.attr('disabled', 'disabled');
|
||||
} else {
|
||||
this.ui.actions.removeAttr('disabled');
|
||||
}
|
||||
},
|
||||
|
||||
_rootFolderChanged : function() {
|
||||
var rootFolderValue = this.ui.rootFolder.val();
|
||||
if (rootFolderValue === 'addNew') {
|
||||
var rootFolderLayout = new RootFolderLayout();
|
||||
this.listenToOnce(rootFolderLayout, 'folderSelected', this._setRootFolder);
|
||||
vent.trigger(vent.Commands.OpenModalCommand, rootFolderLayout);
|
||||
} else {
|
||||
Config.setValue(Config.Keys.DefaultRootFolderId, rootFolderValue);
|
||||
}
|
||||
},
|
||||
|
||||
_setRootFolder : function(options) {
|
||||
vent.trigger(vent.Commands.CloseModalCommand);
|
||||
this.ui.rootFolder.val(options.model.id);
|
||||
this._rootFolderChanged();
|
||||
},
|
||||
|
||||
_organizeFiles : function() {
|
||||
var selected = this.editorGrid.getSelectedModels();
|
||||
var updateFilesMoviesView = new UpdateFilesMoviesView({ movies : selected });
|
||||
this.listenToOnce(updateFilesMoviesView, 'updatingFiles', this._afterSave);
|
||||
|
||||
vent.trigger(vent.Commands.OpenModalCommand, updateFilesMoviesView);
|
||||
}
|
||||
});
|
54
src/UI/Movies/Editor/MovieEditorFooterViewTemplate.hbs
Normal file
54
src/UI/Movies/Editor/MovieEditorFooterViewTemplate.hbs
Normal file
@ -0,0 +1,54 @@
|
||||
<div class="series-editor-footer">
|
||||
<div class="row">
|
||||
<div class="form-group col-md-2">
|
||||
<label>Monitored</label>
|
||||
|
||||
<select class="form-control x-action x-monitored">
|
||||
<option value="noChange">No change</option>
|
||||
<option value="true">Monitored</option>
|
||||
<option value="false">Unmonitored</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-2">
|
||||
<label>Profile</label>
|
||||
|
||||
<select class="form-control x-action x-profiles">
|
||||
<option value="noChange">No change</option>
|
||||
{{#each profiles.models}}
|
||||
<option value="{{id}}">{{attributes.name}}</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{{!--<div class="form-group col-md-2">
|
||||
<label>Season Folder</label>
|
||||
|
||||
<select class="form-control x-action x-season-folder">
|
||||
<option value="noChange">No change</option>
|
||||
<option value="true">Yes</option>
|
||||
<option value="false">No</option>
|
||||
</select>
|
||||
</div>--}}
|
||||
|
||||
<div class="form-group col-md-3">
|
||||
<label>Root Folder</label>
|
||||
|
||||
<select class="form-control x-action x-root-folder" validation-name="RootFolderPath">
|
||||
<option value="noChange">No change</option>
|
||||
{{#each rootFolders}}
|
||||
<option value="{{id}}">{{path}}</option>
|
||||
{{/each}}
|
||||
<option value="addNew">Add a different path</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-3 actions">
|
||||
<label class="x-selected-count">0 movies selected</label>
|
||||
<div>
|
||||
<button class="btn btn-primary x-action x-save">Save</button>
|
||||
<button class="btn btn-danger x-action x-organize-files" title="Organize and rename movie files">Organize</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
153
src/UI/Movies/Editor/MovieEditorLayout.js
Normal file
153
src/UI/Movies/Editor/MovieEditorLayout.js
Normal file
@ -0,0 +1,153 @@
|
||||
var vent = require('vent');
|
||||
var Marionette = require('marionette');
|
||||
var Backgrid = require('backgrid');
|
||||
var EmptyView = require('../Index/EmptyView');
|
||||
var MoviesCollection = require('../MoviesCollection');
|
||||
var MovieTitleCell = require('../../Cells/MovieTitleCell');
|
||||
var ProfileCell = require('../../Cells/ProfileCell');
|
||||
var SelectAllCell = require('../../Cells/SelectAllCell');
|
||||
var ToolbarLayout = require('../../Shared/Toolbar/ToolbarLayout');
|
||||
var FooterView = require('./MovieEditorFooterView');
|
||||
require('../../Mixins/backbone.signalr.mixin');
|
||||
|
||||
module.exports = Marionette.Layout.extend({
|
||||
template : 'Movies/Editor/MovieEditorLayoutTemplate',
|
||||
|
||||
regions : {
|
||||
seriesRegion : '#x-series-editor',
|
||||
toolbar : '#x-toolbar'
|
||||
},
|
||||
|
||||
ui : {
|
||||
monitored : '.x-monitored',
|
||||
profiles : '.x-profiles',
|
||||
rootFolder : '.x-root-folder',
|
||||
selectedCount : '.x-selected-count'
|
||||
},
|
||||
|
||||
events : {
|
||||
'click .x-save' : '_updateAndSave',
|
||||
'change .x-root-folder' : '_rootFolderChanged'
|
||||
},
|
||||
|
||||
columns : [
|
||||
{
|
||||
name : '',
|
||||
cell : SelectAllCell,
|
||||
headerCell : 'select-all',
|
||||
sortable : false
|
||||
},
|
||||
{
|
||||
name : 'title',
|
||||
label : 'Title',
|
||||
cell : MovieTitleCell,
|
||||
cellValue : 'this'
|
||||
},
|
||||
{
|
||||
name : 'profileId',
|
||||
label : 'Profile',
|
||||
cell : ProfileCell
|
||||
},
|
||||
{
|
||||
name : 'path',
|
||||
label : 'Path',
|
||||
cell : 'string'
|
||||
}
|
||||
],
|
||||
|
||||
leftSideButtons : {
|
||||
type : 'default',
|
||||
storeState : false,
|
||||
items : [
|
||||
{
|
||||
title : 'Update Library',
|
||||
icon : 'icon-sonarr-refresh',
|
||||
command : 'refreshseries',
|
||||
successMessage : 'Library was updated!',
|
||||
errorMessage : 'Library update failed!'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
initialize : function() {
|
||||
this.movieCollection = MoviesCollection.clone();
|
||||
this.movieCollection.shadowCollection.bindSignalR();
|
||||
this.listenTo(this.movieCollection, 'save', this.render);
|
||||
|
||||
this.filteringOptions = {
|
||||
type : 'radio',
|
||||
storeState : true,
|
||||
menuKey : 'serieseditor.filterMode',
|
||||
defaultAction : 'all',
|
||||
items : [
|
||||
{
|
||||
key : 'all',
|
||||
title : '',
|
||||
tooltip : 'All',
|
||||
icon : 'icon-sonarr-all',
|
||||
callback : this._setFilter
|
||||
},
|
||||
{
|
||||
key : 'monitored',
|
||||
title : '',
|
||||
tooltip : 'Monitored Only',
|
||||
icon : 'icon-sonarr-monitored',
|
||||
callback : this._setFilter
|
||||
}
|
||||
]
|
||||
};
|
||||
},
|
||||
|
||||
onRender : function() {
|
||||
this._showToolbar();
|
||||
this._showTable();
|
||||
},
|
||||
|
||||
onClose : function() {
|
||||
vent.trigger(vent.Commands.CloseControlPanelCommand);
|
||||
},
|
||||
|
||||
_showTable : function() {
|
||||
if (this.movieCollection.shadowCollection.length === 0) {
|
||||
this.seriesRegion.show(new EmptyView());
|
||||
this.toolbar.close();
|
||||
return;
|
||||
}
|
||||
|
||||
this.columns[0].sortedCollection = this.movieCollection;
|
||||
|
||||
this.editorGrid = new Backgrid.Grid({
|
||||
collection : this.movieCollection,
|
||||
columns : this.columns,
|
||||
className : 'table table-hover'
|
||||
});
|
||||
|
||||
this.seriesRegion.show(this.editorGrid);
|
||||
this._showFooter();
|
||||
},
|
||||
|
||||
_showToolbar : function() {
|
||||
this.toolbar.show(new ToolbarLayout({
|
||||
left : [
|
||||
this.leftSideButtons
|
||||
],
|
||||
right : [
|
||||
this.filteringOptions
|
||||
],
|
||||
context : this
|
||||
}));
|
||||
},
|
||||
|
||||
_showFooter : function() {
|
||||
vent.trigger(vent.Commands.OpenControlPanelCommand, new FooterView({
|
||||
editorGrid : this.editorGrid,
|
||||
collection : this.movieCollection
|
||||
}));
|
||||
},
|
||||
|
||||
_setFilter : function(buttonContext) {
|
||||
var mode = buttonContext.model.get('key');
|
||||
|
||||
this.movieCollection.setFilterMode(mode);
|
||||
}
|
||||
});
|
7
src/UI/Movies/Editor/MovieEditorLayoutTemplate.hbs
Normal file
7
src/UI/Movies/Editor/MovieEditorLayoutTemplate.hbs
Normal file
@ -0,0 +1,7 @@
|
||||
<div id="x-toolbar"></div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div id="x-series-editor" class="table-responsive"></div>
|
||||
</div>
|
||||
</div>
|
33
src/UI/Movies/Editor/Organize/OrganizeFilesView.js
Normal file
33
src/UI/Movies/Editor/Organize/OrganizeFilesView.js
Normal file
@ -0,0 +1,33 @@
|
||||
var _ = require('underscore');
|
||||
var vent = require('vent');
|
||||
var Backbone = require('backbone');
|
||||
var Marionette = require('marionette');
|
||||
var CommandController = require('../../../Commands/CommandController');
|
||||
|
||||
module.exports = Marionette.ItemView.extend({
|
||||
template : 'Movies/Editor/Organize/OrganizeFilesViewTemplate',
|
||||
|
||||
events : {
|
||||
'click .x-confirm-organize' : '_organize'
|
||||
},
|
||||
|
||||
initialize : function(options) {
|
||||
this.movies = options.movies;
|
||||
this.templateHelpers = {
|
||||
numberOfMovies : this.movies.length,
|
||||
movies : new Backbone.Collection(this.movies).toJSON()
|
||||
};
|
||||
},
|
||||
|
||||
_organize : function() {
|
||||
var movieIds = _.pluck(this.movies, 'id');
|
||||
|
||||
CommandController.Execute('renameMovie', {
|
||||
name : 'renameMovie',
|
||||
movieIds : movieIds
|
||||
});
|
||||
|
||||
this.trigger('organizingFiles');
|
||||
vent.trigger(vent.Commands.CloseModalCommand);
|
||||
}
|
||||
});
|
25
src/UI/Movies/Editor/Organize/OrganizeFilesViewTemplate.hbs
Normal file
25
src/UI/Movies/Editor/Organize/OrganizeFilesViewTemplate.hbs
Normal file
@ -0,0 +1,25 @@
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h3>Organize Selected Movies</h3>
|
||||
</div>
|
||||
<div class="modal-body update-files-series-modal">
|
||||
<div class="alert alert-info">
|
||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||
Tip: To preview a rename... select "Cancel" then any movie title and use the <i data-original-title="" class="icon-sonarr-rename" title=""></i>
|
||||
</div>
|
||||
|
||||
Are you sure you want to update all files in the {{numberOfMovies}} selected movies?
|
||||
|
||||
{{debug}}
|
||||
<ul class="selected-series">
|
||||
{{#each movie}}
|
||||
<li>{{title}}</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn" data-dismiss="modal">Cancel</button>
|
||||
<button class="btn btn-danger x-confirm-organize">Organize</button>
|
||||
</div>
|
||||
</div>
|
@ -80,14 +80,9 @@ module.exports = Marionette.Layout.extend({
|
||||
route : 'addmovies'
|
||||
},
|
||||
{
|
||||
title : 'Season Pass',
|
||||
icon : 'icon-sonarr-monitored',
|
||||
route : 'seasonpass'
|
||||
},
|
||||
{
|
||||
title : 'Series Editor',
|
||||
title : 'Movie Editor',
|
||||
icon : 'icon-sonarr-edit',
|
||||
route : 'serieseditor'
|
||||
route : 'movieeditor'
|
||||
},
|
||||
{
|
||||
title : 'RSS Sync',
|
||||
|
@ -1,3 +1,38 @@
|
||||
// var Backbone = require('backbone');
|
||||
// var RenamePreviewModel = require('./RenamePreviewModel');
|
||||
|
||||
// module.exports = Backbone.Collection.extend({
|
||||
// url : window.NzbDrone.ApiRoot + '/rename',
|
||||
// model : RenamePreviewModel,
|
||||
|
||||
// originalFetch : Backbone.Collection.prototype.fetch,
|
||||
|
||||
// initialize : function(options) {
|
||||
// if (!options.seriesId) {
|
||||
// throw 'seriesId is required';
|
||||
// }
|
||||
|
||||
// this.seriesId = options.seriesId;
|
||||
// this.seasonNumber = options.seasonNumber;
|
||||
// },
|
||||
|
||||
// fetch : function(options) {
|
||||
// if (!this.seriesId) {
|
||||
// throw 'seriesId is required';
|
||||
// }
|
||||
|
||||
// options = options || {};
|
||||
// options.data = {};
|
||||
// options.data.seriesId = this.seriesId;
|
||||
|
||||
// if (this.seasonNumber !== undefined) {
|
||||
// options.data.seasonNumber = this.seasonNumber;
|
||||
// }
|
||||
|
||||
// return this.originalFetch.call(this, options);
|
||||
// }
|
||||
// });
|
||||
|
||||
var Backbone = require('backbone');
|
||||
var RenamePreviewModel = require('./RenamePreviewModel');
|
||||
|
||||
@ -8,26 +43,26 @@ module.exports = Backbone.Collection.extend({
|
||||
originalFetch : Backbone.Collection.prototype.fetch,
|
||||
|
||||
initialize : function(options) {
|
||||
if (!options.seriesId) {
|
||||
throw 'seriesId is required';
|
||||
if (!options.movieId) {
|
||||
throw 'movieId is required';
|
||||
}
|
||||
|
||||
this.seriesId = options.seriesId;
|
||||
this.seasonNumber = options.seasonNumber;
|
||||
this.movieId = options.movieId;
|
||||
//this.seasonNumber = options.seasonNumber;
|
||||
},
|
||||
|
||||
fetch : function(options) {
|
||||
if (!this.seriesId) {
|
||||
throw 'seriesId is required';
|
||||
if (!this.movieId) {
|
||||
throw 'movieId is required';
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
options.data = {};
|
||||
options.data.seriesId = this.seriesId;
|
||||
options.data.movieId = this.movieId;
|
||||
|
||||
if (this.seasonNumber !== undefined) {
|
||||
options.data.seasonNumber = this.seasonNumber;
|
||||
}
|
||||
// if (this.seasonNumber !== undefined) {
|
||||
// options.data.seasonNumber = this.seasonNumber;
|
||||
//}
|
||||
|
||||
return this.originalFetch.call(this, options);
|
||||
}
|
||||
|
@ -29,12 +29,13 @@ module.exports = Marionette.Layout.extend({
|
||||
},
|
||||
|
||||
initialize : function(options) {
|
||||
this.model = options.series;
|
||||
this.model = options.movie;
|
||||
this.seasonNumber = options.seasonNumber;
|
||||
|
||||
var viewOptions = {};
|
||||
viewOptions.seriesId = this.model.id;
|
||||
viewOptions.seasonNumber = this.seasonNumber;
|
||||
//viewOptions.seriesId = this.model.id;
|
||||
//viewOptions.seasonNumber = this.seasonNumber;
|
||||
viewOptions.movieId = this.model.id;
|
||||
|
||||
this.collection = new RenamePreviewCollection(viewOptions);
|
||||
this.listenTo(this.collection, 'sync', this._showPreviews);
|
||||
@ -66,7 +67,8 @@ module.exports = Marionette.Layout.extend({
|
||||
}
|
||||
|
||||
var files = _.map(this.collection.where({ rename : true }), function(model) {
|
||||
return model.get('episodeFileId');
|
||||
//return model.get('episodeFileId');
|
||||
return model.get('movieFileId');
|
||||
});
|
||||
|
||||
if (files.length === 0) {
|
||||
@ -74,21 +76,11 @@ module.exports = Marionette.Layout.extend({
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.seasonNumber) {
|
||||
CommandController.Execute('renameFiles', {
|
||||
name : 'renameFiles',
|
||||
seriesId : this.model.id,
|
||||
seasonNumber : this.seasonNumber,
|
||||
files : files
|
||||
});
|
||||
} else {
|
||||
CommandController.Execute('renameFiles', {
|
||||
name : 'renameFiles',
|
||||
seriesId : this.model.id,
|
||||
seasonNumber : -1,
|
||||
files : files
|
||||
});
|
||||
}
|
||||
CommandController.Execute('renameMovieFiles', {
|
||||
name : 'renameMovieFiles',
|
||||
movieId : this.model.id,
|
||||
files : files
|
||||
});
|
||||
|
||||
vent.trigger(vent.Commands.CloseModalCommand);
|
||||
},
|
||||
|
@ -21,7 +21,7 @@ module.exports = Marionette.AppRouter.extend({
|
||||
'system' : 'system',
|
||||
'system/:action' : 'system',
|
||||
'seasonpass' : 'seasonPass',
|
||||
'serieseditor' : 'seriesEditor',
|
||||
'movieeditor' : 'movieEditor',
|
||||
':whatever' : 'showNotFound'
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user