Ejemplo n.º 1
0
        private async void btnGetInfo_Click(object sender, RoutedEventArgs e)
        {
            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 <GqlClipResponse> taskInfo  = TwitchHelper.GetClipInfo(clipId);
                    Task <JArray>          taskLinks = TwitchHelper.GetClipLinks(clipId);
                    await Task.WhenAll(taskInfo, taskLinks);

                    GqlClipResponse    clipData  = taskInfo.Result;
                    string             thumbUrl  = clipData.data.clip.thumbnailURL;
                    Task <BitmapImage> taskThumb = InfoHelper.GetThumb(thumbUrl);
                    await Task.WhenAll(taskThumb);

                    imgThumbnail.Source = taskThumb.Result;
                    textStreamer.Text   = clipData.data.clip.broadcaster.displayName;
                    textCreatedAt.Text  = clipData.data.clip.createdAt.ToString();
                    currentVideoTime    = clipData.data.clip.createdAt.ToLocalTime();
                    textTitle.Text      = clipData.data.clip.title;

                    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;
                    btnQueue.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 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 <JObject> taskLinks = InfoHelper.GetClipLinks(clipId);
                    await Task.WhenAll(taskInfo, taskLinks);

                    JToken             clipData  = taskInfo.Result["data"][0];
                    string             thumbUrl  = clipData["thumbnail_url"].ToString();
                    Task <BitmapImage> taskThumb = InfoHelper.GetThumb(thumbUrl);
                    await Task.WhenAll(taskThumb);

                    imgThumbnail.Source = taskThumb.Result;
                    textStreamer.Text   = clipData["broadcaster_name"].ToString();
                    textCreatedAt.Text  = clipData["created_at"].ToString();
                    textTitle.Text      = clipData["title"].ToString();

                    foreach (var quality in taskLinks.Result["quality_options"])
                    {
                        comboQuality.Items.Add(new TwitchClip(quality["quality"].ToString(), quality["frame_rate"].ToString(), quality["source"].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.Message);
                    btnGetInfo.IsEnabled = true;
                }
            }
        }
Ejemplo n.º 3
0
        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 = TwitchHelper.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();
                        currentVideoTime   = taskInfo.Result["created_at"].ToObject <DateTime>().ToLocalTime();
                        streamerId         = taskInfo.Result["channel"]["_id"].ToObject <int>();
                        SetEnabled(true, false);
                    }
                    else if (downloadType == DownloadType.Clip)
                    {
                        string         clipId   = downloadId;
                        Task <JObject> taskInfo = TwitchHelper.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();
                        currentVideoTime    = clipData["created_at"].ToObject <DateTime>().ToLocalTime();
                        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);
            }
        }
        private async void btnGetInfo_Click(object sender, RoutedEventArgs e)
        {
            int videoId = ValidateUrl(textUrl.Text);

            if (videoId > 0)
            {
                currentVideoId = videoId;
                try
                {
                    Task <JObject> taskInfo        = TwitchHelper.GetVideoInfo(videoId);
                    Task <JObject> taskAccessToken = TwitchHelper.GetVideoToken(videoId, textOauth.Text);
                    await Task.WhenAll(taskInfo, taskAccessToken);

                    string             thumbUrl     = taskInfo.Result["preview"]["medium"].ToString();
                    Task <BitmapImage> thumbImage   = InfoHelper.GetThumb(thumbUrl);
                    Task <string[]>    taskPlaylist = TwitchHelper.GetVideoPlaylist(videoId, taskAccessToken.Result["token"].ToString(), taskAccessToken.Result["sig"].ToString());
                    await taskPlaylist;
                    try
                    {
                        await thumbImage;
                    }
                    catch
                    {
                        AppendLog("ERROR: Unable to find thumbnail");
                    }

                    comboQuality.Items.Clear();
                    videoQualties.Clear();
                    string[] playlist = taskPlaylist.Result;
                    for (int i = 0; i < playlist.Length; i++)
                    {
                        if (playlist[i].Contains("#EXT-X-MEDIA"))
                        {
                            string lastPart      = playlist[i].Substring(playlist[i].IndexOf("NAME=\"") + 6);
                            string stringQuality = lastPart.Substring(0, lastPart.IndexOf("\""));

                            if (!videoQualties.ContainsKey(stringQuality))
                            {
                                videoQualties.Add(stringQuality, playlist[i + 2]);
                                comboQuality.Items.Add(stringQuality);
                            }
                        }
                    }
                    comboQuality.SelectedIndex = 0;

                    if (!thumbImage.IsFaulted)
                    {
                        imgThumbnail.Source = thumbImage.Result;
                    }
                    TimeSpan vodLength = TimeSpan.FromSeconds(taskInfo.Result["length"].ToObject <int>());
                    textStreamer.Text  = taskInfo.Result["channel"]["display_name"].ToString();
                    textTitle.Text     = taskInfo.Result["title"].ToString();
                    textCreatedAt.Text = taskInfo.Result["created_at"].ToString();
                    numEndHour.Value   = (int)vodLength.TotalHours;
                    numEndMinute.Value = vodLength.Minutes;
                    numEndSecond.Value = vodLength.Seconds;
                    labelLength.Text   = String.Format("{0:00}:{1:00}:{2:00}", (int)vodLength.TotalHours, vodLength.Minutes, vodLength.Seconds);

                    SetEnabled(true);
                }
                catch (Exception ex)
                {
                    btnGetInfo.IsEnabled = true;
                    AppendLog("ERROR: " + ex.Message);
                    MessageBox.Show("Unable to get the video information." + Environment.NewLine + "Please make sure the video ID is correct and try again.", "Unable To Fetch Video Info", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("Please enter a valid video ID/URL" + Environment.NewLine + "Examples:" + Environment.NewLine + "https://www.twitch.tv/videos/470741744" + Environment.NewLine + "470741744", "Invalid Video ID/URL", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 5
0
        private async void btnGetInfo_Click(object sender, RoutedEventArgs e)
        {
            int videoId = ValidateUrl(textUrl.Text);

            if (videoId > 0)
            {
                currentVideoId = videoId;
                try
                {
                    Task <JObject> taskInfo        = InfoHelper.GetVideoInfo(videoId);
                    Task <JObject> taskAccessToken = InfoHelper.GetVideoToken(videoId);
                    await Task.WhenAll(taskInfo, taskAccessToken);

                    string             thumbUrl     = taskInfo.Result["data"][0]["thumbnail_url"].ToString().Replace("%{width}", 512.ToString()).Replace("%{height}", 290.ToString());
                    Task <BitmapImage> thumbImage   = InfoHelper.GetThumb(thumbUrl);
                    Task <string[]>    taskPlaylist = InfoHelper.GetVideoPlaylist(videoId, taskAccessToken.Result["token"].ToString(), taskAccessToken.Result["sig"].ToString());
                    await Task.WhenAll(thumbImage, taskPlaylist);

                    comboQuality.Items.Clear();
                    videoQualties.Clear();
                    string[] playlist = taskPlaylist.Result;
                    for (int i = 0; i < playlist.Length; i++)
                    {
                        if (playlist[i].Contains("#EXT-X-MEDIA"))
                        {
                            string lastPart      = playlist[i].Substring(playlist[i].IndexOf("NAME=\"") + 6);
                            string stringQuality = lastPart.Substring(0, lastPart.IndexOf("\""));

                            if (!videoQualties.ContainsKey(stringQuality))
                            {
                                videoQualties.Add(stringQuality, playlist[i + 2]);
                                comboQuality.Items.Add(stringQuality);
                            }
                        }
                    }
                    comboQuality.SelectedIndex = 0;

                    imgThumbnail.Source = thumbImage.Result;
                    TimeSpan vodLength = TimeSpan.Parse(Regex.Replace(taskInfo.Result["data"][0]["duration"].ToString(), @"[^\d]", ":").TrimEnd(':'));
                    textStreamer.Text  = taskInfo.Result["data"][0]["user_name"].ToString();
                    textTitle.Text     = taskInfo.Result["data"][0]["title"].ToString();
                    textCreatedAt.Text = taskInfo.Result["data"][0]["created_at"].ToString();
                    numEndHour.Value   = vodLength.Hours;
                    numEndMinute.Value = vodLength.Minutes;
                    numEndSecond.Value = vodLength.Seconds;
                    labelLength.Text   = String.Format("{0}:{1}:{2}", vodLength.Hours, vodLength.Minutes, vodLength.Seconds);

                    SetEnabled(true);
                }
                catch (Exception ex)
                {
                    btnGetInfo.IsEnabled = true;
                    AppendLog("ERROR: " + ex.Message);
                    MessageBox.Show("Unable to get the video information." + Environment.NewLine + "Please make sure the video ID is correct and try again.", "Unable To Fetch Video Info", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("Please enter a valid video ID/URL" + Environment.NewLine + "Examples:" + Environment.NewLine + "https://www.twitch.tv/videos/470741744" + Environment.NewLine + "470741744", "Invalid Video ID/URL", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        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)
                    {
                        GqlVideoResponse taskInfo = await TwitchHelper.GetVideoInfo(Int32.Parse(downloadId));

                        string             thumbUrl  = taskInfo.data.video.thumbnailURLs.FirstOrDefault();
                        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.data.video.title;
                        textStreamer.Text  = taskInfo.data.video.owner.displayName;
                        textCreatedAt.Text = taskInfo.data.video.createdAt.ToString();
                        currentVideoTime   = taskInfo.data.video.createdAt.ToLocalTime();
                        streamerId         = int.Parse(taskInfo.data.video.owner.id);
                        SetEnabled(true, false);
                    }
                    else if (downloadType == DownloadType.Clip)
                    {
                        string          clipId   = downloadId;
                        GqlClipResponse taskInfo = await TwitchHelper.GetClipInfo(clipId);

                        string             thumbUrl  = taskInfo.data.clip.thumbnailURL;
                        Task <BitmapImage> taskThumb = InfoHelper.GetThumb(thumbUrl);
                        await Task.WhenAll(taskThumb);

                        imgThumbnail.Source = taskThumb.Result;
                        textStreamer.Text   = taskInfo.data.clip.broadcaster.displayName;
                        textCreatedAt.Text  = taskInfo.data.clip.createdAt.ToString();
                        currentVideoTime    = taskInfo.data.clip.createdAt.ToLocalTime();
                        textTitle.Text      = taskInfo.data.clip.title;
                        streamerId          = int.Parse(taskInfo.data.clip.broadcaster.id);
                        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);
            }
        }