Skip to content

Commit

Permalink
fix arguments and limited keys for schemas
Browse files Browse the repository at this point in the history
closes #165

also, if custom arguments are on the main form, they will be copied over to the extended form.
  • Loading branch information
murrty committed Dec 15, 2022
1 parent 1f85c0d commit 9288824
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 146 deletions.
245 changes: 121 additions & 124 deletions youtube-dl-gui/Forms/frmDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ public partial class frmDownloader : Form {
private volatile string Msg = string.Empty; // Output message.
private readonly bool Debug = false;

public frmDownloader(DownloadInfo Info) {
InitializeComponent();
LoadLanguage();
CurrentDownload = Info;
}

public frmDownloader() {
Program.RunningActions.Add(this);
InitializeComponent();
Expand All @@ -28,6 +22,11 @@ public frmDownloader() {
};
t.Tick += (s, e) => rtbVerbose.AppendLine("Hello when when when when when when when when when when when when when when when when when when");
}
public frmDownloader(DownloadInfo Info) {
InitializeComponent();
LoadLanguage();
CurrentDownload = Info;
}

private void LoadLanguage() {
this.Text = Language.frmDownloader + " ";
Expand All @@ -38,124 +37,6 @@ private void LoadLanguage() {
chkDownloaderCloseAfterDownload.Text = Language.chkDownloaderCloseAfterDownload;
chkDownloaderCloseAfterDownload.Checked = Config.Settings.Downloads.CloseDownloaderAfterFinish;
}

private void frmExtendedMassDownloader_Load(object sender, EventArgs e) {
if (Debug) {
btnDownloaderAbortBatchDownload.Visible = true;
tmrTitleActivity.Start();
}
else {
if (CurrentDownload.BatchDownload) {
this.WindowState = FormWindowState.Minimized;
btnDownloaderAbortBatchDownload.Enabled = true;
btnDownloaderAbortBatchDownload.Visible = true;
}
}

if (Config.Settings.Saved.QuickDownloaderLocation.Valid) {
this.StartPosition = FormStartPosition.Manual;
this.Location = Config.Settings.Saved.QuickDownloaderLocation;
}

}
private void frmExtendedMassDownloader_Shown(object sender, EventArgs e) {
pbStatus.Focus();
if (!Debug)
BeginDownload();
}
private void frmExtendedMassDownloader_FormClosing(object sender, FormClosingEventArgs e) {
DialogResult Finish = DialogResult.None;
switch (CurrentDownload.Status) {
case DownloadStatus.Aborted:
if (CurrentDownload.BatchDownload)
Finish = AbortBatch ? DialogResult.Abort : DialogResult.Ignore;
break;

case DownloadStatus.Finished:
if (CurrentDownload.BatchDownload)
Finish = DownloadProcess.ExitCode == 0 ? DialogResult.Yes : DialogResult.No;
break;

case DownloadStatus.ProgramError:
case DownloadStatus.YtdlError:
if (CurrentDownload.BatchDownload)
Finish = DialogResult.No;
break;

default:
if (DownloadThread is not null && DownloadThread.IsAlive) {
DownloadThread.Abort();
e.Cancel = true;
}
break;
}
if (!e.Cancel) {
if (!CurrentDownload.BatchDownload)
Config.Settings.Downloads.CloseDownloaderAfterFinish = chkDownloaderCloseAfterDownload.Checked;
Config.Settings.Saved.QuickDownloaderLocation = this.Location;
this.DialogResult = Finish;
this.Dispose();
}
}
private void tmrTitleActivity_Tick(object sender, EventArgs e) {
this.Text = this.Text.EndsWith("....") ? this.Text.TrimEnd('.') : this.Text += ".";
}
private void btnClearOutput_Click(object sender, EventArgs e) {
if (Debug)
rtbVerbose.AppendLine("Hello, world world world world world world world world world world world world");
else
rtbVerbose.Clear();
}
private void btnDownloaderAbortBatchDownload_Click(object sender, EventArgs e) {
switch (CurrentDownload.Status) {
case DownloadStatus.YtdlError:
case DownloadStatus.ProgramError:
case DownloadStatus.Aborted: {
btnDownloaderAbortBatchDownload.Visible = false;
btnDownloaderAbortBatchDownload.Enabled = false;
this.Text = Language.frmDownloader + " ";
tmrTitleActivity.Start();
BeginDownload();
} break;

default: {
AbortBatch = true;
switch (CurrentDownload.Status) {
case DownloadStatus.Finished:
case DownloadStatus.Aborted:
case DownloadStatus.YtdlError:
case DownloadStatus.ProgramError:
rtbVerbose.AppendLine("The user requested to abort subsequent batch downloads");
btnDownloaderAbortBatchDownload.Enabled = false;
btnDownloaderAbortBatchDownload.Visible = false;
break;
default:
if (DownloadThread is not null && DownloadThread.IsAlive) {
DownloadThread.Abort();
}
rtbVerbose.AppendLine("Additionally, the batch download has been cancelled.");
this.Close();
break;
}
} break;
}
}
private void btnDownloaderCancelExit_Click(object sender, EventArgs e) {
switch (CurrentDownload.Status) {
case DownloadStatus.Finished:
case DownloadStatus.YtdlError:
case DownloadStatus.Aborted:
this.Close();
break;
default:
Log.Write("Aborting download.");
if (DownloadThread is not null && DownloadThread.IsAlive) {
DownloadThread.Abort();
}
break;
}
}

public void Abort() {
switch (CurrentDownload.Status) {
case DownloadStatus.YtdlError:
Expand Down Expand Up @@ -481,4 +362,120 @@ private void DownloadFinished() {
}
}

private void frmExtendedMassDownloader_Load(object sender, EventArgs e) {
if (Debug) {
btnDownloaderAbortBatchDownload.Visible = true;
tmrTitleActivity.Start();
}
else {
if (CurrentDownload.BatchDownload) {
this.WindowState = FormWindowState.Minimized;
btnDownloaderAbortBatchDownload.Enabled = true;
btnDownloaderAbortBatchDownload.Visible = true;
}
}

if (Config.Settings.Saved.QuickDownloaderLocation.Valid) {
this.StartPosition = FormStartPosition.Manual;
this.Location = Config.Settings.Saved.QuickDownloaderLocation;
}

}
private void frmExtendedMassDownloader_Shown(object sender, EventArgs e) {
pbStatus.Focus();
if (!Debug)
BeginDownload();
}
private void frmExtendedMassDownloader_FormClosing(object sender, FormClosingEventArgs e) {
DialogResult Finish = DialogResult.None;
switch (CurrentDownload.Status) {
case DownloadStatus.Aborted:
if (CurrentDownload.BatchDownload)
Finish = AbortBatch ? DialogResult.Abort : DialogResult.Ignore;
break;

case DownloadStatus.Finished:
if (CurrentDownload.BatchDownload)
Finish = DownloadProcess.ExitCode == 0 ? DialogResult.Yes : DialogResult.No;
break;

case DownloadStatus.ProgramError:
case DownloadStatus.YtdlError:
if (CurrentDownload.BatchDownload)
Finish = DialogResult.No;
break;

default:
if (DownloadThread is not null && DownloadThread.IsAlive) {
DownloadThread.Abort();
e.Cancel = true;
}
break;
}
if (!e.Cancel) {
if (!CurrentDownload.BatchDownload)
Config.Settings.Downloads.CloseDownloaderAfterFinish = chkDownloaderCloseAfterDownload.Checked;
Config.Settings.Saved.QuickDownloaderLocation = this.Location;
this.DialogResult = Finish;
this.Dispose();
}
}
private void tmrTitleActivity_Tick(object sender, EventArgs e) {
this.Text = this.Text.EndsWith("....") ? this.Text.TrimEnd('.') : this.Text += ".";
}
private void btnClearOutput_Click(object sender, EventArgs e) {
if (Debug)
rtbVerbose.AppendLine("Hello, world world world world world world world world world world world world");
else
rtbVerbose.Clear();
}
private void btnDownloaderAbortBatchDownload_Click(object sender, EventArgs e) {
switch (CurrentDownload.Status) {
case DownloadStatus.YtdlError:
case DownloadStatus.ProgramError:
case DownloadStatus.Aborted: {
btnDownloaderAbortBatchDownload.Visible = false;
btnDownloaderAbortBatchDownload.Enabled = false;
this.Text = Language.frmDownloader + " ";
tmrTitleActivity.Start();
BeginDownload();
} break;

default: {
AbortBatch = true;
switch (CurrentDownload.Status) {
case DownloadStatus.Finished:
case DownloadStatus.Aborted:
case DownloadStatus.YtdlError:
case DownloadStatus.ProgramError:
rtbVerbose.AppendLine("The user requested to abort subsequent batch downloads");
btnDownloaderAbortBatchDownload.Enabled = false;
btnDownloaderAbortBatchDownload.Visible = false;
break;
default:
if (DownloadThread is not null && DownloadThread.IsAlive) {
DownloadThread.Abort();
}
rtbVerbose.AppendLine("Additionally, the batch download has been cancelled.");
this.Close();
break;
}
} break;
}
}
private void btnDownloaderCancelExit_Click(object sender, EventArgs e) {
switch (CurrentDownload.Status) {
case DownloadStatus.Finished:
case DownloadStatus.YtdlError:
case DownloadStatus.Aborted:
this.Close();
break;
default:
Log.Write("Aborting download.");
if (DownloadThread is not null && DownloadThread.IsAlive) {
DownloadThread.Abort();
}
break;
}
}
}
10 changes: 7 additions & 3 deletions youtube-dl-gui/Forms/frmExtendedDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading;
using System.Windows.Forms;
// Download specific times: yt-dlp -i --download-sections "*00:00:00-00:00:10"
// --abort-on-unavailable-fragment (may prevent broken files)
public partial class frmExtendedDownloader : Form {
public string URL { get; }
public string VideoName { get; private set; }
Expand Down Expand Up @@ -52,6 +53,9 @@ public frmExtendedDownloader(string URL, bool Archived) {
lvAudioFormats.SmallImageList = Program.ExtendedDownloaderSelectedImages;
lvUnknownFormats.SmallImageList = Program.ExtendedDownloaderSelectedImages;
}
public frmExtendedDownloader(string URL, string CustomArguments, bool Archived) : this (URL, Archived) {
txtCustomArguments.Text = CustomArguments.IsNullEmptyWhitespace() ? string.Empty : CustomArguments;
}
public frmExtendedDownloader() {
InitializeComponent();
LoadLanguage();
Expand Down Expand Up @@ -1049,9 +1053,9 @@ private void lvUnknownFormats_SelectedIndexChanged(object sender, EventArgs e) {

private void cbSchema_KeyPress(object sender, KeyPressEventArgs e) {
switch (e.KeyChar) {
case '\\': case '/': case ':':
case '*': case '?': case '"':
case '<': case '>': case '|': {
case ':': case '*': case '?':
case '"': case '<': case '>':
case '|': {
System.Media.SystemSounds.Beep.Play();
e.Handled = true;
} break;
Expand Down
6 changes: 3 additions & 3 deletions youtube-dl-gui/Forms/frmMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 15 additions & 14 deletions youtube-dl-gui/Forms/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,10 @@ private void mSettings_Click(object sender, EventArgs e) {
}

private void mBatchDownload_Click(object sender, EventArgs e) {
frmExtendedBatchDownloader Batch = new();
Batch.Show();
//frmBatchDownloader BatchDownload = new();
//BatchDownload.Show();
//frmExtendedBatchDownloader Batch = new();
//Batch.Show();
frmBatchDownloader BatchDownload = new();
BatchDownload.Show();
}
private void mBatchConverter_Click(object sender, EventArgs e) {
frmBatchConverter BatchConvert = new();
Expand Down Expand Up @@ -862,21 +862,21 @@ private void txtUrl_KeyDown(object sender, KeyEventArgs e) {
private void txtUrl_TextChanged(object sender, EventArgs e) {
//btnMainYtdlpExtended.Enabled = txtUrl.Text.Length > 0;
}
private void txtArgs_KeyPress(object sender, KeyPressEventArgs e) {
if (e.KeyChar == 13) {
Download();
}
}
private void cbCustomArguments_KeyPress(object sender, KeyPressEventArgs e) {
private void cbSchema_KeyPress(object sender, KeyPressEventArgs e) {
switch (e.KeyChar) {
case '\\': case '/': case ':':
case '*': case '?': case '"':
case '<': case '>': case '|': {
case ':': case '*': case '?':
case '"': case '<': case '>':
case '|': {
System.Media.SystemSounds.Beep.Play();
e.Handled = true;
} break;
}
}
private void txtArgs_KeyPress(object sender, KeyPressEventArgs e) {
if (e.KeyChar == 13) {
Download();
}
}
private void sbDownload_Click(object sender, EventArgs e) {
Download();
}
Expand Down Expand Up @@ -1121,7 +1121,7 @@ private void StartDownload(bool WithAuth = false) {
}
private void StartDownloadExtended() {
if (txtUrl.Text.IsNotNullEmptyWhitespace()) {
frmExtendedDownloader Extended = new(txtUrl.Text, false);
frmExtendedDownloader Extended = new(txtUrl.Text, cbCustomArguments.Text, false);
Extended.Show();
if (Config.Settings.General.ClearURLOnDownload) {
txtUrl.Clear();
Expand Down Expand Up @@ -1358,4 +1358,5 @@ private void btnDebugCheckVerification_Click(object sender, EventArgs e) {
}

#endregion

}
Loading

0 comments on commit 9288824

Please sign in to comment.