Skip to content

Commit b9b804f

Browse files
committed
changes for 3.3.0
1 parent cbd804f commit b9b804f

14 files changed

+199
-105
lines changed

App.config

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<add key="HighQuality" value="true" />
2323
<add key="EncodingMode" value="Variable" />
2424
<add key="AudioEnabled" value="false" />
25+
<add key="PathDownload" value="" />
2526
<add key="ClientSettingsProvider.ServiceUri" value="" />
2627
</appSettings>
2728
<system.web>

Binaries/Win64/youtube-dl.exe

7.69 MB
Binary file not shown.

Dialogs/DownloadDialog.Designer.cs

+26-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dialogs/DownloadDialog.cs

+60-60
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,31 @@
66
using Microsoft.WindowsAPICodePack.Taskbar;
77
using Timer = System.Windows.Forms.Timer;
88
using static WebMConverter.Utility;
9+
using System.Linq;
910

1011
namespace WebMConverter.Dialogs
1112
{
1213
public partial class DownloadDialog : Form
1314
{
1415
public string Outfile;
16+
public string OutputPath;
1517

1618
private readonly string _infile;
17-
private YoutubeDL _filenameGetterProcess;
1819
private YoutubeDL _downloaderProcess;
1920

2021
private Timer _timer;
2122
private bool _ended;
2223
private bool _panic;
23-
private bool _gettingFilename;
2424

2525
private TaskbarManager taskbarManager;
2626

27-
public DownloadDialog(string url)
27+
public DownloadDialog(string url, string outputPath)
2828
{
2929
InitializeComponent();
3030
pictureStatus.BackgroundImage = StatusImages.Images["Happening"];
3131

3232
_infile = '"' + url.Replace(@"""", @"\""") + '"';
33-
Outfile = Path.GetTempPath();
33+
OutputPath = outputPath;
3434

3535
taskbarManager = TaskbarManager.Instance;
3636
}
@@ -41,26 +41,32 @@ private void ProcessOnErrorDataReceived(object sender, DataReceivedEventArgs arg
4141
boxOutput.Invoke((Action)(() => boxOutput.AppendText(Environment.NewLine + args.Data)));
4242
}
4343

44-
private void FilenameGetterOnOutputDataReceived(object sender, DataReceivedEventArgs args)
45-
{
46-
if (args.Data != null)
47-
Outfile = Path.Combine(Outfile, args.Data);
48-
}
49-
5044
private void ProcessOnOutputDataReceived(object sender, DataReceivedEventArgs args)
5145
{
5246
if (args.Data != null)
5347
{
5448
boxOutput.Invoke((Action)(() => boxOutput.AppendText(Environment.NewLine + args.Data)));
5549

5650
if (DataContainsProgress(args.Data))
51+
{
5752
ParseAndUpdateProgress(args.Data);
53+
if(String.IsNullOrEmpty(Outfile))
54+
GetId(args.Data);
55+
}
56+
5857
}
5958
}
6059

60+
private void GetId(string data)
61+
{
62+
if(data.Contains("Destination:"))
63+
Outfile = data.Split('-').LastOrDefault().Split('.')[0];
64+
}
65+
6166
// example youtube-dl line:
6267
// [download] 51.5% of ~3.85MiB at 20.49MiB/s ETA 00:00
6368

69+
private bool DataContainsFFMPEG(string data) => data.StartsWith("[ffmpeg]");
6470
private bool DataContainsProgress(string data) => data.StartsWith("[download]");
6571

6672
private void ParseAndUpdateProgress(string input)
@@ -80,29 +86,18 @@ private void ParseAndUpdateProgress(string input)
8086

8187
private void DownloadDialog_Load(object sender, EventArgs e)
8288
{
83-
_filenameGetterProcess = new YoutubeDL("--get-filename " + _infile);
89+
boxOutput.AppendText($"{Environment.NewLine}Starting Process");
8490
_downloaderProcess = new YoutubeDL(null);
8591

86-
_gettingFilename = true;
87-
88-
_filenameGetterProcess.ErrorDataReceived += ProcessOnErrorDataReceived;
89-
_filenameGetterProcess.OutputDataReceived += FilenameGetterOnOutputDataReceived;
90-
_filenameGetterProcess.Exited += (o, args) => boxOutput.Invoke((Action) (() =>
91-
{
92-
if (_panic) return;
93-
boxOutput.AppendText($"{Environment.NewLine}Downloading to {Outfile}");
94-
_downloaderProcess.StartInfo.Arguments = $@"-o ""{Outfile}"" {_infile}";
95-
96-
_timer = new Timer { Interval = 500 };
97-
_timer.Tick += Exited;
98-
_timer.Start();
99-
}));
92+
if(_infile.Contains("youtube"))
93+
_downloaderProcess.StartInfo.Arguments = $@"-f bestvideo+bestaudio {_infile}";
94+
else
95+
_downloaderProcess.StartInfo.Arguments = $@" {_infile}";
10096

10197
_downloaderProcess.ErrorDataReceived += ProcessOnErrorDataReceived;
10298
_downloaderProcess.OutputDataReceived += ProcessOnOutputDataReceived;
10399
_downloaderProcess.Exited += (o, args) => boxOutput.Invoke((Action)(() =>
104100
{
105-
if (_panic) return; //This should stop that one exception when closing the converter
106101
boxOutput.AppendText($"{Environment.NewLine}--- YOUTUBE-DL HAS EXITED ---");
107102
buttonCancel.Enabled = false;
108103

@@ -111,35 +106,15 @@ private void DownloadDialog_Load(object sender, EventArgs e)
111106
_timer.Start();
112107
}));
113108

114-
taskbarManager.SetProgressState(TaskbarProgressBarState.Indeterminate); // can't get progress for filename getter
115-
progressBar.Style = ProgressBarStyle.Marquee;
116-
_filenameGetterProcess.Start();
109+
taskbarManager.SetProgressState(TaskbarProgressBarState.Normal);
110+
progressBar.Style = ProgressBarStyle.Blocks;
111+
_downloaderProcess.Start();
117112
}
118113

119114
private void Exited(object sender, EventArgs eventArgs)
120115
{
121116
_timer.Stop();
122117

123-
if (_gettingFilename)
124-
{
125-
if (_filenameGetterProcess.ExitCode != 0)
126-
{
127-
boxOutput.AppendText($"{Environment.NewLine}{Environment.NewLine}youtube-dl.exe exited with exit code {_filenameGetterProcess.ExitCode}. That's usually bad.");
128-
boxOutput.AppendText($"{Environment.NewLine}If you have no idea what went wrong, open an issue on GitGud and copy paste the output of this window there.");
129-
pictureStatus.BackgroundImage = StatusImages.Images["Failure"];
130-
buttonCancel.Enabled = true;
131-
_ended = true;
132-
}
133-
else
134-
{
135-
_gettingFilename = false;
136-
taskbarManager.SetProgressState(TaskbarProgressBarState.Normal);
137-
progressBar.Style = ProgressBarStyle.Blocks;
138-
_downloaderProcess.Start();
139-
}
140-
return;
141-
}
142-
143118
if (_downloaderProcess.ExitCode != 0)
144119
{
145120
boxOutput.AppendText($"{Environment.NewLine}{Environment.NewLine}youtube-dl.exe exited with exit code {_downloaderProcess.ExitCode}. That's usually bad.");
@@ -153,27 +128,45 @@ private void Exited(object sender, EventArgs eventArgs)
153128
boxOutput.AppendText($"{Environment.NewLine}{Environment.NewLine}Video downloaded succesfully!");
154129
pictureStatus.BackgroundImage = StatusImages.Images["Success"];
155130
buttonLoad.Enabled = true;
131+
buttonCancel.Enabled = true;
132+
buttonCancel.Text = "Close";
133+
MoveNewFile();
134+
this.Activate();
135+
}
136+
137+
_ended = true;
138+
}
139+
140+
private void MoveNewFile()
141+
{
142+
if (String.IsNullOrEmpty(Outfile))
143+
return;
156144

157-
// workaround for https://github.com/rg3/youtube-dl/issues/11472
158-
if (!File.Exists(Outfile))
145+
string[] fileEntries = Directory.GetFiles(".");
146+
foreach (string fileName in fileEntries)
147+
{
148+
if (fileName.Contains(Outfile))
159149
{
160-
Outfile = Path.ChangeExtension(Outfile, "mkv");
150+
Outfile = fileName;
151+
break;
161152
}
162153
}
163-
164-
_ended = true;
154+
File.Move(Outfile, Path.Combine(OutputPath, Outfile));
165155
}
166156

167157
private void buttonCancel_Click(object sender, EventArgs e)
168158
{
169-
if (!_ended || _panic) //Prevent stack overflow
159+
if (buttonCancel.Text.Equals("Close"))
170160
{
171-
if (!_filenameGetterProcess.HasExited)
172-
KillProcessAndChildren(_filenameGetterProcess.Id);
161+
if(!_downloaderProcess.HasExited)
162+
KillProcessAndChildren(_downloaderProcess.Id);
173163

174-
if (_gettingFilename)
175-
return;
164+
Dispose();
165+
return;
166+
}
176167

168+
if (!_ended || _panic) //Prevent stack overflow
169+
{
177170
if (!_downloaderProcess.HasExited)
178171
KillProcessAndChildren(_downloaderProcess.Id);
179172
}
@@ -190,7 +183,6 @@ private void ConverterForm_FormClosing(object sender, FormClosingEventArgs e)
190183

191184
private void ConverterForm_FormClosed(object sender, FormClosedEventArgs e)
192185
{
193-
_filenameGetterProcess.Dispose();
194186
_downloaderProcess.Dispose();
195187
}
196188

@@ -201,5 +193,13 @@ private void buttonLoad_Click(object sender, EventArgs e)
201193
}
202194

203195
private void boxOutput_TextChanged(object sender, EventArgs e) => NativeMethods.SendMessage(boxOutput.Handle, 0x115, 7, 0);
196+
197+
internal string GetOutfile()
198+
{
199+
if (String.IsNullOrEmpty(Outfile))
200+
return String.Empty;
201+
202+
return OutputPath + Outfile.Substring(1);
203+
}
204204
}
205205
}

Dialogs/DownloadDialog.resx

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
129129
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
130130
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADc
131-
CgAAAk1TRnQBSQFMAgEBAwEAAUgBAAFIAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
131+
CgAAAk1TRnQBSQFMAgEBAwEAAVABAAFQAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
132132
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
133133
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
134134
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA

0 commit comments

Comments
 (0)