cosmeticc

This commit is contained in:
2021-07-12 20:58:15 +03:00
parent 308139972a
commit a4c40c31d4
3 changed files with 64 additions and 32 deletions
+20 -12
View File
@@ -5,22 +5,30 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WeatubeDL"
mc:Ignorable="d"
Title="Weatube DL" Height="450" Width="800">
<Grid>
Title="Weatube DL" Height="450" Width="810">
<Window.Resources>
<Storyboard x:Key="ShowSuggested">
<ThicknessAnimation Storyboard.TargetProperty="Margin" From="0,-50,0,0" To="0,0,0,0" DecelerationRatio="0.9" Duration="0:0:0.3"/>
</Storyboard>
<Storyboard x:Key="HideSuggested">
<ThicknessAnimation Storyboard.TargetProperty="Margin" From="0,0,0,0" To="0,-50,0,0" DecelerationRatio="0.9" Duration="0:0:0.3"/>
</Storyboard>
</Window.Resources>
<Border HorizontalAlignment="Center" Background="#2F384E">
<StackPanel x:Name="MainPanel">
<DockPanel Height="30" Margin="0, 20, 0,0">
<TextBox x:Name="Link" Width="600" TextChanged="Link_TextChanged"></TextBox>
<ComboBox Name="VideoType" Width="100">
<StackPanel Height="20" Background="#2F384E"></StackPanel>
<DockPanel Height="30">
<TextBox x:Name="Link" Width="600" TextChanged="Link_TextChanged" Background="#33606E" Foreground="#B9CECD" VerticalContentAlignment="Center"></TextBox>
<ComboBox Name="VideoType" Width="100" Background="#C1A398" Foreground="#2F384E">
</ComboBox>
<Button x:Name="AddLink" Width="100" HorizontalAlignment="Right" IsEnabled="False">
<TextBlock>Add to queue</TextBlock>
<Button x:Name="AddLink" Width="100" HorizontalAlignment="Right" IsEnabled="False" Background="#C1A398" HorizontalContentAlignment="Center">
<TextBlock Foreground="#2F384E" HorizontalAlignment="Center" TextAlignment="Center">Add to queue</TextBlock>
</Button>
</DockPanel>
<StackPanel Orientation="Horizontal" x:Name="Queue" Margin="0, 20, 0,0" Width="800" Height="50">
<Image Stretch="Fill" Name="QueueImage" Height="50" Width="88" HorizontalAlignment="Left" Margin="0, 0, 10, 0"/>
<TextBlock x:Name="QueueItem"></TextBlock>
<StackPanel x:Name="SuggestedVideo" Orientation="Horizontal" Visibility="Visible" Background="#1f2433" Panel.ZIndex="-1" Margin="0,-50,0,0">
<Image Stretch="Fill" Name="SuggestedImage" Height="40" Width="70" HorizontalAlignment="Left" Margin="0, 0, 10, 0"/>
<TextBlock x:Name="SuggestedItem" FontSize="16" Foreground="#B9CECD" VerticalAlignment="Center"></TextBlock>
</StackPanel>
</StackPanel>
</Grid>
</Border>
</Window>
+32 -9
View File
@@ -14,6 +14,7 @@ using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Net;
using System.IO;
using System.Windows.Media.Animation;
namespace WeatubeDL
{
@@ -37,26 +38,48 @@ namespace WeatubeDL
if (await UserKeepsTyping()) return;
if ((sender as TextBox).Text.Length < 1)
{
DisableSuggestion();
current = null;
return;
}
var text = (sender as TextBox).Text;
if (current != null && current.id.Contains(YoutubeVideo.IdFromUrl(text)))
{
EnableSuggestion();
return;
}
var vid = new YoutubeVideo(text);
if (await vid.Exists())
{
current = vid;
while (current.name == null)
{
await Task.Delay(500);
}
AddLink.IsEnabled = true;
QueueItem.Text = current.name;
QueueImage.Source = current.image;
while (current.name == null) await Task.Delay(500);
EnableSuggestion();
}
else
else DisableSuggestion();
}
public void EnableSuggestion()
{
AddLink.IsEnabled = true;
if (SuggestedVideo.Margin.Top < 0)
{
AddLink.IsEnabled = false;
Storyboard sb = Resources["ShowSuggested"] as Storyboard;
sb.Begin(SuggestedVideo);
}
SuggestedItem.Text = current.name;
SuggestedImage.Source = current.image;
}
public void DisableSuggestion()
{
AddLink.IsEnabled = false;
if (SuggestedVideo.Margin.Top == 0)
{
Storyboard sb = Resources["HideSuggested"] as Storyboard;
sb.Begin(SuggestedVideo);
}
SuggestedItem.Text = null;
SuggestedImage.Source = null;
}
protected override void OnClosed(EventArgs e)
{
+12 -11
View File
@@ -34,24 +34,25 @@ namespace WeatubeDL
if (client != null) client.Dispose();
}
private void IdFromUrl()
public static string IdFromUrl(string src)
{
if (src.Contains("youtu.be/") && src.Contains("&"))
this.id = src.Replace("/youtu.be/", "").Split('/')[1].Split('&')[0];
return src.Replace("/youtu.be/", "").Split('/')[1].Split('&')[0];
else if (src.Contains("youtube.com/watch?v=") && src.Contains("&"))
this.id = src.Split('=')[1].Split('&')[0];
return src.Split('=')[1].Split('&')[0];
return " ";
}
private void DownloadPreview()
{
this.IdFromUrl();
if (id == null) return;
id = IdFromUrl(src);
if (id == null || id == " ") return;
client = new WebClient();
client.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0)");
client.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
imagePath = Path.GetTempPath() + "WeatubeDL/" + this.id + ".png";
imagePath = Path.GetTempPath() + "WeatubeDL/" + id + ".png";
Directory.CreateDirectory(Path.GetTempPath() + "WeatubeDL");
client.DownloadFileAsync(new Uri("http://img.youtube.com/vi/" + this.id + "/mqdefault.jpg"), imagePath);
client.DownloadFileAsync(new Uri("http://img.youtube.com/vi/" + id + "/mqdefault.jpg"), imagePath);
}
static void Completed(object sender, AsyncCompletedEventArgs e)
@@ -60,12 +61,12 @@ namespace WeatubeDL
}
public async Task<bool> Exists()
{
if (id == null) return false;
if (id == null || client == null) return false;
while(client.IsBusy)
{
await Task.Delay(100);
}
if (id.Length > 1 && File.Exists(imagePath))
if (id.Length > 2 && File.Exists(imagePath) && new FileInfo(imagePath).Length > 0)
{
image = new BitmapImage();
@@ -82,7 +83,7 @@ namespace WeatubeDL
File.Delete(imagePath);
return false;
}
this.GetVideoName();
GetVideoName();
return true;
}
return false;
@@ -96,7 +97,7 @@ namespace WeatubeDL
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
this.name = Regex.Match(e.Result, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>",
name = Regex.Match(e.Result, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>",
RegexOptions.IgnoreCase).Groups["Title"].Value.Replace(" - YouTube", "");
(sender as WebClient).Dispose();
}