Skip to content

Commit a4929e5

Browse files
author
RandomEngy
committed
Added additional options for auto-naming output file: {preset}, {date}, {time} and {quality}.
1 parent fa67290 commit a4929e5

5 files changed

Lines changed: 61 additions & 73 deletions

File tree

VidCoder/Model/Presets.cs

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@ namespace VidCoder.Model
1212
{
1313
public static class Presets
1414
{
15-
//private static readonly string PresetsFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"VidCoder\Prototype");
1615
private static readonly string UserPresetsFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"VidCoder\UserPresets");
1716
private static readonly string BuiltInPresetsPath = "BuiltInPresets.xml";
18-
//private static readonly string UserPresetsPath = Path.Combine(PresetsFolder, @"UserPresets.xml");
19-
//private static XmlSerializer xmlSerializer = new XmlSerializer(typeof(List<Preset>));
2017
private static XmlSerializer presetListSerializer = new XmlSerializer(typeof(List<Preset>));
2118
private static XmlSerializer presetSerializer = new XmlSerializer(typeof(Preset));
2219
private static object userPresetSync = new object();
23-
private static List<string> disallowedCharacters = new List<string> { "\\", "/", "\"", ":", "*", "?", "<", ">", "|" };
2420

2521
public static List<Preset> BuiltInPresets
2622
{
@@ -102,47 +98,6 @@ public static List<Preset> UserPresets
10298
}
10399
}
104100

105-
//public static List<Preset> UserPresets1
106-
//{
107-
// get
108-
// {
109-
// EnsureFolderCreated();
110-
111-
// try
112-
// {
113-
// lock (userPresetSync)
114-
// {
115-
// XDocument doc = XDocument.Load(UserPresetsPath);
116-
// XElement presetArray = doc.Element("Presets").Element("ArrayOfPreset");
117-
118-
// using (XmlReader reader = presetArray.CreateReader())
119-
// {
120-
// var presetList = presetListSerializer.Deserialize(reader) as List<Preset>;
121-
// return presetList;
122-
// }
123-
// }
124-
// }
125-
// catch (FileNotFoundException)
126-
// {
127-
// }
128-
129-
// return new List<Preset>();
130-
// }
131-
132-
// set
133-
// {
134-
// EnsureFolderCreated();
135-
// StringBuilder xmlBuilder = new StringBuilder();
136-
// using (XmlWriter writer = XmlWriter.Create(xmlBuilder))
137-
// {
138-
// presetListSerializer.Serialize(writer, value);
139-
// }
140-
141-
// // Do the actual save asynchronously.
142-
// ThreadPool.QueueUserWorkItem(SaveUserPresetsBackground, xmlBuilder);
143-
// }
144-
//}
145-
146101
private static void SaveUserPresetsBackground(object presetXmlListObject)
147102
{
148103
lock (userPresetSync)
@@ -169,11 +124,7 @@ private static void SaveUserPresetsBackground(object presetXmlListObject)
169124

170125
private static string FindUserPresetPath(string baseName)
171126
{
172-
string cleanName = baseName;
173-
foreach (string disallowedChar in disallowedCharacters)
174-
{
175-
cleanName = cleanName.Replace(disallowedChar, "_");
176-
}
127+
string cleanName = Utilities.CleanFileName(baseName);
177128

178129
string proposedPresetPath = Path.Combine(UserPresetsFolder, baseName + ".xml");
179130

@@ -192,22 +143,6 @@ private static string FindUserPresetPath(string baseName)
192143
return proposedPresetPath;
193144
}
194145

195-
//private static void SaveUserPresetsBackground1(object xmlBuilderObject)
196-
//{
197-
// lock (userPresetSync)
198-
// {
199-
// var xmlBuilder = xmlBuilderObject as StringBuilder;
200-
201-
// XElement element = XElement.Parse(xmlBuilder.ToString());
202-
// XDocument doc = new XDocument(
203-
// new XElement("UserPreset",
204-
// new XAttribute("Version", "1"),
205-
// element));
206-
207-
// doc.Save(UserPresetsPath);
208-
// }
209-
//}
210-
211146
private static void EnsureFolderCreated()
212147
{
213148
if (!Directory.Exists(UserPresetsFolder))

VidCoder/Utilities/Utilities.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public static class Utilities
1313
public const string UpdateInfoUrl = "http://engy.us/VidCoder/latest.xml";
1414
public const string AppDataFolderName = "VidCoder";
1515

16+
private static List<string> disallowedCharacters = new List<string> { "\\", "/", "\"", ":", "*", "?", "<", ">", "|" };
17+
1618
private static Dictionary<string, double> defaultQueueColumnSizes = new Dictionary<string, double>
1719
{
1820
{"Source", 200},
@@ -137,6 +139,17 @@ public static bool IsValidQueueColumn(string columnId)
137139
return defaultQueueColumnSizes.ContainsKey(columnId);
138140
}
139141

142+
public static string CleanFileName(string fileName)
143+
{
144+
string cleanName = fileName;
145+
foreach (string disallowedChar in disallowedCharacters)
146+
{
147+
cleanName = cleanName.Replace(disallowedChar, "_");
148+
}
149+
150+
return cleanName;
151+
}
152+
140153
public static string CreateUniqueFileName(string baseName, string outputDirectory, HashSet<string> excludedNames)
141154
{
142155
string fileName = Path.GetFileName(baseName);

VidCoder/View/OptionsDialog.xaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@
4343
Margin="195.236,110.223,11,0" Height="22.959" VerticalAlignment="Top"
4444
Text="{Binding CustomFormatString}"
4545
IsEnabled="{Binding CustomFormatStringEnabled}"/>
46-
<Label Margin="195.236,133.866,0.246,130.203" Name="label3">Available options: {source} {title} {chapters}</Label>
46+
<TextBlock Margin="195.236,133.866,0.246,121" TextWrapping="Wrap" Height="36">Available options: {source} {title} {chapters} {preset} {date} {time} {quality}</TextBlock>
4747
<TextBlock
48-
Height="21" HorizontalAlignment="Left" Margin="6,168.04,0,0" VerticalAlignment="Top" Width="82"
48+
Height="21" HorizontalAlignment="Left" Margin="6,176,0,0" VerticalAlignment="Top" Width="82"
4949
Style="{StaticResource EmphasizedTitle}"
5050
Text="Updates:" />
5151
<CheckBox
52-
Height="16" Margin="94,168.04,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="182"
52+
Height="16" Margin="94,176,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="182"
5353
IsChecked="{Binding UpdatesEnabled}">Enable automatic updates</CheckBox>
5454
<Grid
55-
Height="31" Margin="111,190.04,11,0" VerticalAlignment="Top"
55+
Height="31" Margin="111,198,11,0" VerticalAlignment="Top"
5656
Visibility="{Binding UpdatesEnabled, Converter={StaticResource VisibilityConverter}}">
5757
<Grid.ColumnDefinitions>
5858
<ColumnDefinition Width="Auto" />

VidCoder/ViewModel/EncodingViewModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,7 @@ public VideoEncodeRateType VideoEncodeRateType
15271527
this.VideoBitrate = 1200;
15281528
}
15291529

1530+
this.mainViewModel.RefreshDestination();
15301531
this.IsModified = true;
15311532
}
15321533
}
@@ -1542,6 +1543,7 @@ public int TargetSize
15421543
{
15431544
this.profile.TargetSize = value;
15441545
this.NotifyPropertyChanged("TargetSize");
1546+
this.mainViewModel.RefreshDestination();
15451547
this.IsModified = true;
15461548
}
15471549
}
@@ -1557,6 +1559,7 @@ public int VideoBitrate
15571559
{
15581560
this.profile.VideoBitrate = value;
15591561
this.NotifyPropertyChanged("VideoBitrate");
1562+
this.mainViewModel.RefreshDestination();
15601563
this.IsModified = true;
15611564
}
15621565
}
@@ -1572,6 +1575,7 @@ public double Quality
15721575
{
15731576
this.profile.Quality = value;
15741577
this.NotifyPropertyChanged("Quality");
1578+
this.mainViewModel.RefreshDestination();
15751579
this.IsModified = true;
15761580
}
15771581
}

VidCoder/ViewModel/MainViewModel.cs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using VidCoder.Properties;
1414
using VidCoder.Services;
1515
using System.Diagnostics;
16+
using System.Globalization;
1617

1718
namespace VidCoder.ViewModel
1819
{
@@ -1722,6 +1723,8 @@ public ICommand QueueTitlesCommand
17221723
currentAudioChoices.Add(1);
17231724
}
17241725

1726+
EncodingProfile profile = this.SelectedPreset.Preset.EncodingProfile;
1727+
17251728
string queueOutputFileName = this.BuildOutputFileName(
17261729
this.TranslateDvdSourceName(this.sourcePath),
17271730
title.TitleNumber,
@@ -1731,13 +1734,12 @@ public ICommand QueueTitlesCommand
17311734

17321735
string extension = this.GetOutputExtension(subtitles, title);
17331736
string queueOutputPath = this.BuildOutputPath(queueOutputFileName, extension);
1734-
//string uniqueQueueOutputPath = Utilities.CreateUniqueFileName(queueOutputPath, Settings.Default.AutoNameOutputFolder, this.GetQueuedFiles());
17351737

17361738
var job = new EncodeJob
17371739
{
17381740
SourcePath = this.sourcePath,
17391741
OutputPath = queueOutputPath,
1740-
EncodingProfile = this.SelectedPreset.Preset.EncodingProfile.Clone(),
1742+
EncodingProfile = profile.Clone(),
17411743
Title = title.TitleNumber,
17421744
ChapterStart = 1,
17431745
ChapterEnd = title.Chapters.Count,
@@ -2702,6 +2704,40 @@ private string BuildOutputFileName(string sourceName, int title, int startChapte
27022704
fileName = fileName.Replace("{source}", sourceName);
27032705
fileName = fileName.Replace("{title}", title.ToString());
27042706
fileName = fileName.Replace("{chapters}", chapterString);
2707+
fileName = fileName.Replace("{preset}", this.SelectedPreset.Preset.Name);
2708+
2709+
DateTime now = DateTime.Now;
2710+
if (fileName.Contains("{date}"))
2711+
{
2712+
fileName = fileName.Replace("{date}", now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
2713+
}
2714+
2715+
if (fileName.Contains("{time}"))
2716+
{
2717+
fileName = fileName.Replace("{time}", now.Hour + "." + now.Minute + "." + now.Second);
2718+
}
2719+
2720+
if (fileName.Contains("{quality}"))
2721+
{
2722+
EncodingProfile profile = this.SelectedPreset.Preset.EncodingProfile;
2723+
double quality = 0;
2724+
switch (profile.VideoEncodeRateType)
2725+
{
2726+
case VideoEncodeRateType.ConstantQuality:
2727+
quality = profile.Quality;
2728+
break;
2729+
case VideoEncodeRateType.AverageBitrate:
2730+
quality = profile.VideoBitrate;
2731+
break;
2732+
case VideoEncodeRateType.TargetSize:
2733+
quality = profile.TargetSize;
2734+
break;
2735+
default:
2736+
break;
2737+
}
2738+
2739+
fileName = fileName.Replace("{quality}", quality.ToString());
2740+
}
27052741
}
27062742
else
27072743
{
@@ -2727,7 +2763,7 @@ private string BuildOutputFileName(string sourceName, int title, int startChapte
27272763
fileName = sourceName + titleSection + chaptersSection;
27282764
}
27292765

2730-
return fileName;
2766+
return Utilities.CleanFileName(fileName);
27312767
}
27322768

27332769
private int GetFirstUnusedAudioTrack()

0 commit comments

Comments
 (0)