// NOTE: An excellent example of the manifestation of ingenious engineering. // Cause of this f****n mess I need to declare a f****n lot of stuff public, although it doesn't affect anything anyway. public static async Task GetCommentsAsync( string userName, TwitchVideo.UserVideos.VideoInfo videoInfo, string outputPath, ConsoleProgressBar progressBar, BlockingCollection <Tuple <StreamWriter, TwitchComment.JsonComments> > commentsPipe, CancellationToken cancellationToken) { string?nextCursor = null; string videoID = videoInfo.VideoID; string video = $"{videoID}/comments?cursor="; StreamWriter sw = new(outputPath); do { string query = video + nextCursor; try { // NOTE: Stopwatch used to determine http response time //Stopwatch stw = new(); //stw.Start(); var jsonComments = await TwitchClient.GetJsonAsync <JsonComments>(TwitchClient.RequestType.Comment, query); //stw.Stop(); //Console.WriteLine($"Done. Time: {stw.Elapsed}"); commentsPipe.Add(new Tuple <StreamWriter, JsonComments>(sw, jsonComments)); nextCursor = jsonComments.Next; int offset = Convert.ToInt32(jsonComments.Comments[^ 1].ContentOffsetSeconds);
// TODO: I need to fix thi method the same way I fixed GetVideosByUserIDs(), but I'm lazy. // Right now it can get only ~50-60 videos public static async Task <List <UserVideos> > GetVideosByVideoIDsAsync(string videoIDs) { int countVideoIDs = videoIDs.Count(c => c == ','); string query = $"id={videoIDs}"; var jsonVideos = await TwitchClient.GetJsonAsync <JsonVideosResponse>(TwitchClient.RequestType.Video, query); if (countVideoIDs != jsonVideos.Videos.Length) { Console.WriteLine($"WARNING! {countVideoIDs - jsonVideos.Videos.Length} of the specified VideoID were not found"); } var grouppedVideos = jsonVideos.Videos.GroupBy(video => video.UserName); List <UserVideos> usersVideos = new(); foreach (var userVideos in grouppedVideos) { List <UserVideos.VideoInfo> videos = new(); GetVideos(videos, userVideos); videos.Sort((b, a) => a.DurationSeconds.CompareTo(b.DurationSeconds)); usersVideos.Add(new UserVideos(userVideos.Key, videos)); } //videos.Sort((b, a) => a.DurationSeconds.CompareTo(b.DurationSeconds)); return(usersVideos); }
public static async Task <List <UserInfo> > GetUsersByNamesAsync(string[] userNames) { var logins = string.Join("&login="******"login={logins}"; var jsonUsers = (await TwitchClient.GetJsonAsync <JsonUsersResponse>(TwitchClient.RequestType.User, query)).Users; if (userNames.Length != jsonUsers.Length) { Console.WriteLine($"WARNING! {userNames.Length - jsonUsers.Length} of the specified Channel names were not found"); } List <UserInfo> users = new(userNames.Length); users.AddRange(jsonUsers.Select(jsonUser => new UserInfo(jsonUser.UserID, jsonUser.DisplayName))); return(users); }
public static async Task <List <UserVideos> > GetVideosByUserIDsAsync(List <TwitchUser.UserInfo> users, int?firstVideos) { List <UserVideos> usersVideos = new(users.Count); int amountOfVideosForUser = firstVideos ?? 20; foreach (var user in users) { List <UserVideos.VideoInfo> videos = new(); int videosLeft = amountOfVideosForUser; int first = Math.Min(videosLeft, 100); string userQ = $"user_id={user.UserID}"; string afterQ = string.Empty; string?cursor; do { string firstQ = $"&first={first}"; string query = $"{userQ}{firstQ}{afterQ}"; var jsonVideos = await TwitchClient.GetJsonAsync <JsonVideosResponse>(TwitchClient.RequestType.Video, query); GetVideos(videos, jsonVideos.Videos); videosLeft -= jsonVideos.Videos.Length; first = Math.Min(videosLeft, 100); cursor = jsonVideos.Pagination.Cursor; afterQ = $"&after={cursor}"; } while (cursor != null && first > 0); videos.Sort((b, a) => a.DurationSeconds.CompareTo(b.DurationSeconds)); usersVideos.Add(new UserVideos(user.DisplayName, videos)); } //usersVideos.Sort((b, a) => a.DurationSeconds.CompareTo(b.DurationSeconds)); return(usersVideos); }
private static async Task <string> GetNewOAuthTokenAsync() { var jsonAppOAuthToken = await TwitchClient.GetJsonAsync <JsonAppOAuthTokenResponse>(TwitchClient.RequestType.OAuthGetNew); return(jsonAppOAuthToken !.OAuthToken); }
private static async Task <bool> ValidateTokenAsync() { var jsonAppOAuthTokenValidate = await TwitchClient.GetJsonAsync <JsonAppOAuthTokenValidate>(TwitchClient.RequestType.OAuthValidate); return(jsonAppOAuthTokenValidate is not null); }