Skip to content

Commit

Permalink
Allow setting custom downloader args.
Browse files Browse the repository at this point in the history
Minor tweaks in FetchWindow.
  • Loading branch information
alxnull committed Jan 16, 2022
1 parent f5cf9b7 commit 19e672f
Show file tree
Hide file tree
Showing 20 changed files with 207 additions and 16 deletions.
3 changes: 3 additions & 0 deletions Vividl/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
<setting name="SmartAutomationPatternIsRegex" serializeAs="String">
<value>True</value>
</setting>
<setting name="CustomDownloaderArgs" serializeAs="String">
<value />
</setting>
</Vividl.Properties.Settings>
</userSettings>
<runtime>
Expand Down
11 changes: 11 additions & 0 deletions Vividl/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Vividl.Services;
using Vividl.ViewModel;
using YoutubeDLSharp;
using YoutubeDLSharp.Options;

namespace Vividl
{
Expand Down Expand Up @@ -119,6 +120,16 @@ public static void InitializeDownloadEngine()
ytdl.DownloadArchive = Path.Combine(Settings.Default.DownloadFolder, Settings.Default.ArchiveFilename);
}
else ytdl.DownloadArchive = null;
if (!String.IsNullOrEmpty(Settings.Default.CustomDownloaderArgs))
{
ytdl.CustomDownloadOptions = OptionSet.FromString(
Settings.Default.CustomDownloaderArgs.Split(new[] { Environment.NewLine }, StringSplitOptions.None)
);
}
else
{
ytdl.CustomDownloadOptions = null;
}
}

private void registerServices()
Expand Down
13 changes: 13 additions & 0 deletions Vividl/Helpers/ValueConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,17 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
throw new NotImplementedException();
}
}

class RemoveLineBreaksConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value.ToString().Replace(Environment.NewLine, " ");
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
2 changes: 1 addition & 1 deletion Vividl/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Border Grid.Column="1" Panel.ZIndex="1">
<notif:NotificationMessageContainer Manager="{Binding NotificationManager}"/>
<notif:NotificationMessageContainer IsTabStop="False" Manager="{Binding NotificationManager}"/>
</Border>
<DockPanel Grid.ColumnSpan="3">
<Menu DockPanel.Dock="Top">
Expand Down
6 changes: 6 additions & 0 deletions Vividl/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ private void handleOpenWindow(ShowWindowMessage msg)
playlistDataWindow.Owner = this;
dialogResult = playlistDataWindow.ShowDialog();
break;
case WindowType.CustomArgsWindow:
var customArgsWindow = new CustomArgsWindow(msg.Parameter as string);
customArgsWindow.Owner = this;
dialogResult = customArgsWindow.ShowDialog();
returnVal = customArgsWindow.ReturnValue;
break;
#else
case WindowType.VideoDataWindow:
case WindowType.PlaylistDataWindow:
Expand Down
6 changes: 6 additions & 0 deletions Vividl/Model/CustomYoutubeDL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public CustomYoutubeDL(byte maxNumberOfProcesses) : base(maxNumberOfProcesses)

public string Proxy { get; set; }

public OptionSet CustomDownloadOptions { get; set; }

// Dumb way to determine if we are likely using yt-dlp
public bool UsingYtDlp => YoutubeDLPath.Contains("yt-dlp");

Expand All @@ -29,6 +31,10 @@ protected override OptionSet GetDownloadOptions()
options.DownloadArchive = this.DownloadArchive;
options.AddMetadata = this.AddMetadata;
options.Proxy = this.Proxy;
if (this.CustomDownloadOptions != null)
{
options = options.OverrideOptions(this.CustomDownloadOptions);
}
return options;
}
}
Expand Down
27 changes: 27 additions & 0 deletions Vividl/Properties/Resources.Designer.cs

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

9 changes: 9 additions & 0 deletions Vividl/Properties/Resources.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -562,4 +562,13 @@ Um Duplikate zu erlauben, gehe zu Optionen -&gt; Einstellungen.</value>
<data name="SettingsWindow_AutomatePatternIsRegex" xml:space="preserve">
<value>Regulären Ausdruck als Filterschema verwenden</value>
</data>
<data name="CustomArgsWindow_Title" xml:space="preserve">
<value>Benutzerdefinierte Downloaderargumente</value>
</data>
<data name="CustomArgsWindow_Description" xml:space="preserve">
<value>Benutzerdefinierte Argumente in separaten Zeilen eingeben</value>
</data>
<data name="CustomArgsWindow_Warning" xml:space="preserve">
<value>WARNUNG: Gegebene Argumente werden direkt an Downloaderprozess weitergegeben. Es werden möglicherweise Optionen überschrieben, die für die korrekte Funktionsweise der Applikation nötig sind. Benutzung auf eigene Gefahr.</value>
</data>
</root>
9 changes: 9 additions & 0 deletions Vividl/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -562,4 +562,13 @@ To allow duplicates, go to Options -&gt; Settings.</value>
<data name="SettingsWindow_AutomatePatternIsRegex" xml:space="preserve">
<value>Use regular expression as URL filter pattern</value>
</data>
<data name="CustomArgsWindow_Title" xml:space="preserve">
<value>Custom Downloader Arguments</value>
</data>
<data name="CustomArgsWindow_Description" xml:space="preserve">
<value>Enter custom downloader arguments in separate lines</value>
</data>
<data name="CustomArgsWindow_Warning" xml:space="preserve">
<value>WARNING: Specified arguments are passed directly to the downloader process. They might override options required for the correct functioning of this application. Use at your own risk.</value>
</data>
</root>
12 changes: 12 additions & 0 deletions Vividl/Properties/Settings.Designer.cs

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

3 changes: 3 additions & 0 deletions Vividl/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,8 @@
<Setting Name="SmartAutomationPatternIsRegex" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="CustomDownloaderArgs" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>
38 changes: 38 additions & 0 deletions Vividl/View/CustomArgsWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<adonisControls:AdonisWindow x:Class="Vividl.View.CustomArgsWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI"
xmlns:adonisControls="clr-namespace:AdonisUI.Controls;assembly=AdonisUI"
xmlns:adonisExtensions="clr-namespace:AdonisUI.Extensions;assembly=AdonisUI"
xmlns:lex="http://wpflocalizeextension.codeplex.com"
lex:LocalizeDictionary.DesignCulture="en"
lex:ResxLocalizationProvider.DefaultAssembly="Vividl"
lex:ResxLocalizationProvider.DefaultDictionary="Resources"
Title="{lex:Loc CustomArgsWindow_Title}"
Width="350" Height="350"
WindowStartupLocation="CenterOwner" ShowInTaskbar="False">
<Window.Style>
<Style TargetType="Window" BasedOn="{StaticResource {x:Type Window}}"/>
</Window.Style>
<DockPanel>
<DockPanel Margin="4" DockPanel.Dock="Bottom" LastChildFill="False">
<Button Content="{lex:Loc Cancel}" TabIndex="2"
DockPanel.Dock="Right" MinWidth="80"
IsCancel="True"/>
<Button Content="{lex:Loc Submit}" TabIndex="1"
DockPanel.Dock="Right" MinWidth="80"
Click="Submit_Click" IsDefault="True"/>
</DockPanel>
<StackPanel DockPanel.Dock="Top">
<TextBlock Text="{lex:Loc CustomArgsWindow_Description}"
Margin="8"/>
<TextBlock Text="{lex:Loc CustomArgsWindow_Warning}"
TextWrapping="Wrap"
Foreground="{DynamicResource {x:Static adonisUi:Brushes.AccentBrush}}"
Margin="8,0,8,8"/>
</StackPanel>
<TextBox x:Name="txtArgs" AcceptsReturn="True" TabIndex="0"
VerticalScrollBarVisibility="Auto"
adonisExtensions:CursorSpotlightExtension.RelativeSpotlightSize="0"/>
</DockPanel>
</adonisControls:AdonisWindow>
24 changes: 24 additions & 0 deletions Vividl/View/CustomArgsWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Windows;
using AdonisUI.Controls;

namespace Vividl.View
{
public partial class CustomArgsWindow : AdonisWindow
{
public CustomArgsWindow(string args)
{
InitializeComponent();
txtArgs.Text = args;
}

public object ReturnValue { get; set; }

private void Submit_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
this.ReturnValue = txtArgs.Text;
this.Close();
}
}
}
24 changes: 11 additions & 13 deletions Vividl/View/FetchWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,29 @@
</Window.Style>
<DockPanel>
<DockPanel Margin="4" DockPanel.Dock="Bottom" LastChildFill="False">
<Button Content="{lex:Loc Cancel}"
<Button Padding="4,2" Command="{Binding SettingsCommand}" TabIndex="2">
<StackPanel Orientation="Horizontal">
<icon:PackIconModern Kind="Cog" Margin="0,0,4,0" VerticalAlignment="Center"/>
<TextBlock Text="{lex:Loc FetchWindow_Settings}" Margin="4,2"/>
</StackPanel>
</Button>
<Button Content="{lex:Loc Cancel}" TabIndex="4"
DockPanel.Dock="Right" MinWidth="80"
IsCancel="True"/>
<Button Content="{lex:Loc Submit}"
DockPanel.Dock="Right" MinWidth="80"
Click="Submit_Click"/>
DockPanel.Dock="Right" MinWidth="80" TabIndex="3"
Click="Submit_Click" IsDefault="True"/>
</DockPanel>
<StackPanel>
<TextBlock Text="{lex:Loc FetchWindow_EnterUrls}"
Margin="8"/>
<Grid>
<TextBox x:Name="txtUrl" AcceptsReturn="True" Height="90"
<TextBox x:Name="txtUrl" AcceptsReturn="True" Height="90" TabIndex="0"
Text="{Binding VideoUrls, Converter={StaticResource arrayToString}}"
VerticalScrollBarVisibility="Auto"
adonisExtensions:CursorSpotlightExtension.RelativeSpotlightSize="0"/>
</Grid>
<Expander Header="{lex:Loc FetchWindow_Options}" Margin="0,2">
<Expander Header="{lex:Loc FetchWindow_Options}" Margin="0,2" TabIndex="1" KeyboardNavigation.TabNavigation="Local">
<TabControl Margin="0,2,0,0" Height="170">
<TabControl.Resources>
<Style TargetType="CheckBox" BasedOn="{StaticResource {x:Type CheckBox}}">
Expand Down Expand Up @@ -71,14 +77,6 @@
IsChecked="{Binding OverrideOptions.YesPlaylist}"/>
<CheckBox Content="{lex:Loc FetchWindow_ImmediateDownload}"
IsChecked="{Binding ImmediateDownload}"/>
<StackPanel Orientation="Horizontal">
<Button Padding="4,2" Command="{Binding SettingsCommand}">
<StackPanel Orientation="Horizontal">
<icon:PackIconModern Kind="Cog" Margin="0,0,4,0" VerticalAlignment="Center"/>
<TextBlock Text="{lex:Loc FetchWindow_Settings}" Margin="4,2"/>
</StackPanel>
</Button>
</StackPanel>
</StackPanel>
</TabItem>
<TabItem Header="{lex:Loc FetchWindow_TabAuthentication}">
Expand Down
1 change: 1 addition & 0 deletions Vividl/View/GeneralResources.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<local:ResTextConverter x:Key="resConv"/>
<local:DownloadOptionIconConverter x:Key="iconConv"/>
<local:ValueGreaterEqualConverter x:Key="greaterEqual"/>
<local:RemoveLineBreaksConverter x:Key="removeLineBreaks"/>
<!-- Control styling -->
<Style TargetType="Menu" BasedOn="{StaticResource {x:Type Menu}}">
<Setter Property="Background" Value="{DynamicResource {x:Static adonisUi:Brushes.Layer1BackgroundBrush}}"/>
Expand Down
8 changes: 8 additions & 0 deletions Vividl/View/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@
IsChecked="{Binding Settings.SmartAutomationPatternIsRegex, Mode=TwoWay, UpdateSourceTrigger=Explicit}"/>
</StackPanel>
</GroupBox>
<GroupBox Header="{lex:Loc CustomArgsWindow_Title}">
<DockPanel>
<Button DockPanel.Dock="Right" Content="{lex:Loc PathSelectionControl_Change}"
Command="{Binding EditCustomArgsCommand}"/>
<TextBox IsReadOnly="True" Margin="4"
Text="{Binding Settings.CustomDownloaderArgs, Mode=OneWay, Converter={StaticResource removeLineBreaks}}"/>
</DockPanel>
</GroupBox>
</StackPanel>
</TabItem>
<TabItem Header="{lex:Loc SettingsWindow_Binaries}">
Expand Down
2 changes: 1 addition & 1 deletion Vividl/ViewModel/FetchViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public FetchViewModel()
OverrideOptions = new OptionSet();
SelectedDownloadOption = Settings.Default.DefaultFormat;
SettingsCommand = new RelayCommand(
() => Messenger.Default.Send(new ShowWindowMessage(WindowType.SettingsWindow))
() => Messenger.Default.Send(new ShowWindowMessage(WindowType.SettingsWindow, 0))
);
}
}
Expand Down
15 changes: 15 additions & 0 deletions Vividl/ViewModel/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.CommandWpf;
using GalaSoft.MvvmLight.Ioc;
using GalaSoft.MvvmLight.Messaging;
using Vividl.Model;
using Vividl.Properties;
using Vividl.Services;
Expand All @@ -25,6 +26,7 @@ public class SettingsViewModel : ViewModelBase
public ObservableCollection<IDownloadOption> DefaultFormats { get; }

public ICommand SwitchAppThemeCommand { get; }
public ICommand EditCustomArgsCommand { get; }

public ILibUpdateService YoutubeDLUpdateService { get; }
public ICommand UpdateVividlCommand { get; }
Expand All @@ -41,10 +43,23 @@ public SettingsViewModel(IFileService fileService, IDialogService dialogService,
this.YoutubeDLUpdateService = ytdlUpdateService;
DefaultFormats = new ObservableCollection<IDownloadOption>(optionProvider.CreateDownloadOptions());
SwitchAppThemeCommand = new RelayCommand(() => SwitchAppTheme());
EditCustomArgsCommand = new RelayCommand(
() => Messenger.Default.Send(
new ShowWindowMessage(WindowType.CustomArgsWindow, parameter: Settings.Default.CustomDownloaderArgs, callback: editCustomArgsCallback)
)
);
UpdateVividlCommand = new RelayCommand(() => UpdateVividl());
UpdateYoutubeDLCommand = new RelayCommand(async () => await UpdateYoutubeDL());
}

private void editCustomArgsCallback(bool? dialogResult, object param)
{
if (dialogResult.GetValueOrDefault())
{
Settings.Default.CustomDownloaderArgs = param.ToString();
}
}

public void SwitchAppTheme()
=> themeResolver.SetColorScheme(Settings.Default.AppTheme);

Expand Down
3 changes: 2 additions & 1 deletion Vividl/ViewModel/ShowWindowMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public enum WindowType
SettingsWindow,
FetchWindow,
DownloadOutputWindow,
FormatSelectionWindow
FormatSelectionWindow,
CustomArgsWindow
}


Expand Down
Loading

0 comments on commit 19e672f

Please sign in to comment.