Skip to content
This repository has been archived by the owner on Oct 18, 2021. It is now read-only.

Commit

Permalink
Cache ytdl install and an option to download audio
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowsink committed Oct 24, 2020
1 parent d43f44f commit e081c14
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 104 deletions.
3 changes: 2 additions & 1 deletion README.md
@@ -1,4 +1,5 @@
# Ytdl-Gui
A GUI for Youtube-DL
[![Appveyor Build status](https://ci.appveyor.com/api/projects/status/772gt5qyb5circ3f?svg=true)](https://ci.appveyor.com/project/cainy-a/ytdl-gui)
[![Travis Build Status](https://travis-ci.com/cainy-a/Ytdl-Gui.svg?branch=master)](https://travis-ci.com/cainy-a/Ytdl-Gui)

A GUI for [Youtube-DL](https://yt-dl.org)
30 changes: 19 additions & 11 deletions Ytdl-Gui/Download.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
Expand All @@ -7,27 +8,34 @@ namespace Ytdl_Gui
{
public static class Download
{
public static void DownloadUrls(List<string> urls)
public static void DownloadUrls(List<string> urls, bool extractAudio = false, bool forceRedownload = false)
{
GetDownloader();
foreach (var VARIABLE in urls)
var ytdlDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Cain Atkinson\\Ytdl-Gui");
var ytdlPath = Path.Combine(ytdlDir, "youtube-dl.exe");
if (!File.Exists(ytdlPath) || forceRedownload)
{
RunYtdl(VARIABLE);
Directory.CreateDirectory(ytdlDir);
GetDownloader(ytdlPath);
}

foreach (var VARIABLE in urls)
{
RunYtdl(VARIABLE, ytdlPath, extractAudio);
} // Download each URL
File.Delete("youtube-dl.exe"); // Delete the Downloader
}
private static void RunYtdl(string url)
private static void RunYtdl(string url, string ytdlPath, bool extractAudio = false)
{
var dlProcess = Process.Start(
Directory.GetCurrentDirectory() + "\\youtube-dl",
url); // Start the Process
var dlProcess = Process.Start(ytdlPath,
extractAudio ? $"-x {url}" : url); // Start the Process
dlProcess.WaitForExit(); // Wait for the Downloader to finish
} // Calls YTDL and waits for it
private static void GetDownloader()
private static void GetDownloader(string pathToDownload)
{
using (var client = new WebClient())
{
client.DownloadFile("https://yt-dl.org/downloads/2020.05.08/youtube-dl.exe", "youtube-dl.exe");

client.DownloadFile("https://yt-dl.org/downloads/latest/youtube-dl.exe", pathToDownload);
}
} // Downloads Youtube-DL
}
Expand Down
206 changes: 115 additions & 91 deletions Ytdl-Gui/Form1.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 Ytdl-Gui/Form1.cs
Expand Up @@ -97,7 +97,7 @@ private async void buttonDownload_Click(object sender, EventArgs e)
tempUrls.AddRange(from object variable in listBoxSelected.Items select variable.ToString());

// DownloadUrls(tempUrls); // old way, runs it synchronously
await Task.Factory.StartNew(() => DownloadUrls(tempUrls)); // New way, should run async.
await Task.Factory.StartNew(() => DownloadUrls(tempUrls, checkBoxExtract.Checked, checkBoxRedownload.Checked));

buttonDownload.Text = "Done!";
_busy = false;
Expand Down

0 comments on commit e081c14

Please sign in to comment.