Files
ytdlp-gui/Main.cs

65 lines
1.7 KiB
C#
Raw Normal View History

2025-05-20 02:11:57 +02:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ytdlp_gui
{
public partial class Main : Form
{
public Main()
{
2025-05-20 02:28:22 +02:00
ytdlp = new YTdlp();
2025-05-20 02:11:57 +02:00
downloads = new List<Download>();
InitializeComponent();
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnDownload_Click(object sender, EventArgs e)
{
2025-05-20 02:28:22 +02:00
// Get user download folder on Windows
string user = Environment.GetEnvironmentVariable("USERNAME");
string workdir = @"C:\Users\" + user + @"\Downloads\";
YTdlpProcess process = ytdlp.Download(
textUrl.Text,
checkAudioOnly.Checked,
false,
workdir
);
Download download = new Download(process, workdir);
2025-05-20 02:11:57 +02:00
download.Show();
downloads.Add(download);
download.FormClosed += (_sender, _e) => {
downloads.Remove(download);
};
}
private void Main_FormClosing(object sender, FormClosingEventArgs e)
{
if (downloads.Count == 0)
return;
var window = MessageBox.Show(
"Close the window?\nClosing current window will cancel current downloads!",
"Are you sure?",
MessageBoxButtons.YesNo
);
e.Cancel = (window == DialogResult.No);
}
protected List<Download> downloads;
2025-05-20 02:28:22 +02:00
protected YTdlp ytdlp;
2025-05-20 02:11:57 +02:00
}
}