cosmeticc
This commit is contained in:
+20
-12
@@ -5,22 +5,30 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:local="clr-namespace:WeatubeDL"
|
xmlns:local="clr-namespace:WeatubeDL"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="Weatube DL" Height="450" Width="800">
|
Title="Weatube DL" Height="450" Width="810">
|
||||||
<Grid>
|
<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">
|
<StackPanel x:Name="MainPanel">
|
||||||
<DockPanel Height="30" Margin="0, 20, 0,0">
|
<StackPanel Height="20" Background="#2F384E"></StackPanel>
|
||||||
<TextBox x:Name="Link" Width="600" TextChanged="Link_TextChanged"></TextBox>
|
<DockPanel Height="30">
|
||||||
<ComboBox Name="VideoType" Width="100">
|
<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>
|
</ComboBox>
|
||||||
<Button x:Name="AddLink" Width="100" HorizontalAlignment="Right" IsEnabled="False">
|
<Button x:Name="AddLink" Width="100" HorizontalAlignment="Right" IsEnabled="False" Background="#C1A398" HorizontalContentAlignment="Center">
|
||||||
<TextBlock>Add to queue</TextBlock>
|
<TextBlock Foreground="#2F384E" HorizontalAlignment="Center" TextAlignment="Center">Add to queue</TextBlock>
|
||||||
</Button>
|
</Button>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
<StackPanel Orientation="Horizontal" x:Name="Queue" Margin="0, 20, 0,0" Width="800" Height="50">
|
<StackPanel x:Name="SuggestedVideo" Orientation="Horizontal" Visibility="Visible" Background="#1f2433" Panel.ZIndex="-1" Margin="0,-50,0,0">
|
||||||
<Image Stretch="Fill" Name="QueueImage" Height="50" Width="88" HorizontalAlignment="Left" Margin="0, 0, 10, 0"/>
|
<Image Stretch="Fill" Name="SuggestedImage" Height="40" Width="70" HorizontalAlignment="Left" Margin="0, 0, 10, 0"/>
|
||||||
<TextBlock x:Name="QueueItem"></TextBlock>
|
<TextBlock x:Name="SuggestedItem" FontSize="16" Foreground="#B9CECD" VerticalAlignment="Center"></TextBlock>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>
|
</Border>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ using System.Windows.Navigation;
|
|||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Windows.Media.Animation;
|
||||||
|
|
||||||
namespace WeatubeDL
|
namespace WeatubeDL
|
||||||
{
|
{
|
||||||
@@ -37,26 +38,48 @@ namespace WeatubeDL
|
|||||||
if (await UserKeepsTyping()) return;
|
if (await UserKeepsTyping()) return;
|
||||||
if ((sender as TextBox).Text.Length < 1)
|
if ((sender as TextBox).Text.Length < 1)
|
||||||
{
|
{
|
||||||
|
DisableSuggestion();
|
||||||
current = null;
|
current = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var text = (sender as TextBox).Text;
|
var text = (sender as TextBox).Text;
|
||||||
|
if (current != null && current.id.Contains(YoutubeVideo.IdFromUrl(text)))
|
||||||
|
{
|
||||||
|
EnableSuggestion();
|
||||||
|
return;
|
||||||
|
}
|
||||||
var vid = new YoutubeVideo(text);
|
var vid = new YoutubeVideo(text);
|
||||||
if (await vid.Exists())
|
if (await vid.Exists())
|
||||||
{
|
{
|
||||||
current = vid;
|
current = vid;
|
||||||
while (current.name == null)
|
while (current.name == null) await Task.Delay(500);
|
||||||
{
|
EnableSuggestion();
|
||||||
await Task.Delay(500);
|
|
||||||
}
|
|
||||||
AddLink.IsEnabled = true;
|
|
||||||
QueueItem.Text = current.name;
|
|
||||||
QueueImage.Source = current.image;
|
|
||||||
}
|
}
|
||||||
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)
|
protected override void OnClosed(EventArgs e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -34,24 +34,25 @@ namespace WeatubeDL
|
|||||||
if (client != null) client.Dispose();
|
if (client != null) client.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void IdFromUrl()
|
public static string IdFromUrl(string src)
|
||||||
{
|
{
|
||||||
if (src.Contains("youtu.be/") && src.Contains("&"))
|
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("&"))
|
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()
|
private void DownloadPreview()
|
||||||
{
|
{
|
||||||
this.IdFromUrl();
|
id = IdFromUrl(src);
|
||||||
if (id == null) return;
|
if (id == null || id == " ") return;
|
||||||
client = new WebClient();
|
client = new WebClient();
|
||||||
client.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0)");
|
client.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0)");
|
||||||
client.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
|
client.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
|
||||||
imagePath = Path.GetTempPath() + "WeatubeDL/" + this.id + ".png";
|
imagePath = Path.GetTempPath() + "WeatubeDL/" + id + ".png";
|
||||||
Directory.CreateDirectory(Path.GetTempPath() + "WeatubeDL");
|
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)
|
static void Completed(object sender, AsyncCompletedEventArgs e)
|
||||||
@@ -60,12 +61,12 @@ namespace WeatubeDL
|
|||||||
}
|
}
|
||||||
public async Task<bool> Exists()
|
public async Task<bool> Exists()
|
||||||
{
|
{
|
||||||
if (id == null) return false;
|
if (id == null || client == null) return false;
|
||||||
while(client.IsBusy)
|
while(client.IsBusy)
|
||||||
{
|
{
|
||||||
await Task.Delay(100);
|
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();
|
image = new BitmapImage();
|
||||||
|
|
||||||
@@ -82,7 +83,7 @@ namespace WeatubeDL
|
|||||||
File.Delete(imagePath);
|
File.Delete(imagePath);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.GetVideoName();
|
GetVideoName();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -96,7 +97,7 @@ namespace WeatubeDL
|
|||||||
|
|
||||||
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
|
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", "");
|
RegexOptions.IgnoreCase).Groups["Title"].Value.Replace(" - YouTube", "");
|
||||||
(sender as WebClient).Dispose();
|
(sender as WebClient).Dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user