forked from jarrettv/ChapterGrabber
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStreamSelectDialog.cs
92 lines (83 loc) · 2.98 KB
/
StreamSelectDialog.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace JarrettVance.ChapterTools
{
public partial class StreamSelectDialog : Form
{
private static readonly TimeSpan TWENTY = TimeSpan.FromMinutes(20);
private readonly List<ChapterInfo> extracted;
public StreamSelectDialog(ChapterExtractor extractor)
{
InitializeComponent();
this.MinimumSize = new Size(700, 400);
extracted = new List<ChapterInfo>();
extractor.StreamDetected += (sender, arg) =>
{
extracted.Add(arg.ProgramChain);
if (!Hidden(arg.ProgramChain)) listBox1.Items.Add(arg.ProgramChain);
};
extractor.ChaptersLoaded += (sender, arg) =>
{
for (int i = 0; i < listBox1.Items.Count; i++)
{
if (((ChapterInfo)listBox1.Items[i]).SourceName == arg.ProgramChain.SourceName)
{
listBox1.Items[i] = arg.ProgramChain;
break;
}
}
};
extractor.ExtractionComplete += (sender, arg) =>
{
Reload();
};
}
private bool Hidden(ChapterInfo pgc)
{
if (checkBoxLessThan20mins.Checked && pgc.Duration < TWENTY) return true;
if (checkBoxLessThan5.Checked && pgc.Chapters.Count < 5) return true;
if (checkBoxGreaterThan50.Checked && pgc.Chapters.Count > 50) return true;
return false;
}
private void Reload()
{
ChapterInfo[] show = extracted
.Where(x => !Hidden(x))
.OrderByDescending(x => x.Duration)
.ToArray();
int hidden = extracted.Count - show.Length;
lblCounts.Text = string.Format("{0} shown {1} hidden", show.Length, hidden);
listBox1.Items.Clear();
listBox1.Items.AddRange(show);
if (extracted.Count > 0)
{
var vol = extracted.First().VolumeName;
if (!string.IsNullOrEmpty(vol))
{
this.Text = "Select Stream from " + vol;
listBox1.SelectedIndex = 0;
}
}
}
public ChapterInfo ProgramChain
{
get { return listBox1.SelectedItems.Count > 0 ? listBox1.SelectedItem as ChapterInfo : null; }
}
private void btnOK_Click(object sender, EventArgs e)
{
if (listBox1.SelectedItems.Count == 1)
DialogResult = DialogResult.OK;
else
MessageBox.Show("Please select a stream.");
}
private void checkBox_CheckedChanged(object sender, EventArgs e)
{
Reload();
}
}
}