diff options
author | Matthew Lazarow <[email protected]> | 2018-08-13 15:56:01 -0400 |
---|---|---|
committer | Scott <[email protected]> | 2018-08-13 20:56:01 +0100 |
commit | a9daef1e18b93f793479155210110322234bb655 (patch) | |
tree | 0bd762a171c18d9999ec13dfc65f025f1e7db160 /win/CS/HandBrakeWPF | |
parent | 223dc7bd007bfd665948f7e11a9f4681d580cb35 (diff) |
Autoname creation date
Adds {creation-date} and {creation-time} templates to autoname
preference option.
Diffstat (limited to 'win/CS/HandBrakeWPF')
-rw-r--r-- | win/CS/HandBrakeWPF/Constants.cs | 14 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs | 38 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Properties/Resources.Designer.cs | 2 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Properties/Resources.resx | 2 |
4 files changed, 49 insertions, 7 deletions
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,16 +50,26 @@ namespace HandBrakeWPF public const string Quality = "{quality}";
/// <summary>
- /// The quality.
+ /// The creation date of the new output file.
/// </summary>
public const string Date = "{date}";
/// <summary>
- /// The quality.
+ /// The creation time of the new output file.
/// </summary>
public const string Time = "{time}";
/// <summary>
+ /// The source creation date.
+ /// </summary>
+ public const string CretaionDate = "{creation-date}";
+
+ /// <summary>
+ /// The source creation time.
+ /// </summary>
+ public const string CreationTime = "{creation-time}";
+
+ /// <summary>
/// The bitrate.
/// </summary>
public const string Bitrate = "{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;
}
-
+
/// <summary>
/// Check if there is a valid autoname path.
/// </summary>
@@ -219,6 +251,6 @@ namespace HandBrakeWPF.Helpers return userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Trim().StartsWith("{source_path}") ||
(userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Contains("{source_folder_name}") ||
Directory.Exists(userSettingService.GetUserSetting<string>(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).
/// </summary>
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?</value> <value>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)</value>
+Non-Live Options: {date} {time} {creation-date} {creation-time} {quality} {bitrate} (These only change if you scan a new source, change title or chapters)</value>
</data>
<data name="Options_DefaultPathAdditionalParams" xml:space="preserve">
<value>Available additional Options: {source_path} or {source_folder_name}
|