Skip to content

Commit

Permalink
🛑 v0.7: The Cancellation Update
Browse files Browse the repository at this point in the history
- Added "Abort" button.
- Code Cleanup.
  • Loading branch information
database64128 committed May 10, 2020
1 parent e9c956f commit e8cff96
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 45 deletions.
6 changes: 3 additions & 3 deletions AboutDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Margin="8 8 8 8" Style="{StaticResource MaterialDesignHeadline5TextBlock}" TextWrapping="Wrap">About - v0.6 Build 20200510</TextBlock>
<TextBlock Grid.Row="1" Margin="8 8 8 8" Style="{StaticResource MaterialDesignSubtitle1TextBlock}" TextWrapping="Wrap">Cube YouTube Downloader is a simple GUI wrapper for <Hyperlink RequestNavigate="Hyperlink_RequestNavigate" NavigateUri="https://github.com/ytdl-org/youtube-dl">https://github.com/ytdl-org/youtube-dl</Hyperlink></TextBlock>
<TextBlock Grid.Row="2" Margin="8 8 8 8" Style="{StaticResource MaterialDesignSubtitle1TextBlock}" TextWrapping="Wrap">For more information please visit <Hyperlink RequestNavigate="Hyperlink_RequestNavigate" NavigateUri="https://github.com/database64128/youtube-dl-wpf">https://github.com/database64128/youtube-dl-wpf</Hyperlink></TextBlock>
<TextBlock Grid.Row="0" Margin="8" Style="{StaticResource MaterialDesignHeadline5TextBlock}" TextWrapping="Wrap">About - v0.7 Build 20200510</TextBlock>
<TextBlock Grid.Row="1" Margin="8" Style="{StaticResource MaterialDesignSubtitle1TextBlock}" TextWrapping="Wrap">Cube YouTube Downloader is a simple GUI wrapper for <Hyperlink RequestNavigate="Hyperlink_RequestNavigate" NavigateUri="https://github.com/ytdl-org/youtube-dl">https://github.com/ytdl-org/youtube-dl</Hyperlink></TextBlock>
<TextBlock Grid.Row="2" Margin="8" Style="{StaticResource MaterialDesignSubtitle1TextBlock}" TextWrapping="Wrap">For more information please visit <Hyperlink RequestNavigate="Hyperlink_RequestNavigate" NavigateUri="https://github.com/database64128/youtube-dl-wpf">https://github.com/database64128/youtube-dl-wpf</Hyperlink></TextBlock>
<Button Grid.Row="3"
IsDefault="True" Style="{DynamicResource MaterialDesignFlatButton}"
HorizontalAlignment="Right"
Expand Down
Binary file modified DarkMode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 38 additions & 31 deletions Home.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,46 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
d:DesignHeight="680" d:DesignWidth="960">
<Grid Margin="24,24,24,24">
d:DesignHeight="680" d:DesignWidth="960"
SizeChanged="UserControl_SizeChanged">
<Grid Margin="24">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Margin="8,8,8,8" Style="{StaticResource MaterialDesignHeadline5TextBlock}">Start your download</TextBlock>
<TextBlock Grid.Row="0" Margin="8" Style="{StaticResource MaterialDesignHeadline5TextBlock}">Start your download</TextBlock>
<StackPanel Grid.Row="1">
<StackPanel Orientation="Horizontal" >
<TextBlock Style="{StaticResource MaterialDesignSubtitle1TextBlock}" VerticalAlignment="Center" Margin="8,8,8,8">Video Link</TextBlock>
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource MaterialDesignSubtitle1TextBlock}" VerticalAlignment="Center" Margin="8">Video Link</TextBlock>
<TextBox
x:Name="linkTextBox"
materialDesign:HintAssist.Hint="e.g. https://www.youtube.com/watch?v=b2390GAm4d0"
Style="{StaticResource MaterialDesignFloatingHintTextBox}"
Margin="8,8,8,8" Width="384"
Margin="8" Width="384"
Text="{Binding Link, UpdateSourceTrigger=PropertyChanged}"/>
<Button
x:Name="downloadButton"
Margin="8,8,8,8"
Margin="8"
materialDesign:ButtonProgressAssist.IsIndicatorVisible="{Binding FreezeButton}"
materialDesign:ButtonProgressAssist.IsIndeterminate="True"
Command="{Binding StartDownload}">_Download</Button>
<Button
x:Name="listFormatsButton"
Margin="8,8,8,8"
Margin="8"
materialDesign:ButtonProgressAssist.IsIndicatorVisible="{Binding FreezeButton}"
materialDesign:ButtonProgressAssist.IsIndeterminate="True"
Style="{StaticResource MaterialDesignRaisedAccentButton}"
Command="{Binding ListFormats}">_List Formats</Button>
<Button
x:Name="abortButton"
Margin="8"
Style="{StaticResource MaterialDesignRaisedDarkButton}"
Command="{Binding AbortDl}">_Abort</Button>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource MaterialDesignSubtitle1TextBlock}" VerticalAlignment="Top" Margin="8,8,8,8">Options</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignSubtitle1TextBlock}" VerticalAlignment="Top" Margin="8">Options</TextBlock>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
Expand All @@ -47,17 +54,17 @@
<StackPanel Orientation="Horizontal">
<ToggleButton
x:Name="overrideFormatsToggle"
Margin="8,8,8,8"
Margin="8"
IsChecked="{Binding OverrideFormats}"/>
<TextBlock VerticalAlignment="Center" Margin="0,8,8,8">Override Formats</TextBlock>
<TextBlock VerticalAlignment="Center" Margin="8,8,8,8">Video Format</TextBlock>
<TextBlock VerticalAlignment="Center" Margin="8">Video Format</TextBlock>
<TextBox
x:Name="videoTextBox"
Margin="0,8,8,8"
Width="50"
IsEnabled="{Binding Path=IsChecked, ElementName=overrideFormatsToggle}"
Text="{Binding VideoFormat}"/>
<TextBlock VerticalAlignment="Center" Margin="8,8,8,8">Audio Format</TextBlock>
<TextBlock VerticalAlignment="Center" Margin="8">Audio Format</TextBlock>
<TextBox
x:Name="audioTextBox"
Margin="0,8,8,8"
Expand All @@ -68,17 +75,17 @@
<StackPanel Orientation="Horizontal" Grid.Row="1">
<ToggleButton
x:Name="metadataToggle"
Margin="8,8,8,8"
Margin="8"
IsChecked="{Binding Metadata}"/>
<TextBlock VerticalAlignment="Center" Margin="0,8,8,8">Add Metadata</TextBlock>
<ToggleButton
x:Name="thumbnailToggle"
Margin="8,8,8,8"
Margin="8"
IsChecked="{Binding Thumbnail}"/>
<TextBlock VerticalAlignment="Center" Margin="0,8,8,8">Download Thumbnail</TextBlock>
<ToggleButton
x:Name="subtitlesToggle"
Margin="8,8,8,8"
Margin="8"
IsChecked="{Binding Subtitles}"/>
<TextBlock VerticalAlignment="Center" Margin="0,8,8,8">Download Subtitles</TextBlock>
<ToggleButton
Expand All @@ -90,7 +97,7 @@
<StackPanel Orientation="Horizontal" Grid.Row="2">
<ToggleButton
x:Name="pathToggle"
Margin="8,8,8,8"
Margin="8"
IsChecked="{Binding CustomPath}"/>
<TextBlock VerticalAlignment="Center" Margin="0,8,8,8">Custom Download Path</TextBlock>
<TextBox
Expand All @@ -115,20 +122,20 @@
</Grid>
</StackPanel>
</StackPanel>
<StackPanel Grid.Row="2">
<TextBlock Margin="8,24,8,8" Style="{StaticResource MaterialDesignHeadline5TextBlock}">Results</TextBlock>
<TextBox
x:Name="resultTextBox"
Style="{StaticResource MaterialDesignOutlinedTextFieldTextBox}"
Height="240"
Margin="8,8,8,8"
TextWrapping="Wrap"
IsReadOnly="True"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto"
materialDesign:HintAssist.Hint="Output from youtube-dl"
Text="{Binding Output}"
TextChanged="resultTextBox_TextChanged"/>
</StackPanel>
<TextBlock Grid.Row="2" Margin="8,24,8,8" Style="{StaticResource MaterialDesignHeadline5TextBlock}">Results</TextBlock>
<TextBox
Grid.Row="3"
x:Name="resultTextBox"
Style="{StaticResource MaterialDesignOutlinedTextFieldTextBox}"
Height="240"
Margin="8"
TextWrapping="Wrap"
IsReadOnly="True"
VerticalAlignment="Top"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto"
materialDesign:HintAssist.Hint="Output from youtube-dl"
Text="{Binding Output}"
TextChanged="resultTextBox_TextChanged"/>
</Grid>
</UserControl>
7 changes: 7 additions & 0 deletions Home.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@ private void resultTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
resultTextBox.ScrollToEnd();
}

private void UserControl_SizeChanged(object sender, System.Windows.SizeChangedEventArgs e)
{
//resultStackPanel.MaxWidth = e.NewSize.Width - 48;
if (e.NewSize.Width > 64)
resultTextBox.MaxWidth = e.NewSize.Width - 64;
}
}
}
80 changes: 73 additions & 7 deletions HomeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Windows;
using System.Windows.Input;

namespace youtube_dl_wpf
Expand All @@ -16,6 +15,7 @@ public HomeViewModel()
_openFolder = new DelegateCommand(OnOpenFolder, CanOpenFolder);
_startDownload = new DelegateCommand(OnStartDownload, CanStartDownload);
_listFormats = new DelegateCommand(OnListFormats, CanStartDownload);
_abortDl = new DelegateCommand(OnAbortDl, (object commandParameter) => _freezeButton);

_overrideFormats = AppSettings.settings.OverrideFormats;
_videoFormat = AppSettings.settings.VideoFormat;
Expand Down Expand Up @@ -43,17 +43,20 @@ public HomeViewModel()
private bool _freezeButton = false; // true for freezing the button
private BackgroundWorker worker;
//private Thread t;
private Process dlProcess;

private readonly DelegateCommand _browseFolder;
private readonly DelegateCommand _openFolder;
private readonly DelegateCommand _startDownload;
private readonly DelegateCommand _listFormats;
private readonly DelegateCommand _abortDl;

private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
FreezeButton = false;
_startDownload.InvokeCanExecuteChanged();
_listFormats.InvokeCanExecuteChanged();
_abortDl.InvokeCanExecuteChanged();
}

private void OnBrowseFolder(object commandParameter)
Expand All @@ -64,7 +67,7 @@ private void OnBrowseFolder(object commandParameter)
folderDialog.CheckFileExists = false;
folderDialog.CheckPathExists = true;

Nullable<bool> result = folderDialog.ShowDialog();
bool? result = folderDialog.ShowDialog();

if (result == true)
{
Expand All @@ -79,9 +82,9 @@ private void OnOpenFolder(object commandParameter)
{
Process.Start("explorer.exe", _downloadPath);
}
catch (Exception e)
catch (Exception ex)
{
MessageBox.Show(e.Message);
Output = ex.Message;
}
}

Expand All @@ -92,6 +95,7 @@ private void OnStartDownload(object commandParameter)
FreezeButton = true;
_startDownload.InvokeCanExecuteChanged();
_listFormats.InvokeCanExecuteChanged();
_abortDl.InvokeCanExecuteChanged();

worker = new BackgroundWorker();
worker.DoWork += DoStartDownload;
Expand All @@ -102,8 +106,9 @@ private void OnStartDownload(object commandParameter)
private void DoStartDownload(object sender, DoWorkEventArgs e)
{
outputString = new StringBuilder();
dlProcess = new Process();

using (Process dlProcess = new Process())
try
{
dlProcess.StartInfo.FileName = AppSettings.settings.DlPath;
dlProcess.StartInfo.CreateNoWindow = true;
Expand Down Expand Up @@ -141,6 +146,10 @@ private void DoStartDownload(object sender, DoWorkEventArgs e)
{
dlProcess.StartInfo.ArgumentList.Add("--yes-playlist");
}
else
{
dlProcess.StartInfo.ArgumentList.Add("--no-playlist");
}
if (_customPath)
{
dlProcess.StartInfo.ArgumentList.Add("-o");
Expand All @@ -153,6 +162,16 @@ private void DoStartDownload(object sender, DoWorkEventArgs e)
dlProcess.BeginOutputReadLine();
dlProcess.WaitForExit();
}
catch (Exception ex)
{
outputString.Append(ex.Message);
outputString.Append(Environment.NewLine);
Output = outputString.ToString();
}
finally
{
dlProcess.Dispose();
}
}

private void OnListFormats(object commandParameter)
Expand All @@ -162,6 +181,7 @@ private void OnListFormats(object commandParameter)
FreezeButton = true;
_startDownload.InvokeCanExecuteChanged();
_listFormats.InvokeCanExecuteChanged();
_abortDl.InvokeCanExecuteChanged();

worker = new BackgroundWorker();
worker.DoWork += DoListFormats;
Expand All @@ -172,8 +192,9 @@ private void OnListFormats(object commandParameter)
private void DoListFormats(object sender, DoWorkEventArgs e)
{
outputString = new StringBuilder();
dlProcess = new Process();

using (Process dlProcess = new Process())
try
{
dlProcess.StartInfo.FileName = AppSettings.settings.DlPath;
dlProcess.StartInfo.CreateNoWindow = true;
Expand All @@ -196,6 +217,38 @@ private void DoListFormats(object sender, DoWorkEventArgs e)
dlProcess.BeginOutputReadLine();
dlProcess.WaitForExit();
}
catch (Exception ex)
{
outputString.Append(ex.Message);
outputString.Append(Environment.NewLine);
Output = outputString.ToString();
}
finally
{
dlProcess.Dispose();
}
}

private void OnAbortDl(object commandParameter)
{
try
{
// yes, I know it's bad to just kill the process.
// but currently .NET Core doesn't have an API for sending ^C or SIGTERM to a process
// see https://github.com/dotnet/runtime/issues/14628
// To implement a platform-specific solution,
// we need to use Win32 APIs.
// see https://stackoverflow.com/questions/283128/how-do-i-send-ctrlc-to-a-process-in-c
// I would prefer not to use Win32 APIs in the application.
dlProcess.Kill();
outputString.Append("🛑 Aborted.");
outputString.Append(Environment.NewLine);
Output = outputString.ToString();
}
catch (Exception ex)
{
Output = ex.Message;
}
}

private bool CanOpenFolder(object commandParameter)
Expand All @@ -215,6 +268,7 @@ private void UpdateDl()
FreezeButton = true;
_startDownload.InvokeCanExecuteChanged();
_listFormats.InvokeCanExecuteChanged();
_abortDl.InvokeCanExecuteChanged();

worker = new BackgroundWorker();
worker.DoWork += DoUpdateDl;
Expand All @@ -225,8 +279,9 @@ private void UpdateDl()
private void DoUpdateDl(object sender, DoWorkEventArgs e)
{
outputString = new StringBuilder();
dlProcess = new Process();

using (Process dlProcess = new Process())
try
{
dlProcess.StartInfo.FileName = AppSettings.settings.DlPath;
dlProcess.StartInfo.CreateNoWindow = true;
Expand All @@ -248,6 +303,16 @@ private void DoUpdateDl(object sender, DoWorkEventArgs e)
dlProcess.BeginOutputReadLine();
dlProcess.WaitForExit();
}
catch (Exception ex)
{
outputString.Append(ex.Message);
outputString.Append(Environment.NewLine);
Output = outputString.ToString();
}
finally
{
dlProcess.Dispose();
}
}

private void DlOutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
Expand All @@ -264,6 +329,7 @@ private void DlOutputHandler(object sendingProcess, DataReceivedEventArgs outLin
public ICommand OpenFolder => _openFolder;
public ICommand StartDownload => _startDownload;
public ICommand ListFormats => _listFormats;
public ICommand AbortDl => _abortDl;

public string Link
{
Expand Down
Binary file modified LightMode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ A simple GUI wrapper for [`youtube-dl`](https://github.com/ytdl-org/youtube-dl).
- Override video and audio formats.
- Toggle metadata embedding.
- Toggle thumbnail and subtitles embedding.
- Toggle downloading a single video or the whole playlist.
- Custom download path.
- Custom `ffmpeg` and `youtube-dl` path.
- Custom proxy support.

Expand Down
Loading

0 comments on commit e8cff96

Please sign in to comment.