private async void btnGetInfo_Click(object sender, RoutedEventArgs e) { string clipId = ValidateUrl(textUrl.Text); if (clipId == "") { MessageBox.Show("Please enter a valid clip ID/URL" + Environment.NewLine + "Examples:" + Environment.NewLine + "https://clips.twitch.tv/ImportantPlausibleMetalOSsloth" + Environment.NewLine + "ImportantPlausibleMetalOSsloth", "Invalid Video ID/URL", MessageBoxButton.OK, MessageBoxImage.Error); } else { try { btnGetInfo.IsEnabled = false; comboQuality.Items.Clear(); Task <JObject> taskInfo = InfoHelper.GetClipInfo(clipId); Task <JArray> taskLinks = InfoHelper.GetClipLinks(clipId); await Task.WhenAll(taskInfo, taskLinks); JToken clipData = taskInfo.Result; string thumbUrl = clipData["thumbnails"]["medium"].ToString(); Task <BitmapImage> taskThumb = InfoHelper.GetThumb(thumbUrl); await Task.WhenAll(taskThumb); imgThumbnail.Source = taskThumb.Result; textStreamer.Text = clipData["broadcaster"]["display_name"].ToString(); textCreatedAt.Text = clipData["created_at"].ToString(); textTitle.Text = clipData["title"].ToString(); foreach (var quality in taskLinks.Result[0]["data"]["clip"]["videoQualities"]) { comboQuality.Items.Add(new TwitchClip(quality["quality"].ToString(), quality["frameRate"].ToString(), quality["sourceURL"].ToString())); } comboQuality.SelectedIndex = 0; comboQuality.IsEnabled = true; btnDownload.IsEnabled = true; btnGetInfo.IsEnabled = true; } catch (Exception ex) { MessageBox.Show("Unable to get Clip information. Please double check Clip Slug and try again", "Unable to get info", MessageBoxButton.OK, MessageBoxImage.Error); AppendLog("ERROR: " + ex); btnGetInfo.IsEnabled = true; } } }
private async void btnGetInfo_Click(object sender, RoutedEventArgs e) { string id = ValidateUrl(textUrl.Text); if (id != "") { btnGetInfo.IsEnabled = false; downloadId = id; if (id.All(Char.IsDigit)) { downloadType = DownloadType.Video; } else { downloadType = DownloadType.Clip; } try { if (downloadType == DownloadType.Video) { Task <JObject> taskInfo = InfoHelper.GetVideoInfo(Int32.Parse(downloadId)); await Task.WhenAll(taskInfo); videoData = taskInfo.Result; string thumbUrl = taskInfo.Result["preview"]["medium"].ToString(); Task <BitmapImage> taskThumb = InfoHelper.GetThumb(thumbUrl); try { await taskThumb; } catch { AppendLog("ERROR: Unable to find thumbnail"); } if (!taskThumb.IsFaulted) { imgThumbnail.Source = taskThumb.Result; } textTitle.Text = taskInfo.Result["title"].ToString(); textStreamer.Text = taskInfo.Result["channel"]["display_name"].ToString(); textCreatedAt.Text = taskInfo.Result["created_at"].ToString(); streamerId = taskInfo.Result["channel"]["_id"].ToObject <int>(); SetEnabled(true, false); } else if (downloadType == DownloadType.Clip) { string clipId = downloadId; Task <JObject> taskInfo = InfoHelper.GetClipInfo(clipId); await Task.WhenAll(taskInfo); JToken clipData = taskInfo.Result; videoData = taskInfo.Result; string thumbUrl = clipData["thumbnails"]["medium"].ToString(); Task <BitmapImage> taskThumb = InfoHelper.GetThumb(thumbUrl); await Task.WhenAll(taskThumb); imgThumbnail.Source = taskThumb.Result; textStreamer.Text = clipData["broadcaster"]["display_name"].ToString(); textCreatedAt.Text = clipData["created_at"].ToString(); textTitle.Text = clipData["title"].ToString(); streamerId = clipData["broadcaster"]["id"].ToObject <int>(); SetEnabled(true, false); SetEnabled(false, true); } btnGetInfo.IsEnabled = true; } catch (Exception ex) { MessageBox.Show("Unable to get Clip/Video information. Please double check your link and try again", "Unable to get info", MessageBoxButton.OK, MessageBoxImage.Error); AppendLog("ERROR: " + ex.Message); btnGetInfo.IsEnabled = true; } } else { MessageBox.Show("Please double check the VOD/Clip link", "Unable to parse input", MessageBoxButton.OK, MessageBoxImage.Error); } }