Skip to content

Commit

Permalink
[Update] 2022.10.10
Browse files Browse the repository at this point in the history
  • Loading branch information
Kannagi authored and Kannagi committed Oct 10, 2022
1 parent 1871935 commit 78cb16b
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 25 deletions.
2 changes: 1 addition & 1 deletion yt-dlp-gui/App.xaml.cs
Expand Up @@ -6,7 +6,7 @@ namespace yt_dlp_gui {
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application {
public static string CurrentVersion = "2022.10.05";
public static string CurrentVersion = "2022.10.10";
private void Application_Startup(object sender, StartupEventArgs e) {
var args = e.Args.ToList();
LoadPath();
Expand Down
3 changes: 3 additions & 0 deletions yt-dlp-gui/Controls/Icons.xaml.cs
Expand Up @@ -154,5 +154,8 @@ public enum IconKind {

[Description("M21,16H3V4H21M21,2H3C1.89,2 1,2.89 1,4V16A2,2 0 0,0 3,18H10V20H8V22H16V20H14V18H21A2,2 0 0,0 23,16V4C23,2.89 22.1,2 21,2Z")]
Monitor,

[Description("M20 18H4V8H20V18M12 6L10 4H4C2.9 4 2 4.89 2 6V18C2 19.11 2.9 20 4 20H20C21.11 20 22 19.11 22 18V8C22 6.9 21.11 6 20 6H12M11 14V12H15V9L19 13L15 17V14H11Z")]
FolderMoveOutline
}
}
11 changes: 11 additions & 0 deletions yt-dlp-gui/Libs/Util.Shell.cs
@@ -1,5 +1,7 @@
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

namespace Libs {
public partial class Util {
Expand Down Expand Up @@ -33,5 +35,14 @@ private enum CtrlTypes : uint {
}
}
/* -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ */
public static async Task Explorer(string path) {
await Task.Run(() => {
if (File.Exists(path)) {
Process.Start("explorer.exe", string.Format("/select,\"{0}\"", path));
} else if (Directory.Exists(path)) {
Process.Start("explorer.exe", string.Format("/e,\"{0}\"", path));
}
});
}
}
}
3 changes: 2 additions & 1 deletion yt-dlp-gui/Models/Cookies.cs
Expand Up @@ -2,7 +2,8 @@
public enum UseCookie {
WhenNeeded,
Never,
Always
Always,
Ask
}
public enum CookieType {
Chrome,
Expand Down
17 changes: 17 additions & 0 deletions yt-dlp-gui/ViewModels/Main.cs
Expand Up @@ -155,6 +155,14 @@ public class ViewData :INotifyPropertyChanged {
public bool IsDownload { get; set; } = false;
public bool IsAbouted { get; set; } = false;
public bool IsMonitor { get; set; } = false;
public bool AlwaysOnTop { get; set; } = false;
public bool RememberWindowStatePosition { get; set; } = false;
public bool RememberWindowStateSize { get; set; } = false;
public double Top { get; set; } = 0;
public double Left { get; set; } = 0;
public double Width { get; set; } = 600;
public double Height { get; set; } = 380;
public bool CanCancel { get; set; } = false;
public string Url { get; set; } = string.Empty;
public string CommandLine { get; set; } = string.Empty;
public bool IsPackage { get; set; } = false;
Expand Down Expand Up @@ -310,6 +318,15 @@ public class GUIConfig :IYamlConfig, INotifyPropertyChanged {
this.Save();
}
[Description("Last Browsed Folder")] public string TargetPath { get; set; } = string.Empty;
[Description("Window - Always on Top")]
public bool AlwaysOnTop { get; set; } = false;
[Description("Window - Remember State")]
public bool RememberWindowStatePosition { get; set; } = false;
public bool RememberWindowStateSize { get; set; } = false;
public double Top { get; set; } = 0;
public double Left { get; set; } = 0;
public double Width { get; set; } = 600;
public double Height { get; set; } = 380;
[Description("Use Cookie From Browser")] public UseCookie UseCookie { get; set; } = UseCookie.WhenNeeded;
public CookieType CookieType { get; set; } = CookieType.Chrome;
[Description("With Thumbnail When Downlaod")] public bool SaveThumbnail { get; set; } = true;
Expand Down
66 changes: 56 additions & 10 deletions yt-dlp-gui/Views/Main.xaml
Expand Up @@ -9,6 +9,7 @@
mc:Ignorable="d" Style="{DynamicResource WindowStyle}"
Title="yt-dlp-gui" Width="600" Height="380"
Background="{StaticResource BackgroundColour}"
Closed="Window_Closed"
Icon="pack://application:,,,/Resources/logo.ico">
<Window.CommandBindings>
<CommandBinding Command="ApplicationCommands.SaveAs" CanExecute="CommandBinding_SaveAs_CanExecute" Executed="CommandBinding_SaveAs_Executed"/>
Expand Down Expand Up @@ -38,7 +39,7 @@
<VirtualizingStackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</Menu.ItemsPanel>
<MenuItem Style="{StaticResource TopLevelMenu}" Width="40"
<MenuItem Style="{StaticResource TopLevelMenu}"
VerticalAlignment="Center" Padding="0">
<MenuItem.Icon>
<controls:Icons Kind="MenuDown" VerticalAlignment="Center" HorizontalAlignment="Center"/>
Expand Down Expand Up @@ -479,17 +480,31 @@
<RowDefinition/>
<!-- 3 -->
<RowDefinition/>
<!-- 4 -->
<RowDefinition/>
<!-- 5 -->
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="Notifications" Margin="0,5,5,5" HorizontalAlignment="Right"/>
<CheckBox Grid.Row="0" Grid.Column="1" Content="Enabled" IsEnabled="{Binding Enable.UseNotifications}" IsChecked="{Binding UseNotifications}" Margin="0,2"/>
<!--Always on Top-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ -->
<TextBlock Grid.Row="1" Text="Always on Top" Margin="0,5,5,5" HorizontalAlignment="Right"/>
<CheckBox Grid.Row="1" Grid.Column="1" Content="Enabled" IsChecked="{Binding AlwaysOnTop}" Margin="0,2"/>
<!--Potistion & Size-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ -->
<TextBlock Grid.Row="2" Text="Remember Window State" Margin="0,2,5,5" HorizontalAlignment="Right"/>
<StackPanel Grid.Row="2" Grid.Column="1" VerticalAlignment="Center">
<CheckBox Content="Position" IsChecked="{Binding RememberWindowStatePosition}"/>
<CheckBox Content="Size" IsChecked="{Binding RememberWindowStateSize}"/>
</StackPanel>
<!--UseCookie-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ -->
<TextBlock Grid.Row="1" Text="Cookie" Margin="0,5,5,5" HorizontalAlignment="Right"/>
<StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Top" Margin="0,2">
<TextBlock Grid.Row="3" Text="Cookie" Margin="0,5,5,5" HorizontalAlignment="Right"/>
<StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Top" Margin="0,2">
<!--TextBlock Text="Cookie" Margin="0,0,4,0" VerticalAlignment="Center"/-->
<ComboBox SelectedValue="{Binding UseCookie}" SelectedValuePath="Tag" IsEnabled="{Binding Enable.UseCookie}">
<ComboBoxItem Content="When Needed" Tag="{x:Static m:UseCookie.WhenNeeded}"/>
<ComboBoxItem Content="Never" Tag="{x:Static m:UseCookie.Never}"/>
<ComboBoxItem Content="Always" Tag="{x:Static m:UseCookie.Always}"/>
<ComboBoxItem Content="Ask" Tag="{x:Static m:UseCookie.Ask}"/>
</ComboBox>
<TextBlock Text="Use" Margin="4,0" VerticalAlignment="Center"/>
<ComboBox SelectedValue="{Binding CookieType}" SelectedValuePath="Tag" IsEnabled="{Binding Enable.CookieType}">
Expand All @@ -504,41 +519,72 @@
</ComboBox>
</StackPanel>
<!-- Configuration-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ -->
<TextBlock Grid.Row="2" Text="Configuration" Margin="0,5,5,5" HorizontalAlignment="Right"/>
<ComboBox Grid.Row="2" Grid.Column="1" x:Name="cc" HorizontalAlignment="Left"
<TextBlock Grid.Row="4" Text="Configuration" Margin="0,5,5,5" HorizontalAlignment="Right"/>
<ComboBox Grid.Row="4" Grid.Column="1" x:Name="cc" HorizontalAlignment="Left"
SelectedValue="{Binding selectedConfig}"
DisplayMemberPath="name"
ItemsSource="{Binding ConfigsView}"/>
<!--UseAria2-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ -->
<TextBlock Grid.Row="3" Text="Aria2" Margin="0,5,5,5" HorizontalAlignment="Right"/>
<CheckBox Grid.Row="3" Grid.Column="1" Content="Enabled" IsEnabled="{Binding Enable.UseAria2}" IsChecked="{Binding UseAria2}" Margin="0,2"/>
<TextBlock Grid.Row="5" Text="Aria2" Margin="0,5,5,5" HorizontalAlignment="Right"/>
<CheckBox Grid.Row="5" Grid.Column="1" Content="Enabled" IsEnabled="{Binding Enable.UseAria2}" IsChecked="{Binding UseAria2}" Margin="0,2"/>
</Grid>
</TabItem>
</TabControl>
<!-- -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ -->
<Grid Grid.Row="4" Grid.ColumnSpan="3">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto" SharedSizeGroup="Button"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto" SharedSizeGroup="Button"/>
</Grid.ColumnDefinitions>
<controls:TextEditor Helper="Save As..." Text="{Binding TargetDisplay}"
IsReadOnly="True" WordWrap="True" Margin="0,2"/>
<Button Grid.Column="1" IsEnabled="{Binding Enable.Browser}"
<Button Grid.Column="1" Margin="2" Cursor="Hand" Click="Button_ExplorerTarget">
<StackPanel Orientation="Horizontal" Margin="4,0">
<controls:Icons Size="14" Kind="FolderMoveOutline"/>
</StackPanel>
</Button>
<Button Grid.Column="2" IsEnabled="{Binding Enable.Browser}"
Margin="4,2,2,2" Click="Button_Browser" Cursor="Hand">
<TextBlock Margin="2,0,0,0" Text="Browse"/>
</Button>
</Grid>
<Button Grid.Column="1" IsEnabled="{Binding Enable.Download}" Margin="2" Click="Button_Download">
<Button Grid.Column="1" Margin="2" Cursor="Hand" IsEnabled="{Binding CanCancel}" Click="Button_Cancel">
<Button.Style>
<Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsDownload}" Value="False">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
<StackPanel Orientation="Horizontal" Margin="4,0">
<controls:Icons Size="14" Kind="Download" IsLoading="True"/>
<TextBlock Margin="2,0,0,0" Text="Cancel"/>
</StackPanel>
</Button>
<Button Grid.Column="1" IsEnabled="{Binding Enable.Download}" Margin="2" Click="Button_Download" Cursor="Hand">
<Button.Style>
<Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsDownload}" Value="True">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
<StackPanel Orientation="Horizontal" Margin="4,0">
<controls:Icons Size="14" Kind="Download" IsLoading="{Binding IsDownload}"/>
<TextBlock Margin="2,0,0,0" d:Text="Download" Text="{Binding ExecText}"/>
</StackPanel>
</Button>

</Grid>
<!-- -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ -->
</Grid>
Expand Down
63 changes: 52 additions & 11 deletions yt-dlp-gui/Views/Main.xaml.cs
Expand Up @@ -33,6 +33,16 @@ public partial class Main :Window {
//Load Configs
InitGUIConfig();

Topmost = Data.AlwaysOnTop;
if (Data.RememberWindowStatePosition) {
Top = Data.Top;
Left = Data.Left;
}
if (Data.RememberWindowStateSize) {
Width = Data.Width;
Height = Data.Height;
}

//Configuration Checking
InitConfiguration();

Expand Down Expand Up @@ -71,6 +81,9 @@ public partial class Main :Window {
}
//Debug.WriteLine($"Clipboard Change To: {ClipboardText}");
break;
case nameof(Data.AlwaysOnTop):
Topmost = Data.AlwaysOnTop;
break;
}
};

Expand Down Expand Up @@ -230,6 +243,16 @@ public partial class Main :Window {
if (Data.UseCookie == UseCookie.WhenNeeded) {
Data.NeedCookie = true;
GetInfo();
} else if (Data.UseCookie == UseCookie.Ask) {
var mb = System.Windows.Forms.MessageBox.Show(
"Cookies are required, Use it?\n",
"yt-dlp-gui",
MessageBoxButtons.YesNo);
if (mb == System.Windows.Forms.DialogResult.Yes) {
Data.NeedCookie = true;
GetInfo();
}
}
});
}
Expand All @@ -254,7 +277,7 @@ public partial class Main :Window {
s.Total = d_total;
s.Persent = decimal.Parse(d[3]) / d_total * 100; ;
} else {
if (decimal.TryParse(d[1].TrimEnd('%') , out decimal d_persent)) {
if (decimal.TryParse(d[1].TrimEnd('%'), out decimal d_persent)) {
s.Persent = d_persent;
}
}
Expand Down Expand Up @@ -358,7 +381,23 @@ public partial class Main :Window {
});
}
}
private void Button_ExplorerTarget(object sender, RoutedEventArgs e) {
//Debug.WriteLine(Data.TargetDisplay, "TargetDisplay");
//Debug.WriteLine(Data.TargetFile, "TargetFile");
//Debug.WriteLine(Data.TargetName, "TargetName");
//Debug.WriteLine(Data.TargetPath, "TargetPath");
Util.Explorer(Data.TargetFile);
}
private void Button_Cancel(object sender, RoutedEventArgs e) {
if (Data.IsDownload) {
Data.IsAbouted = true;
foreach (var dlp in RunningDLP) {
dlp.Close();
}
}
}
private void Button_Download(object sender, RoutedEventArgs e) {
Data.CanCancel = false;
Data.IsAbouted = false;
if (Data.IsDownload) {
Data.IsAbouted = true;
Expand All @@ -371,7 +410,7 @@ public partial class Main :Window {
//如果檔案已存在
if (File.Exists(Data.TargetFile)) {
var mb = System.Windows.Forms.MessageBox.Show(
"File Already exist. Overwrite it?\nwe",
"File Already exist. Overwrite it?\n",
"yt-dlp-gui",
MessageBoxButtons.YesNo);
overwrite = mb == System.Windows.Forms.DialogResult.Yes;
Expand Down Expand Up @@ -407,19 +446,12 @@ public partial class Main :Window {
vid = vid += "+" + Data.selectedAudio.format_id;
dlp.DownloadSections(tr);
}
/*
if (isSingle) {
dlp.DownloadFormat(vid, Data.TargetFile);
} else {
tmp_video_path = Path.Combine(App.AppPath, $"{Data.Video.id}.{vid}.{Data.selectedVideo.video_ext}");
dlp.DownloadFormat(vid, tmp_video_path);
}
*/
tmp_video_path = Path.Combine(App.AppPath, $"{Data.Video.id}.{vid}.{Data.selectedVideo.video_ext}");
dlp.DownloadFormat(vid, tmp_video_path);
dlp.Exec(std => {
//Debug.WriteLine(std, "V");
Debug.WriteLine(std, "V");
GetStatus(std, 0);
});
}));
Expand Down Expand Up @@ -458,7 +490,9 @@ public partial class Main :Window {
FFMPEG.DownloadUrl(Data.Thumbnail, thumbpath);
}
}
//WaitAll Downloads, Merger Video and Audio
Data.CanCancel = true;
Task.WaitAll(tasks.ToArray());
if (!Data.IsAbouted) {
//Download Complete
Expand Down Expand Up @@ -563,6 +597,13 @@ public partial class Main :Window {
win.Owner = GetWindow(this);
win.ShowDialog();
}

private void Window_Closed(object sender, EventArgs e) {
Data.Left = Left;
Data.Top = Top;
Data.Width = Width;
Data.Height = Height;
}
}
}

4 changes: 2 additions & 2 deletions yt-dlp-gui/Wrappers/DLP.cs
Expand Up @@ -153,14 +153,14 @@ public enum DLPError { Sign, Unsupported }
process.StartInfo = info;
process.EnableRaisingEvents = true;
process.OutputDataReceived += (s, e) => {
//Debug.WriteLine(e.Data, "STD");
Debug.WriteLine(e.Data, "STD");
if (!string.IsNullOrWhiteSpace(e.Data)) {
stdall?.Invoke(e.Data);
stdout?.Invoke(e.Data);
}
};
process.ErrorDataReceived += (s, e) => {
//Debug.WriteLine(e.Data, "ERR");
Debug.WriteLine(e.Data, "ERR");
if (!string.IsNullOrWhiteSpace(e.Data)) {
stdall?.Invoke(e.Data);
stderr?.Invoke(e.Data);
Expand Down

0 comments on commit 78cb16b

Please sign in to comment.