Skip to content

Commit

Permalink
WinGui: Add {preset} to autoname options. This is a non-live option m…
Browse files Browse the repository at this point in the history
…eaning it only changes when the title changes. (Same as {date} {time} {quality} {bitrate}). Implements HandBrake#156
  • Loading branch information
sr55 committed Jun 9, 2016
1 parent cea9d23 commit 2002aa9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
5 changes: 5 additions & 0 deletions win/CS/HandBrakeWPF/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public class Constants
/// </summary>
public const string Bitrate = "{bitrate}";

/// <summary>
/// The preset.
/// </summary>
public const string Preset = "{preset}";

/// <summary>
/// Preset Major Version
/// </summary>
Expand Down
17 changes: 11 additions & 6 deletions win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace HandBrakeWPF.Helpers

using HandBrakeWPF.Extensions;
using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.Services.Presets.Model;

using EncodeTask = HandBrakeWPF.Services.Encode.Model.EncodeTask;
using OutputFormat = HandBrakeWPF.Services.Encode.Model.Models.OutputFormat;
Expand All @@ -41,7 +42,7 @@ public class AutoNameHelper
/// <returns>
/// The Generated FileName
/// </returns>
public static string AutoName(EncodeTask task, string sourceOrLabelName)
public static string AutoName(EncodeTask task, string sourceOrLabelName, Preset presetName)
{
IUserSettingService userSettingService = IoC.Get<IUserSettingService>();
if (task.Destination == null)
Expand All @@ -54,6 +55,7 @@ public static string AutoName(EncodeTask task, string sourceOrLabelName)
{
// Get the Source Name and remove any invalid characters
string sourceName = Path.GetInvalidFileNameChars().Aggregate(sourceOrLabelName, (current, character) => current.Replace(character.ToString(), string.Empty));
string sanitisedPresetName = presetName != null ? Path.GetInvalidFileNameChars().Aggregate(presetName.Name, (current, character) => current.Replace(character.ToString(), string.Empty)) : string.Empty;

// Remove Underscores
if (userSettingService.GetUserSetting<bool>(UserSettingConstants.AutoNameRemoveUnderscore))
Expand Down Expand Up @@ -88,11 +90,14 @@ public static string AutoName(EncodeTask task, string sourceOrLabelName)
if (userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNameFormat) != string.Empty)
{
destinationFilename = userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNameFormat);
destinationFilename = destinationFilename.Replace("{source}", sourceName)
.Replace(Constants.Title, dvdTitle)
.Replace(Constants.Chapters, combinedChapterTag)
.Replace(Constants.Date, DateTime.Now.Date.ToShortDateString().Replace('/', '-'))
.Replace(Constants.Time, DateTime.Now.ToString("HH:mm"));
destinationFilename =
destinationFilename
.Replace("{source}", sourceName)
.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.Preset, sanitisedPresetName);

if (task.VideoEncodeRateType == VideoEncodeRateType.ConstantQuality)
{
Expand Down
2 changes: 1 addition & 1 deletion win/CS/HandBrakeWPF/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion win/CS/HandBrakeWPF/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,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} {quality} {bitrate} {preset} (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}
Expand Down
6 changes: 3 additions & 3 deletions win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ public Title SelectedTitle
{
if (this.userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNameFormat) != null)
{
this.Destination = AutoNameHelper.AutoName(this.CurrentTask, this.SourceName);
this.Destination = AutoNameHelper.AutoName(this.CurrentTask, this.SourceName, this.SelectedPreset);
}
}
this.NotifyOfPropertyChange(() => this.CurrentTask);
Expand Down Expand Up @@ -817,7 +817,7 @@ public int SelectedStartPoint
if (this.SelectedPointToPoint == PointToPointMode.Chapters && this.userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNameFormat) != null &&
this.userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNameFormat).Contains(Constants.Chapters))
{
this.Destination = AutoNameHelper.AutoName(this.CurrentTask, this.SourceName);
this.Destination = AutoNameHelper.AutoName(this.CurrentTask, this.SourceName, this.SelectedPreset);
}
}

Expand Down Expand Up @@ -846,7 +846,7 @@ public int SelectedEndPoint
if (this.SelectedPointToPoint == PointToPointMode.Chapters && this.userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNameFormat) != null &&
this.userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNameFormat).Contains(Constants.Chapters))
{
this.Destination = AutoNameHelper.AutoName(this.CurrentTask, this.SourceName);
this.Destination = AutoNameHelper.AutoName(this.CurrentTask, this.SourceName, this.SelectedPreset);
}

if (this.SelectedStartPoint > this.SelectedEndPoint && this.SelectedPointToPoint == PointToPointMode.Chapters)
Expand Down

0 comments on commit 2002aa9

Please sign in to comment.