public async Task UploadClipAsync(string FilePath, BroadcasterInfo Info = null, string Title = null, string Privacy = null, IEnumerable <string> Tags = null, string Description = null, DateTimeOffset?PublishAtUtc = null) { try { Title ??= Path.GetFileNameWithoutExtension(FilePath); Privacy ??= PrivacyStatus.Private; LogUtil.Log($"Uploading {FilePath}\n{Title}"); var youtubeService = BuildService(await BuildCredential(YouTubeService.Scope.YoutubeUpload)); var video = new Video(); video.Snippet = new VideoSnippet(); video.Snippet.Title = Title; video.Snippet.Description = "\n" + Description ?? $"\nFollow {Info.broadcaster_name ?? "the streamer"}! Twitch.tv/{Info.broadcaster_name}"; video.Snippet.Tags = Tags?.ToArray() ?? new[] { "clip", Info.broadcaster_name, Info.broadcaster_language, Info.game_name }; video.Snippet.CategoryId = "22"; video.Status = new VideoStatus(); video.Status.PrivacyStatus = Privacy; video.Status.PublishAt = PublishAtUtc.HasValue ? PublishAtUtc.Value.ToString("yyyy-MM-ddTHH:mm:ss.000zzz") : JsonConvert.SerializeObject(DateTime.UtcNow.AddMinutes(5)); var filePath = FilePath; using (var fileStream = new FileStream(filePath, FileMode.Open)) { var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*"); videosInsertRequest.ResponseReceived += VideosInsertRequest_ResponseReceived; var Res = await videosInsertRequest.UploadAsync(); } } catch (Exception ex) { LogUtil.Log(ex); } }
public bool Run(DrakeBot bot, OnChatCommandReceivedArgs e) { BroadcasterInfo broadcaster = bot.ChannelBroadcaster[e.Command.ChatMessage.Channel]; if (!bot.HasPermission(e.Command.ChatMessage.UserId, e.Command.ChatMessage.Channel, perms[0])) { return(false); } Clip retrieved = null; if (e.Command.ArgumentsAsList.Count > 0) { string arg = e.Command.ArgumentsAsList[0]; if (arg.StartsWith("https://clips.twitch.tv/")) { arg = arg.Substring(24); } var split = arg.Split('/'); for (int i = 0; i < split.Length; i++) { if (split[i] != string.Empty) { arg = split[i]; break; } } var getClip = bot.Service.Helix.Clips.GetClipAsync(arg); getClip.Wait(); if (getClip.Result.Clips.Length == 0) { bot.Client.SendMessage(e.Command.ChatMessage.Channel, "@" + e.Command.ChatMessage.Username + " your clip had an invalid id/url"); return(true); } retrieved = getClip.Result.Clips[0]; bot.Client.SendMessage(e.Command.ChatMessage.Channel, "@" + e.Command.ChatMessage.Username + " your clip was retrieved ( " + "https://clips.twitch.tv/" + arg + " )"); } else { var task = bot.Service.Helix.Clips.CreateClipAsync(broadcaster.ID, broadcaster.AccessToken); task.Wait(); var result = task.Result; var clip = result.CreatedClips[0]; bot.Client.SendMessage(e.Command.ChatMessage.Channel, "@" + e.Command.ChatMessage.Username + " your clip was created and is available at https://clips.twitch.tv/" + result.CreatedClips[0].Id); var getClip = bot.Service.Helix.Clips.GetClipAsync(result.CreatedClips[0].Id); getClip.Wait(); while (getClip.Result.Clips.Length == 0) { Thread.Sleep(1000); getClip = bot.Service.Helix.Clips.GetClipAsync(result.CreatedClips[0].Id); getClip.Wait(); } retrieved = getClip.Result.Clips[0]; } var getGame = bot.Service.Helix.Games.GetGamesAsync(new List <string>(new[] { retrieved.GameId })); getGame.Wait(); string game = getGame.Result.Games[0].Name; //TODO: SAVE to database return(true); }