Example #1
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);
            }
        }