public static async Task <GqlVideoSearchResponse> GetGqlVideos(string channelName, string cursor = "", int limit = 50) { using (WebClient client = new WebClient()) { client.Encoding = Encoding.UTF8; client.Headers.Add("Client-ID", "kimne78kx3ncx6brgo4mv6wki5h1ko"); client.Headers[HttpRequestHeader.ContentType] = "application/json"; string response = await client.UploadStringTaskAsync("https://gql.twitch.tv/gql", "{\"query\":\"query{user(login:\\\"" + channelName + "\\\"){videos(first: " + limit + "" + (cursor == "" ? "" : ",after:\\\"" + cursor + "\\\"") + ") { edges { node { title, id, lengthSeconds, previewThumbnailURL(height: 180, width: 320), createdAt, viewCount }, cursor }, pageInfo { hasNextPage, hasPreviousPage }, totalCount }}}\",\"variables\":{}}"); GqlVideoSearchResponse result = JsonConvert.DeserializeObject <GqlVideoSearchResponse>(response); return(result); } }
private async Task UpdateList() { if (type == DownloadType.Video) { string currentCursor = ""; if (cursorList.Count > 0 && cursorIndex >= 0) { currentCursor = cursorList[cursorIndex]; } GqlVideoSearchResponse res = await TwitchHelper.GetGqlVideos(currnetChannel, currentCursor, 100); videoList.Clear(); if (res.data.user != null) { foreach (var video in res.data.user.videos.edges) { TaskData data = new TaskData(); data.Title = video.node.title; data.Length = video.node.lengthSeconds; data.Id = video.node.id; data.Time = video.node.createdAt; data.Views = video.node.viewCount; data.Streamer = currnetChannel; try { var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.UriSource = new Uri(video.node.previewThumbnailURL); bitmapImage.EndInit(); data.Thumbnail = bitmapImage; } catch { } videoList.Add(data); } if (res.data.user.videos.pageInfo.hasNextPage) { btnNext.IsEnabled = true; } else { btnNext.IsEnabled = false; } if (res.data.user.videos.pageInfo.hasPreviousPage) { btnPrev.IsEnabled = true; } else { btnPrev.IsEnabled = false; } if (res.data.user.videos.pageInfo.hasNextPage) { string newCursor = res.data.user.videos.edges[0].cursor; if (!cursorList.Contains(newCursor)) { cursorList.Add(newCursor); } } } } else { string currentCursor = ""; if (cursorList.Count > 0 && cursorIndex >= 0) { currentCursor = cursorList[cursorIndex]; } GqlClipSearchResponse res = await TwitchHelper.GetGqlClips(currnetChannel, period, currentCursor, 50); videoList.Clear(); if (res.data.user != null) { foreach (var clip in res.data.user.clips.edges) { TaskData data = new TaskData(); data.Title = clip.node.title; data.Length = clip.node.durationSeconds; data.Id = clip.node.slug; data.Time = clip.node.createdAt; data.Views = clip.node.viewCount; data.Streamer = currnetChannel; try { var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.UriSource = new Uri(clip.node.thumbnailURL); bitmapImage.EndInit(); data.Thumbnail = bitmapImage; } catch { } videoList.Add(data); } if (res.data.user.clips.pageInfo.hasNextPage) { btnNext.IsEnabled = true; } else { btnNext.IsEnabled = false; } if (cursorIndex >= 0) { btnPrev.IsEnabled = true; } else { btnPrev.IsEnabled = false; } if (res.data.user.clips.pageInfo.hasNextPage) { string newCursor = res.data.user.clips.edges.Where(x => x.cursor != null).First().cursor; if (!cursorList.Contains(newCursor)) { cursorList.Add(newCursor); } } } } }