|
|
@ -7,6 +7,7 @@ using System.Text.RegularExpressions;
|
|
|
|
using NLog;
|
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Common.EnsureThat;
|
|
|
|
using NzbDrone.Common.EnsureThat;
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
|
|
|
|
using NzbDrone.Core.CustomFormats;
|
|
|
|
using NzbDrone.Core.MediaFiles;
|
|
|
|
using NzbDrone.Core.MediaFiles;
|
|
|
|
using NzbDrone.Core.MediaFiles.MediaInfo;
|
|
|
|
using NzbDrone.Core.MediaFiles.MediaInfo;
|
|
|
|
using NzbDrone.Core.Movies;
|
|
|
|
using NzbDrone.Core.Movies;
|
|
|
@ -16,7 +17,7 @@ namespace NzbDrone.Core.Organizer
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public interface IBuildFileNames
|
|
|
|
public interface IBuildFileNames
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string BuildFileName(Movie movie, MovieFile movieFile, NamingConfig namingConfig = null);
|
|
|
|
string BuildFileName(Movie movie, MovieFile movieFile, NamingConfig namingConfig = null, List<CustomFormat> customFormats = null);
|
|
|
|
string BuildFilePath(Movie movie, string fileName, string extension);
|
|
|
|
string BuildFilePath(Movie movie, string fileName, string extension);
|
|
|
|
BasicNamingConfig GetBasicNamingConfig(NamingConfig nameSpec);
|
|
|
|
BasicNamingConfig GetBasicNamingConfig(NamingConfig nameSpec);
|
|
|
|
string GetMovieFolder(Movie movie, NamingConfig namingConfig = null);
|
|
|
|
string GetMovieFolder(Movie movie, NamingConfig namingConfig = null);
|
|
|
@ -29,6 +30,7 @@ namespace NzbDrone.Core.Organizer
|
|
|
|
private readonly INamingConfigService _namingConfigService;
|
|
|
|
private readonly INamingConfigService _namingConfigService;
|
|
|
|
private readonly IQualityDefinitionService _qualityDefinitionService;
|
|
|
|
private readonly IQualityDefinitionService _qualityDefinitionService;
|
|
|
|
private readonly IUpdateMediaInfo _mediaInfoUpdater;
|
|
|
|
private readonly IUpdateMediaInfo _mediaInfoUpdater;
|
|
|
|
|
|
|
|
private readonly ICustomFormatService _formatService;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
|
|
|
private static readonly Regex TitleRegex = new Regex(@"\{(?<prefix>[- ._\[(]*)(?<token>(?:[a-z0-9]+)(?:(?<separator>[- ._]+)(?:[a-z0-9]+))?)(?::(?<customFormat>[a-z0-9]+))?(?<suffix>[- ._)\]]*)\}",
|
|
|
|
private static readonly Regex TitleRegex = new Regex(@"\{(?<prefix>[- ._\[(]*)(?<token>(?:[a-z0-9]+)(?:(?<separator>[- ._]+)(?:[a-z0-9]+))?)(?::(?<customFormat>[a-z0-9]+))?(?<suffix>[- ._)\]]*)\}",
|
|
|
@ -65,15 +67,17 @@ namespace NzbDrone.Core.Organizer
|
|
|
|
public FileNameBuilder(INamingConfigService namingConfigService,
|
|
|
|
public FileNameBuilder(INamingConfigService namingConfigService,
|
|
|
|
IQualityDefinitionService qualityDefinitionService,
|
|
|
|
IQualityDefinitionService qualityDefinitionService,
|
|
|
|
IUpdateMediaInfo mediaInfoUpdater,
|
|
|
|
IUpdateMediaInfo mediaInfoUpdater,
|
|
|
|
|
|
|
|
ICustomFormatService formatService,
|
|
|
|
Logger logger)
|
|
|
|
Logger logger)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_namingConfigService = namingConfigService;
|
|
|
|
_namingConfigService = namingConfigService;
|
|
|
|
_qualityDefinitionService = qualityDefinitionService;
|
|
|
|
_qualityDefinitionService = qualityDefinitionService;
|
|
|
|
_mediaInfoUpdater = mediaInfoUpdater;
|
|
|
|
_mediaInfoUpdater = mediaInfoUpdater;
|
|
|
|
|
|
|
|
_formatService = formatService;
|
|
|
|
_logger = logger;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string BuildFileName(Movie movie, MovieFile movieFile, NamingConfig namingConfig = null)
|
|
|
|
public string BuildFileName(Movie movie, MovieFile movieFile, NamingConfig namingConfig = null, List<CustomFormat> customFormats = null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (namingConfig == null)
|
|
|
|
if (namingConfig == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -97,6 +101,7 @@ namespace NzbDrone.Core.Organizer
|
|
|
|
AddMediaInfoTokens(tokenHandlers, movieFile);
|
|
|
|
AddMediaInfoTokens(tokenHandlers, movieFile);
|
|
|
|
AddMovieFileTokens(tokenHandlers, movieFile);
|
|
|
|
AddMovieFileTokens(tokenHandlers, movieFile);
|
|
|
|
AddTagsTokens(tokenHandlers, movieFile);
|
|
|
|
AddTagsTokens(tokenHandlers, movieFile);
|
|
|
|
|
|
|
|
AddCustomFormats(tokenHandlers, movie, movieFile, customFormats);
|
|
|
|
|
|
|
|
|
|
|
|
var fileName = ReplaceTokens(pattern, tokenHandlers, namingConfig).Trim();
|
|
|
|
var fileName = ReplaceTokens(pattern, tokenHandlers, namingConfig).Trim();
|
|
|
|
fileName = FileNameCleanupRegex.Replace(fileName, match => match.Captures[0].Value[0].ToString());
|
|
|
|
fileName = FileNameCleanupRegex.Replace(fileName, match => match.Captures[0].Value[0].ToString());
|
|
|
@ -332,6 +337,17 @@ namespace NzbDrone.Core.Organizer
|
|
|
|
m => MediaInfoFormatter.FormatVideoDynamicRange(movieFile.MediaInfo);
|
|
|
|
m => MediaInfoFormatter.FormatVideoDynamicRange(movieFile.MediaInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void AddCustomFormats(Dictionary<string, Func<TokenMatch, string>> tokenHandlers, Movie movie, MovieFile movieFile, List<CustomFormat> customFormats = null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (customFormats == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
movieFile.Movie = movie;
|
|
|
|
|
|
|
|
customFormats = CustomFormatCalculationService.ParseCustomFormat(movieFile, _formatService.All());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tokenHandlers["{Custom Formats}"] = m => string.Join(" ", customFormats.Where(x => x.IncludeCustomFormatWhenRenaming));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string GetLanguagesToken(string mediaInfoLanguages)
|
|
|
|
private string GetLanguagesToken(string mediaInfoLanguages)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
List<string> tokens = new List<string>();
|
|
|
|
List<string> tokens = new List<string>();
|
|
|
|