Skip to content
This repository was archived by the owner on Jan 19, 2022. It is now read-only.

Commit a1a008d

Browse files
committed
Fixes thumbnail retrieval
1 parent f8d25dd commit a1a008d

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

WPFMETRO/MainWindow.xaml.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private async void SelectButton_Click(object sender, RoutedEventArgs e)
154154
await Task.Run(() => formats=queue.GetFormats(Url));
155155
await Task.Run(() => videoInfo = queue.GetInfo(Url));
156156

157-
if (formats.Count > 0)
157+
if (formats.Count > 0)
158158
{
159159
FiletypeBox.IsEnabled = AddToQueueButton.IsEnabled = true;
160160
UrlBox.Background = Brushes.DarkGreen;
@@ -246,8 +246,8 @@ private async void AddFromTextButton_Click(object sender, RoutedEventArgs e)
246246
string filename = "%(title)s.%(ext)s";
247247
string path = PathBox.Text + "/";
248248
string filetype = "default";
249-
string title = videoInfo[0];
250-
string thumbURL = videoInfo[1] == "N.A" ? null : videoInfo[1];
249+
string title = videoInfo[0] ?? "N.A.";
250+
string thumbURL = videoInfo[1];
251251
formats.Add("default", "default (mp4)");
252252

253253
foreach (string video in videos)
@@ -283,10 +283,13 @@ public void UpdateCard()
283283

284284
if (video.ThumbURL != null)
285285
{
286-
image.BeginInit();
287-
image.UriSource = new Uri(video.ThumbURL);
288-
image.DecodePixelWidth = 600;
289-
image.EndInit();
286+
var imageData = new WebClient().DownloadData(new Uri(video.ThumbURL + ".jpg"));
287+
var bitmapImage = new BitmapImage { CacheOption = BitmapCacheOption.OnLoad };
288+
bitmapImage.BeginInit();
289+
bitmapImage.StreamSource = new MemoryStream(imageData);
290+
bitmapImage.EndInit();
291+
292+
image = bitmapImage;
290293
}
291294
else
292295
{

WPFMETRO/Queue.cs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,24 @@ public List<string> GetInfo(string url)
4444
{
4545
string[] args = { "--encoding utf-8 --skip-download --get-title --no-warnings " + url, "--encoding utf-8 --skip-download --list-thumbnails --no-warnings " + url };
4646
List<string> response = new List<string>();
47-
string info = "N.A.";
4847
bool isThumb = false;
4948
bool isNext = false;
5049

5150
foreach (string argument in args)
5251
{
5352
ytbDLInfo.Arguments = argument;
5453
ytbDL = Process.Start(ytbDLInfo);
54+
string info = null;
5555

5656
ytbDL.OutputDataReceived += new DataReceivedEventHandler(
5757
(s, f) =>
5858
{
5959
string output = f.Data ?? "null";
6060
if (isThumb)
6161
{
62-
if(isNext)
62+
if(isNext && info == null)
6363
{
64-
info = output == "null" ? info : output.Substring(output.LastIndexOf(' ')+1);
64+
info = output == "null" || output.Contains("No thumbnail") ? info : output.Substring(output.LastIndexOf(' ')+1);
6565
}
6666
else
6767
{
@@ -218,8 +218,14 @@ public void DownloadChannel(string ID, string filename, string path, string file
218218

219219
}
220220

221-
public void ModifyQueue(string title, string thumbURL, string ID, string filename, string path, string filetype, Dictionary<string, string> formats)
221+
public void ModifyQueue(string title, string thumbURL, string ID, string filename, string path, string filetype, Dictionary<string, string> formats)
222222
{
223+
if(filetype == null)
224+
{
225+
MessageBox.Show("Please select a filetype");
226+
return;
227+
}
228+
223229
string fullpath = filename == "%(title)s.%(ext)s" ? path + title + "." + formats[filetype] : path + filename + "." + formats[filetype];
224230
if (File.Exists(fullpath))
225231
{
@@ -245,16 +251,16 @@ public void ModifyQueue(string title, string thumbURL, string ID, string filenam
245251
}
246252
else
247253
{
248-
Video video = new Video();
249-
video.ID = ID;
250-
video.Name = filename;
251-
video.Path = path;
252-
video.SelectedFormat = filetype;
253-
video.ThumbURL = thumbURL;
254-
video.Title = title;
255-
video.AvailableFormats = formats.ToList();
256-
257-
Videos.Add(video);
254+
Video video = new Video();
255+
video.ID = ID;
256+
video.Name = filename;
257+
video.Path = path;
258+
video.SelectedFormat = filetype;
259+
video.ThumbURL = thumbURL;
260+
video.Title = title;
261+
video.AvailableFormats = formats.ToList();
262+
263+
Videos.Add(video);
258264
}
259265
}
260266
else
@@ -264,7 +270,6 @@ public void ModifyQueue(string title, string thumbURL, string ID, string filenam
264270
case 0:
265271
throw new QueueException(Localization.Strings.InvalidURL);
266272
default:
267-
268273
Video videoNonYoutube = new Video();
269274
videoNonYoutube.ID = ID;
270275
videoNonYoutube.Name = filename;
@@ -278,7 +283,6 @@ public void ModifyQueue(string title, string thumbURL, string ID, string filenam
278283
break;
279284
}
280285
}
281-
282286
}
283287
}
284288
}

0 commit comments

Comments
 (0)