Example #1
0
        public async Task QueueSong(string query, SocketUser usr, IMessageChannel channel, IGuild guild, SocketUserMessage usrmsg)
        {
            if ((usr as IVoiceState).VoiceChannel == null)
            {
                await channel.SendMessageAsync(usr.Mention + " você não está conectado em nenhum canal de voz");

                return;
            }
            Video video = YTVideoOperation.YoutubeSearch(query);

            if (video == null)
            {
                var embedL = new EmbedBuilder()
                             .WithColor(new Color(240, 230, 231))
                             .WithDescription("Nenhum resultado encontrado para: " + query);
                await channel.SendMessageAsync("", false, embedL);

                return;
            }

            //Attempts to get the audio URI either by YoutubeExplode or youtube-dl
            //First attempt is with YoutubeExplode
            string uri = YTVideoOperation.GetVideoURIExplode(video.Id).Result;


            if (uri == null)
            {
                uri = YTVideoOperation.GetVideoAudioURI("https://www.youtube.com/watch?v=" + video.Id);
            }

            YTSong song = new YTSong(video, uri, query, SongOrder(), usr);

            mp.Enqueue(song);
            var embedQueue = new EmbedBuilder()
                             .WithColor(new Color(240, 230, 231))
                             .WithTitle("#" + song.Order + "  " + song.Title)
                             .WithDescription("Busca: " + query)
                             .WithUrl(song.Url)
                             .WithImageUrl(song.DefaultThumbnailUrl)
                             .WithFooter(new EmbedFooterBuilder().WithText(song.RequestAuthor.Username + " | " + song.Duration));

            var msg = await channel.SendMessageAsync("", false, embedQueue);

            await Task.Delay(6000);

            await usrmsg.DeleteAsync().ConfigureAwait(false);

            await msg.DeleteAsync().ConfigureAwait(false);
        }
Example #2
0
        public async Task QueuePlaylist(string playlistUrl, SocketUser usr, IMessageChannel channel, IGuild guild, IVoiceChannel target)
        {
            if ((usr as IVoiceState).VoiceChannel == null)
            {
                await channel.SendMessageAsync(usr.Mention + " você não está conectado em nenhum canal de voz");

                return;
            }

            PlaylistItem[] songs     = YTVideoOperation.PlaylistSearch(YTVideoOperation.TryParsePlaylistID(playlistUrl).ID);
            string[]       audioURIs = new string[songs.Length];


            var embedA = new EmbedBuilder()
                         .WithColor(new Color(240, 230, 231))
                         .WithDescription("Carregando playlist...");
            await channel.SendMessageAsync("", false, embedA);

            int unavailableVids = 0;
            int x = 0;

            for (int i = 0; i < songs.Length; i++)
            {
                try
                {
                    //Video video = YTVideoOperation.SearchVideoByID(songs[i].Snippet.ResourceId.VideoId);
                    if (cancelPlaylist)
                    {
                        break;
                    }

                    var song = songs[i];

                    string uri = YTVideoOperation.GetVideoURIExplode(songs[i].Snippet.ResourceId.VideoId).Result;

                    if (uri == null)
                    {
                        uri = YTVideoOperation.GetVideoAudioURI("https://www.youtube.com/watch?v=" + songs[i].Snippet.ResourceId.VideoId);
                    }

                    if (uri == null || uri == "")
                    {
                        unavailableVids++;
                    }
                    else
                    {
                        YTSong playlistSong = new YTSong(song.Snippet.Title,
                                                         song.Snippet.Thumbnails.Default__.Url,
                                                         song.Snippet.ResourceId.VideoId, uri, "playlist", SongOrder(), usr, YTVideoOperation.GetVideoDuration(song.Snippet.ResourceId.VideoId));
                        mp.Enqueue(playlistSong);
                        x++;
                    }

                    if (cancelPlaylist)
                    {
                        break;
                    }
                }
                catch (OperationCanceledException)
                {
                    Console.WriteLine("QUEUE PLAYLIST CANCELED");
                    //cancelPlaylist = true;
                    //Playing = false;
                }

                if (!mp.Playing)
                {
                    StartMusicPlayer(guild, target, usr, channel);
                }
            }

            if (cancelPlaylist)
            {
                mp.Clear();
                cancelPlaylist = false;
                return;
            }

            if (unavailableVids == 0)
            {
                var embedAll = new EmbedBuilder()
                               .WithColor(new Color(240, 230, 231))
                               .WithDescription("Playlist carregada \n\n`Todos os videos carregados (" + x + ")`");
                await channel.SendMessageAsync("", false, embedAll);
            }
            else
            {
                var embedB = new EmbedBuilder()
                             .WithColor(new Color(240, 230, 231))
                             .WithDescription("Playlist carregada \n\n`✔ Videos carregados: " + x + " ❌ Videos indisponiveis: " + unavailableVids);
                await channel.SendMessageAsync("", false, embedB);
            }
        }