public async Task NowPlaying(SocketCommandContext Context) { try { List <SongStruct> queue = new List <SongStruct>(); if (queueDict.TryGetValue(Context.Guild.Id, out queue)) { if (queue.Count != 0) { var infoJson = File.ReadAllText($"{queue[0].name}.info.json"); var info = JObject.Parse(infoJson); var title = info["fulltitle"]; var eb = new EmbedBuilder() { Color = new Color(4, 97, 247), Footer = new EmbedFooterBuilder() { Text = $"Requested by {Context.User.Username}#{Context.User.Discriminator}", IconUrl = (Context.User.GetAvatarUrl()) } }; eb.AddField((efb) => { int duration = 0; var con = Int32.TryParse(info["duration"].ToString(), out duration); string dur = "00:00"; if (con) { dur = Convert(duration); } efb.Name = "Now playing"; efb.IsInline = false; efb.Value = $"[{dur}] - [{title}]({StringEncoder.Base64Decode(queue[0].name)})"; }); eb.AddField((x) => { x.Name = "Requested by"; x.IsInline = false; x.Value = queue[0].user; }); await Context.Channel.SendMessageAsync("", false, eb.Build()); } else { await Context.Channel.SendMessageAsync(":no_entry_sign: Queue is empty!"); } } else { await Context.Channel.SendMessageAsync( ":no_entry_sign: You first have to create a Queue by adding atleast one song!"); } } catch (Exception e) { Console.WriteLine(e); } }
private async Task <string> Download(string path, IUserMessage msg, SocketCommandContext Context) { bool stream = false; if (path.Contains("https://www.youtube.com/watch?v=") && path.Contains("&"))//path.Contains('&')) { var split = path.Split('&'); path = split[0]; } string name = StringEncoder.Base64Encode(path); Process ytdl = new Process(); if (!File.Exists(name + ".mp3")) { try { var ytdlChecker = CheckerYtDl(path); ytdlChecker.ErrorDataReceived += (x, y) => { stream = false; Console.WriteLine("YTDL CHECKER FAILED"); }; string output = ytdlChecker.StandardOutput.ReadToEnd(); ytdlChecker.WaitForExit(); if (ytdlChecker.ExitCode != 0) { await msg.ModifyAsync(x => { x.Content = ":no_entry_sign: YT-DL Error. Possible reasons: Video is blocked in Bot's country, NO LIVESTREAMS or a plain YT-DL bug. Retry once"; }); return("f"); } IDictionary <string, JToken> json = JObject.Parse(output); if (json.ContainsKey("is_live") && !String.IsNullOrEmpty(json["is_live"].Value <string>())) { stream = false; ytdl = YtDl("", name); Console.WriteLine("YTDL CHECKER LIVE DETECTED"); } else { ytdl = YtDl(path, name); } } catch (Exception e) { Console.WriteLine(e); } } if (name != null) { Stopwatch stopwatch = Stopwatch.StartNew(); stopwatch.Start(); while (!File.Exists(name + ".mp3")) { if (ytdl != null) { if (ytdl.HasExited) { break; } } if (stopwatch.ElapsedMilliseconds > 60000) { stopwatch.Stop(); try { ytdl.Kill(); } catch (Exception e) { Console.WriteLine(e); } var dir = new DirectoryInfo("."); foreach (var file in dir.EnumerateFiles("*.part")) { file.Delete(); } File.Delete($"{name}.info.json"); await msg.ModifyAsync(x => { x.Content = ":no_entry_sign: The Server that hosts the Video you tried to download is way to slow. Try another, faster service!"; }); return("f"); } } if (File.Exists(name + ".mp3")) { try { await msg.ModifyAsync( x => { x.Content = ":musical_note: Successfully Downloaded."; }); stream = true; } catch (Exception e) { Console.WriteLine(e); } } else { await msg.ModifyAsync(x => { x.Content = ":no_entry_sign: Failed to Download. Possible reasons: Video is blocked in Bot's country, Video was too long, NO PLAYLISTS AND NO LIVE STREAMS!"; }); } } else { await msg.ModifyAsync(x => { x.Content = "It must be a YT link! Failed to Download."; }); } if (stream) { return(name); } else { return("f"); } }
public async Task QueueList(SocketCommandContext Context) { List <SongStruct> queue = new List <SongStruct>(); if (queueDict.TryGetValue(Context.Guild.Id, out queue)) { if (queue.Count != 0) { try { var eb = new EmbedBuilder() { Color = new Color(4, 97, 247), Footer = new EmbedFooterBuilder() { Text = $"Requested by {Context.User.Username}#{Context.User.Discriminator}", IconUrl = (Context.User.GetAvatarUrl()) } }; eb.Title = "Queue List"; var infoJsonT = File.ReadAllText($"{queue[0].name}.info.json"); var infoT = JObject.Parse(infoJsonT); var titleT = infoT["fulltitle"].ToString(); if (String.IsNullOrWhiteSpace(titleT)) { titleT = "Couldn't find name"; } eb.AddField((efb) => { int duration = 0; var con = Int32.TryParse(infoT["duration"].ToString(), out duration); string dur = "00:00"; if (con) { dur = Convert(duration); } efb.Name = "Now playing"; efb.IsInline = true; efb.Value = $"[{dur}] - **[{titleT}]({StringEncoder.Base64Decode(queue[0].name)})** \n \t*by {queue[0].user}*"; }); int lenght = 0; if (queue.Count > 11) { lenght = 11; } else { lenght = queue.Count; } for (int i = 1; i < lenght; i++) { eb.AddField((efb) => { efb.Name = $"#{i} by {queue[i].user}"; efb.IsInline = false; var infoJson = File.ReadAllText($"{queue[i].name}.info.json"); var info = JObject.Parse(infoJson); int duration = 0; var con = Int32.TryParse(info["duration"].ToString(), out duration); string dur = "00:00"; if (con) { dur = Convert(duration); } var title = info["fulltitle"].ToString(); if (String.IsNullOrWhiteSpace(title)) { title = "Couldn't find name"; } efb.Value += $"[{dur}] - **[{title}]({StringEncoder.Base64Decode(queue[i].name)})**"; }); } if (queue.Count == 1) { eb.AddField((efb) => { efb.Name = "Queue"; efb.IsInline = false; efb.Value = "No Songs in Queue"; }); } await Context.Channel.SendMessageAsync("", false, eb.Build()); } catch (Exception e) { Console.WriteLine(e); } } else { await Context.Channel.SendMessageAsync(":no_entry_sign: Queue is empty!"); } } else { await Context.Channel.SendMessageAsync( ":no_entry_sign: You first have to create a Queue by adding atleast one song!"); } }