poprav ochka
This commit is contained in:
@@ -13,6 +13,7 @@ using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
|
||||
namespace WeatubeDL
|
||||
{
|
||||
@@ -50,13 +51,17 @@ namespace WeatubeDL
|
||||
}
|
||||
AddLink.IsEnabled = true;
|
||||
QueueItem.Text = current.name;
|
||||
Uri uri = new Uri(current.imagePath, UriKind.RelativeOrAbsolute);
|
||||
QueueImage.Source = BitmapFrame.Create(uri);
|
||||
QueueImage.Source = current.image;
|
||||
}
|
||||
else
|
||||
{
|
||||
AddLink.IsEnabled = false;
|
||||
}
|
||||
}
|
||||
protected override void OnClosed(EventArgs e)
|
||||
{
|
||||
base.OnClosed(e);
|
||||
Application.Current.Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.IO;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace WeatubeDL
|
||||
{
|
||||
@@ -17,6 +18,7 @@ namespace WeatubeDL
|
||||
public string id { get; private set; }
|
||||
public string[] types { get; private set; }
|
||||
public string imagePath { get; private set; }
|
||||
public BitmapImage image { get; private set; }
|
||||
public string name { get; private set; }
|
||||
private WebClient client;
|
||||
|
||||
@@ -47,7 +49,8 @@ namespace WeatubeDL
|
||||
client = new WebClient();
|
||||
client.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0)");
|
||||
client.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
|
||||
imagePath = Path.GetTempPath() + this.id + ".png";
|
||||
imagePath = Path.GetTempPath() + "WeatubeDL/" + this.id + ".png";
|
||||
Directory.CreateDirectory(Path.GetTempPath() + "WeatubeDL");
|
||||
client.DownloadFileAsync(new Uri("http://img.youtube.com/vi/" + this.id + "/mqdefault.jpg"), imagePath);
|
||||
}
|
||||
|
||||
@@ -64,14 +67,21 @@ namespace WeatubeDL
|
||||
}
|
||||
if (imagePath.Length > 1 && File.Exists(imagePath))
|
||||
{
|
||||
Bitmap img = new Bitmap(imagePath);
|
||||
if (img.Width == 120)
|
||||
image = new BitmapImage();
|
||||
|
||||
using (var stream = File.OpenRead(imagePath))
|
||||
{
|
||||
image.BeginInit();
|
||||
image.CacheOption = BitmapCacheOption.OnLoad;
|
||||
image.StreamSource = stream;
|
||||
image.EndInit();
|
||||
}
|
||||
|
||||
if (image.Width == 120)
|
||||
{
|
||||
img.Dispose();
|
||||
File.Delete(imagePath);
|
||||
return false;
|
||||
}
|
||||
img.Dispose();
|
||||
this.GetVideoName();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user