poprav ochka
This commit is contained in:
@@ -13,6 +13,7 @@ using System.Windows.Media.Imaging;
|
|||||||
using System.Windows.Navigation;
|
using System.Windows.Navigation;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace WeatubeDL
|
namespace WeatubeDL
|
||||||
{
|
{
|
||||||
@@ -50,13 +51,17 @@ namespace WeatubeDL
|
|||||||
}
|
}
|
||||||
AddLink.IsEnabled = true;
|
AddLink.IsEnabled = true;
|
||||||
QueueItem.Text = current.name;
|
QueueItem.Text = current.name;
|
||||||
Uri uri = new Uri(current.imagePath, UriKind.RelativeOrAbsolute);
|
QueueImage.Source = current.image;
|
||||||
QueueImage.Source = BitmapFrame.Create(uri);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AddLink.IsEnabled = false;
|
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.ComponentModel;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
|
||||||
namespace WeatubeDL
|
namespace WeatubeDL
|
||||||
{
|
{
|
||||||
@@ -17,6 +18,7 @@ namespace WeatubeDL
|
|||||||
public string id { get; private set; }
|
public string id { get; private set; }
|
||||||
public string[] types { get; private set; }
|
public string[] types { get; private set; }
|
||||||
public string imagePath { get; private set; }
|
public string imagePath { get; private set; }
|
||||||
|
public BitmapImage image { get; private set; }
|
||||||
public string name { get; private set; }
|
public string name { get; private set; }
|
||||||
private WebClient client;
|
private WebClient client;
|
||||||
|
|
||||||
@@ -47,7 +49,8 @@ namespace WeatubeDL
|
|||||||
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() + 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);
|
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))
|
if (imagePath.Length > 1 && File.Exists(imagePath))
|
||||||
{
|
{
|
||||||
Bitmap img = new Bitmap(imagePath);
|
image = new BitmapImage();
|
||||||
if (img.Width == 120)
|
|
||||||
|
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);
|
File.Delete(imagePath);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
img.Dispose();
|
|
||||||
this.GetVideoName();
|
this.GetVideoName();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user