Skip to content

Commit 0814ae5

Browse files
author
RandomEngy
committed
When doing batch file encodes, we now pick the default title to encode rather
than just the first one every time. --HG-- branch : beta
1 parent f3fa6de commit 0814ae5

4 files changed

Lines changed: 33 additions & 28 deletions

File tree

VidCoder/Utilities/Utilities.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,27 @@ public static bool CanPassthrough(AudioCodec codec)
430430
codec == AudioCodec.Mp3;
431431
}
432432

433+
public static Title GetFeatureTitle(List<Title> titles, int hbFeatureTitle)
434+
{
435+
// If the feature title is supplied, find it in the list.
436+
if (hbFeatureTitle > 0)
437+
{
438+
return titles.FirstOrDefault(title => title.TitleNumber == hbFeatureTitle);
439+
}
440+
441+
// Select the first title within 80% of the duration of the longest title.
442+
double maxSeconds = titles.Max(title => title.Duration.TotalSeconds);
443+
foreach (Title title in titles)
444+
{
445+
if (title.Duration.TotalSeconds >= maxSeconds * .8)
446+
{
447+
return title;
448+
}
449+
}
450+
451+
return titles[0];
452+
}
453+
433454
// Assumes the hashset has a comparer of StringComparer.OrdinalIgnoreCase
434455
public static bool? FileExists(string path, HashSet<string> queuedPaths)
435456
{

VidCoder/View/Panels/AdvancedPanel.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@
100100
</StackPanel>
101101

102102
<TextBlock
103-
Text="{x:Static res:EncodingRes.AdvancedOptionsStringLabel}" HorizontalAlignment="Left" Margin="7,117,0,0" VerticalAlignment="Top" />
103+
Text="{x:Static res:EncodingRes.AdvancedOptionsStringLabel}" HorizontalAlignment="Left" Margin="9,117,0,0" VerticalAlignment="Top" />
104104
<TextBox
105-
Margin="0,134,0,0" VerticalAlignment="Top" Height="40"
105+
Margin="6,134,6,0" VerticalAlignment="Top" Height="40"
106106
Text="{Binding AdvancedOptionsString, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" />
107107
</Grid>
108108
</UserControl>

VidCoder/ViewModel/MainViewModel.cs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,28 +2146,7 @@ private void UpdateFromNewVideoSource()
21462146

21472147
if (this.sourceData != null && this.sourceData.Titles != null && this.sourceData.Titles.Count > 0)
21482148
{
2149-
if (this.sourceData.FeatureTitle > 0)
2150-
{
2151-
selectTitle = this.sourceData.Titles.FirstOrDefault(title => title.TitleNumber == this.sourceData.FeatureTitle);
2152-
}
2153-
else
2154-
{
2155-
// Select the first title within 80% of the duration of the longest title.
2156-
double maxSeconds = this.sourceData.Titles.Max(title => title.Duration.TotalSeconds);
2157-
foreach (Title title in this.sourceData.Titles)
2158-
{
2159-
if (title.Duration.TotalSeconds >= maxSeconds * .8)
2160-
{
2161-
selectTitle = title;
2162-
break;
2163-
}
2164-
}
2165-
2166-
if (selectTitle == null)
2167-
{
2168-
selectTitle = this.sourceData.Titles[0];
2169-
}
2170-
}
2149+
selectTitle = Utilities.GetFeatureTitle(this.sourceData.Titles, this.sourceData.FeatureTitle);
21712150
}
21722151

21732152
if (selectTitle != null)

VidCoder/ViewModel/ScanMultipleDialogViewModel.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace VidCoder.ViewModel
99
{
10+
using HandBrake.Interop.SourceData;
11+
1012
/// <summary>
1113
/// View model for dialog that shows when scanning multiple files.
1214
/// </summary>
@@ -45,17 +47,20 @@ public void ScanNextJob()
4547
{
4648
EncodeJobViewModel jobVM = itemsToScan[currentJobIndex];
4749

48-
HandBrakeInstance onDemandInstance = new HandBrakeInstance();
50+
var onDemandInstance = new HandBrakeInstance();
4951
onDemandInstance.Initialize(Config.LogVerbosity);
5052
onDemandInstance.ScanCompleted += (o, e) =>
5153
{
5254
jobVM.HandBrakeInstance = onDemandInstance;
5355

5456
if (onDemandInstance.Titles.Count > 0)
5557
{
56-
jobVM.Job.Length = onDemandInstance.Titles[0].Duration;
58+
Title titleToEncode = Utilities.GetFeatureTitle(onDemandInstance.Titles, onDemandInstance.FeatureTitle);
59+
60+
jobVM.Job.Title = titleToEncode.TitleNumber;
61+
jobVM.Job.Length = titleToEncode.Duration;
5762
jobVM.Job.ChapterStart = 1;
58-
jobVM.Job.ChapterEnd = onDemandInstance.Titles[0].Chapters.Count;
63+
jobVM.Job.ChapterEnd = titleToEncode.Chapters.Count;
5964
}
6065

6166
lock (this.currentJobIndexLock)
@@ -77,7 +82,7 @@ public void ScanNextJob()
7782
}
7883
};
7984

80-
onDemandInstance.StartScan(jobVM.Job.SourcePath, 10, 1);
85+
onDemandInstance.StartScan(jobVM.Job.SourcePath, 10, 0);
8186
}
8287
}
8388
}

0 commit comments

Comments
 (0)