From a9daef1e18b93f793479155210110322234bb655 Mon Sep 17 00:00:00 2001 From: Matthew Lazarow <2117435+MatthewLazarow@users.noreply.github.com> Date: Mon, 13 Aug 2018 15:56:01 -0400 Subject: Autoname creation date Adds {creation-date} and {creation-time} templates to autoname preference option. --- win/CS/HandBrakeWPF/Constants.cs | 14 ++++++-- win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs | 38 ++++++++++++++++++++-- .../HandBrakeWPF/Properties/Resources.Designer.cs | 2 +- win/CS/HandBrakeWPF/Properties/Resources.resx | 2 +- 4 files changed, 49 insertions(+), 7 deletions(-) (limited to 'win') diff --git a/win/CS/HandBrakeWPF/Constants.cs b/win/CS/HandBrakeWPF/Constants.cs index cf322e85c..f13d8cb0f 100644 --- a/win/CS/HandBrakeWPF/Constants.cs +++ b/win/CS/HandBrakeWPF/Constants.cs @@ -50,15 +50,25 @@ namespace HandBrakeWPF public const string Quality = "{quality}"; /// - /// The quality. + /// The creation date of the new output file. /// public const string Date = "{date}"; /// - /// The quality. + /// The creation time of the new output file. /// public const string Time = "{time}"; + /// + /// The source creation date. + /// + public const string CretaionDate = "{creation-date}"; + + /// + /// The source creation time. + /// + public const string CreationTime = "{creation-time}"; + /// /// The bitrate. /// diff --git a/win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs b/win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs index 4ef7405f2..4fd7ec1fc 100644 --- a/win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs +++ b/win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs @@ -18,6 +18,7 @@ namespace HandBrakeWPF.Helpers using HandBrake.Interop.Interop.Model.Encoding; using HandBrakeWPF.Extensions; + using HandBrakeWPF.Services.Encode.Model; using HandBrakeWPF.Services.Interfaces; using HandBrakeWPF.Services.Presets.Model; @@ -86,6 +87,35 @@ namespace HandBrakeWPF.Helpers if (chapterFinish != chapterStart && chapterFinish != string.Empty) combinedChapterTag = chapterStart + "-" + chapterFinish; + // Local method to check if we have a creation time in the meta data. If not, fall back to source file creation time. + DateTime obtainCreateDateObject() + { + var rd = task.MetaData.ReleaseDate; + if (DateTime.TryParse(rd, out var d)) + { + return d; + } + try + { + return File.GetCreationTime(task.Source); + } + catch (Exception e) + { + if (e is UnauthorizedAccessException || + e is PathTooLongException || + e is NotSupportedException) + { + // Suspect the most likely concerns trying to grab the creation date in which we would want to swallow exception. + return default(DateTime); + } + throw e; + } + } + + var creationDateTime = obtainCreateDateObject(); + string createDate = creationDateTime.Date.ToShortDateString().Replace('/', '-'); + string createTime = creationDateTime.ToString("HH-mm"); + /* * File Name */ @@ -98,7 +128,9 @@ namespace HandBrakeWPF.Helpers .Replace(Constants.Title, dvdTitle) .Replace(Constants.Chapters, combinedChapterTag) .Replace(Constants.Date, DateTime.Now.Date.ToShortDateString().Replace('/', '-')) - .Replace(Constants.Time, DateTime.Now.ToString("HH:mm")); + .Replace(Constants.Time, DateTime.Now.ToString("HH-mm")) + .Replace(Constants.CretaionDate, createDate) + .Replace(Constants.CreationTime, createTime); // .Replace(Constants.Preset, sanitisedPresetName); if (task.VideoEncodeRateType == VideoEncodeRateType.ConstantQuality) @@ -199,7 +231,7 @@ namespace HandBrakeWPF.Helpers return autoNamePath; } - + /// /// Check if there is a valid autoname path. /// @@ -219,6 +251,6 @@ namespace HandBrakeWPF.Helpers return userSettingService.GetUserSetting(UserSettingConstants.AutoNamePath).Trim().StartsWith("{source_path}") || (userSettingService.GetUserSetting(UserSettingConstants.AutoNamePath).Contains("{source_folder_name}") || Directory.Exists(userSettingService.GetUserSetting(UserSettingConstants.AutoNamePath).Trim())); - } + } } } diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs index bbe866be0..d5ccb157f 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs @@ -1242,7 +1242,7 @@ namespace HandBrakeWPF.Properties { /// Looks up a localized string similar to The format of the output file. In addition to any supported file system character, you can use the following placeholders that will be replaced when you change title or scan a source. /// ///Live Update Options: {source} {title} {chapters} - ///Non-Live Options: {date} {time} {quality} {bitrate} (These only change if you scan a new source, change title or chapters). + ///Non-Live Options: {date} {time} {creation-date} {creation-time} {quality} {bitrate} (These only change if you scan a new source, change title or chapters). /// public static string Options_AdditionalFormatOptions { get { diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx index 21bed46f7..1c0e4c1f2 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.resx +++ b/win/CS/HandBrakeWPF/Properties/Resources.resx @@ -479,7 +479,7 @@ Do you wish to proceed? The format of the output file. In addition to any supported file system character, you can use the following placeholders that will be replaced when you change title or scan a source. Live Update Options: {source} {title} {chapters} -Non-Live Options: {date} {time} {quality} {bitrate} (These only change if you scan a new source, change title or chapters) +Non-Live Options: {date} {time} {creation-date} {creation-time} {quality} {bitrate} (These only change if you scan a new source, change title or chapters) Available additional Options: {source_path} or {source_folder_name} -- cgit v1.2.3