Beispiel #1
0
        public static async Task <List <string> > GetRandomUrls(string playlistLink, int amount)
        {
            var name         = playlistLink.Split('=')[1];
            var client       = new YoutubeClient();
            var playlistInfo = await client.GetPlaylistInfoAsync(name);

            var videoIds = playlistInfo.VideoIds;

            if (amount > videoIds.Count)
            {
                return(null);
            }
            var list = new List <string>();

            for (var i = 0; i < amount; i++)
            {
                var e = videoIds[new Random().Next(0, videoIds.Count - 1)];
                while (list.Contains(e))
                {
                    e = videoIds[new Random().Next(0, videoIds.Count - 1)];
                }
                list.Add(e);
            }
            return(list);
        }
        public async Task YoutubeClient_GetPlaylistInfoAsync_Favorites_Test()
        {
            // System playlist for videos favorited by a user

            var client       = new YoutubeClient();
            var playlistInfo = await client.GetPlaylistInfoAsync("FLEnBXANsKmyj2r9xVyKoDiQ");

            Assert.That.IsSet(playlistInfo);
            Assert.AreEqual("FLEnBXANsKmyj2r9xVyKoDiQ", playlistInfo.Id);
            Assert.AreEqual(PlaylistType.Favorites, playlistInfo.Type);
        }
        public async Task YoutubeClient_GetPlaylistInfoAsync_Normal_Test()
        {
            // Playlist created by a user

            var client       = new YoutubeClient();
            var playlistInfo = await client.GetPlaylistInfoAsync("PLI5YfMzCfRtZ8eV576YoY3vIYrHjyVm_e");

            Assert.That.IsSet(playlistInfo);
            Assert.AreEqual("PLI5YfMzCfRtZ8eV576YoY3vIYrHjyVm_e", playlistInfo.Id);
            Assert.AreEqual(PlaylistType.UserMade, playlistInfo.Type);
        }
        public async Task YoutubeClient_GetPlaylistInfoAsync_ChannelMix_Test()
        {
            // Playlist generated by Youtube to group uploads by same channel based on video

            var client       = new YoutubeClient();
            var playlistInfo = await client.GetPlaylistInfoAsync("ULl6WWX-BgIiE");

            Assert.That.IsSet(playlistInfo);
            Assert.AreEqual("ULl6WWX-BgIiE", playlistInfo.Id);
            Assert.AreEqual(PlaylistType.ChannelMix, playlistInfo.Type);
        }
        public async Task YoutubeClient_GetPlaylistInfoAsync_ChannelPopular_Test()
        {
            // Playlist generated by Youtube to group popular uploads by same channel

            var client       = new YoutubeClient();
            var playlistInfo = await client.GetPlaylistInfoAsync("PUTMt7iMWa7jy0fNXIktwyLA");

            Assert.That.IsSet(playlistInfo);
            Assert.AreEqual("PUTMt7iMWa7jy0fNXIktwyLA", playlistInfo.Id);
            Assert.AreEqual(PlaylistType.ChannelPopular, playlistInfo.Type);
        }
        public async Task YoutubeClient_GetPlaylistInfoAsync_VideoMix_Test()
        {
            // Playlist generated by Youtube to group similar videos

            var client       = new YoutubeClient();
            var playlistInfo = await client.GetPlaylistInfoAsync("RD1hu8-y6fKg0");

            Assert.That.IsSet(playlistInfo);
            Assert.AreEqual("RD1hu8-y6fKg0", playlistInfo.Id);
            Assert.AreEqual(PlaylistType.VideoMix, playlistInfo.Type);
        }
Beispiel #7
0
        private async void btnPlaylist_Click(object sender, EventArgs e)
        {
            YoutubeClient youtubeClient = new YoutubeClient();

            if (YoutubeClient.TryParsePlaylistId(tbPlaylistUrl.Text, out string playlistId))
            {
                var playlistInfos = await youtubeClient.GetPlaylistInfoAsync(playlistId);

                var firstVideo = await youtubeClient.GetVideoInfoAsync(playlistInfos.Videos[0].Id);
            }
        }
        public async Task YoutubeClient_GetPlaylistInfoAsync_LargeTruncated_Test()
        {
            // Playlist created by a user with a lot of videos in it

            var client       = new YoutubeClient();
            var playlistInfo = await client.GetPlaylistInfoAsync("PLWwAypAcFRgKFlxtLbn_u14zddtDJj3mk", 2);

            Assert.That.IsSet(playlistInfo);
            Assert.AreEqual("PLWwAypAcFRgKFlxtLbn_u14zddtDJj3mk", playlistInfo.Id);
            Assert.AreEqual(PlaylistType.UserMade, playlistInfo.Type);
            Assert.IsTrue(400 >= playlistInfo.Videos.Count);
        }
Beispiel #9
0
        public async Task YoutubeClient_GetPlaylistInfoAsync_Truncated_Test()
        {
            string id        = (string)TestContext.DataRow["Id"];
            int    pageLimit = 1;

            var client       = new YoutubeClient();
            var playlistInfo = await client.GetPlaylistInfoAsync(id, pageLimit);

            Assert.That.IsSet(playlistInfo);
            Assert.AreEqual(id, playlistInfo.Id);
            Assert.IsTrue(200 * pageLimit >= playlistInfo.Videos.Count);
        }
Beispiel #10
0
        public async Task YoutubeClient_GetPlaylistInfoAsync_Test()
        {
            string id            = (string)TestContext.DataRow["Id"];
            int    minVideoCount = (int)TestContext.DataRow["MinVideoCount"];

            var client       = new YoutubeClient();
            var playlistInfo = await client.GetPlaylistInfoAsync(id);

            Assert.That.IsSet(playlistInfo);
            Assert.AreEqual(id, playlistInfo.Id);
            Assert.IsTrue(minVideoCount <= playlistInfo.Videos.Count);
        }
        public async Task GetPlaylistInfoAsync_Test()
        {
            var playlistInfo = await _client.GetPlaylistInfoAsync("PLOU2XLYxmsII8UKqP84oaAxpwyryxbM-o");

            var expectedVideoIds = new[]
            {
                "zDAYZU4A3w0", "HgWHeT_OwHc", "axhdIa_co2o", "ZRvWqF2JmUg", "M_G_1SWVHgw",
                "LxwQeQCUplg", "WaKZ5pCKP6Y", "g_iig8sxsYc", "_xNFt7FsWaA", "H4vMcD7zKM0",
                "jgsKOc4skmY", "twC2viX7u6s", "MPhQ9VT6Rq4", "mBs8MQG-pp0", "HGdKHqMTAko",
                "WVc8iZyhezw", "h1Q5X-Uv0dw", "9nWyWwY2Onc", "jsznS0QxtYI", "LaGpoOgGip0",
                "AUW4ZEhhk_w", "qamtiWa-Cy4", "RK8K9nuRQPQ", "xT6tQAIywFQ", "6xV6aelL6fQ",
                "Ja2hxBAwG_0", "mJ5lNaLX5Bg", "8Lo3KZ1rZWw", "6Nv18xmJirs", "LTVFg6YOjWo",
                "8NbP07OEGsQ", "fqOpaCS117Q"
            };

            CollectionAssert.AreEqual(expectedVideoIds, playlistInfo.VideoIds);
        }
Beispiel #12
0
        public async Task PlaylistCmd([Remainder] string playlistLink)
        {
            var ytc = new YoutubeClient();

            var playListInfo = await ytc.GetPlaylistInfoAsync(YoutubeClient.ParsePlaylistId(playlistLink));

            var ten  = playListInfo.VideoIds.ToArray().Take(10).ToArray();
            var list = new List <string>();

            if (Queue.ContainsKey(Context.Guild.Id))
            {
                Queue.TryGetValue(Context.Guild.Id, out list);
            }
            await ReplyAsync($"Attempting to add the first 10 songs of **{playListInfo.Title}** to the queue!");

            var i = 0;

            foreach (var song in ten)
            {
                var videoInfo = await ytc.GetVideoInfoAsync(song);

                var title = videoInfo.Title;
                list.Add(title);
                await ReplyAsync($"`{i}` - **{title}** added to the queue");

                Queue.Remove(Context.Guild.Id);
                Queue.Add(Context.Guild.Id,
                          list); //ineffieient as f**k because im adding all songs one by one rather than as a group, however. it takes a long time so this is better timewise
                i++;
            }

            await PlayQueue();

            await ReplyAsync(
                $"**{playListInfo.Title}** has been added to the end of the queue. \nQueue Length: **{list.Count}**");
        }
Beispiel #13
0
        public async Task QueueFromUrl(ulong requester, string url)
        {
            // Check if the url is a valid youtube playlist url
            if (YoutubeClient.TryParsePlaylistId(url, out string playlistId))
            {
                var playlistInfos = await youtubeClient.GetPlaylistInfoAsync(playlistId);

                foreach (var videoSnippet in playlistInfos.Videos)
                {
                    YoutubePlaylistSong yps = new YoutubePlaylistSong(videoSnippet.Id, requester, videoSnippet.Title, videoSnippet.ImageThumbnailUrl);
                    songs.Enqueue(yps);
                }

                PlaylistQueued?.Invoke(this, requester, playlistInfos.Videos.Count);
            }
            // Check if the url is a valid youtube video url
            else if (YoutubeClient.TryParseVideoId(url, out string videoId))
            {
                Song song = await GetSongFromUrl($"https://www.youtube.com/watch?v={videoId}");

                song.Requester = requester;
                songs.Enqueue(song);

                SongQueued?.Invoke(this, requester, song);
            }
            else
            {
                throw new Exception("Invalid audio url");
            }

            // Dequeue in case the queue was empty and the player isn't playing anything
            if (!IsPlaying)
            {
                await DequeueSong();
            }
        }