public async Task PobierzAsync() { try { var client = new YoutubeClient(); var url = textBox1.Text; var id = YoutubeClient.ParsePlaylistId(url); var playlist = await client.GetPlaylistAsync(id); foreach (var vid in playlist.Videos) { var streamInfoSet = await client.GetVideoMediaStreamInfosAsync(vid.Id); var streamInfo = streamInfoSet.Audio.WithHighestBitrate(); var ext = streamInfo.Container.GetFileExtension(); var video = await client.GetVideoAsync(vid.Id); string sourcePath = $"C:/YTMP3/{video.Title}.{ext}"; string outputPath = $"C:/YTMP3/{video.Title}.mp3"; await client.DownloadMediaStreamAsync(streamInfo, sourcePath); var ffMpeg = new NReco.VideoConverter.FFMpegConverter(); ffMpeg.ConvertMedia(sourcePath, outputPath, Format.mp4); File.Delete(sourcePath); } MessageBox.Show("Pobrałem."); } catch (Exception ex) { MessageBox.Show("Coś poszło nie tak." + Environment.NewLine + ex.Message); } }
private async void button2_Click(object sender, EventArgs e) { _link = this.tbLink.Text; var id = YoutubeClient.ParsePlaylistId(_link); await GetPlaylistAsync(id); }
public async Task <IActionResult> GetPlaylistMetadata(string url) { var client = new YoutubeClient(); var id = YoutubeClient.ParsePlaylistId(WebUtility.UrlDecode(url)); var playlist = await client.GetPlaylistAsync(id); return(Ok(playlist)); }
public void Extensions_GetUrl_Playlist_Test() { var playlist = GetPlaylist(); var url = playlist.GetUrl(); Assert.That(url, Is.Not.Null.Or.Empty); Assert.That(YoutubeClient.ParsePlaylistId(url), Is.EqualTo(playlist.Id)); }
public void YoutubeClient_ParsePlaylistId_Valid_Test() { var url = (string)TestContext.DataRow["Url"]; var id = (string)TestContext.DataRow["Id"]; var actualId = YoutubeClient.ParsePlaylistId(url); Assert.AreEqual(id, actualId); }
public void YoutubeClient_ParsePlaylistId_Invalid_Test() { var data = File.ReadAllLines("Data\\InvalidPlaylistUrls.txt"); foreach (string datastr in data) { string url = datastr; Assert.ThrowsException <FormatException>(() => YoutubeClient.ParsePlaylistId(url)); } }
public async void DownloadAndQueue() { YoutubeClient client = new YoutubeClient(); while (true) { if (PreQueue.Count > 0) { for (int c = 0; c < PreQueue.Count; c++) { if (PreQueue.ToList()[c].Contains("index") && PreQueue.ToList()[c].Contains("list")) { Console.WriteLine("Playlist"); List <Video> playlist = new List <Video>(); int index = 0; for (int i = 0; i < PreQueue.Count; i++) { if (PreQueue.ToList()[i].Contains("index") && PreQueue.ToList()[i].Contains("list")) { index = i; break; } } var templist = await client.GetPlaylistAsync(YoutubeClient.ParsePlaylistId(PreQueue.ToList()[index])); playlist = templist.Videos.ToList(); List <string> tempholder = PreQueue.ToList(); tempholder.RemoveAt(index); PreQueue = new Queue <string>(tempholder); for (int x = 0; x < playlist.Count; x++) { PreQueue.Enqueue(playlist[x].GetUrl()); } } } } if (PlayList.Count < 5 && PreQueue.Count > 0) { if (PreQueue.Peek().Contains("www")) { SongInfo songInfo = new SongInfo(); await songInfo.AddVideoInfoAudio(PreQueue.Dequeue()); PlayList.Enqueue(songInfo); } else { //seach youtube } } } }
public void YoutubeClient_ParsePlaylistId_Valid_Test() { var data = File.ReadAllLines("Data\\ValidPlaylistUrls.txt"); foreach (string datastr in data) { string url = datastr.SubstringUntil(";"); string id = datastr.SubstringAfter(";"); string actualId = YoutubeClient.ParsePlaylistId(url); Assert.AreEqual(id, actualId); } }
public async Task Create_joblistAsync(string url) { string id = YoutubeClient.ParsePlaylistId(url); var client = new YoutubeClient(); Playlist playlist = await client.GetPlaylistAsync(id); var videos = playlist.Videos; foreach (Video item in videos) { _jobs.Add(item); } }
public static async Task <Playlist> GetPlaylistAsync(string playlistUrl) { try { var id = YoutubeClient.ParsePlaylistId(playlistUrl); var client = new YoutubeClient(); return(await client.GetPlaylistAsync(id)); } catch (FormatException ex) { Debug.WriteLine(ex.StackTrace); return(null); } }
public async Task DownloadPlayList(string url, string Path) { var id = YoutubeClient.ParsePlaylistId(url); var client = new YoutubeClient(); var PlayList = await client.GetPlaylistAsync(id); Path += $"//{PlayList.Title.ValidNameForWindows()}"; Path.EnsureExsit(); foreach (var video in PlayList.Videos) { await DownloadVideoAsync(video, Path); await GenrateSubTitleAsync(video.Id, Path, video.Title.ValidNameForWindows()); } }
public async Task PlaylistCmd([Remainder] string PlaylistLink) { await this._Service.LeaveAudio(this.Context.Guild); await this._Service.JoinAudio(this.Context.Guild, (this.Context.User as IVoiceState).VoiceChannel); var YTC = new YoutubeClient(); var PlayListInfo = await YTC.GetPlaylistAsync(YoutubeClient.ParsePlaylistId(PlaylistLink)); var IDArray = PlayListInfo.Videos.ToArray(); foreach (var ID in IDArray) { await this._Service.SendAudioAsync(this.Context.Guild, ID); } await this._Service.LeaveAudio(this.Context.Guild); }
protected override void ProcessLinks(string[] links, string format) { var tasksToWait = new List <Task>(); long playListCounter = 0; foreach (var link in links) { playListCounter++; var client = new YoutubeClient(); uiService.WriteHeader($@"[{playListCounter}] Processing link ""{link}"""); try { var id = YoutubeClient.ParsePlaylistId(link); var playlist = client.GetPlaylistAsync(id).GetAwaiter().GetResult(); long videoCounter = 0; foreach (var video in playlist.Videos) { videoCounter++; var directoryToSaveVideo = $"../{_downloadFolderName}/{_downloadSubFolderName} - {playlist.Title}"; var logPrefix = $"{playListCounter}.{videoCounter}"; ProcessVideo(format, video.Id, client, logPrefix, ref tasksToWait, directoryToSaveVideo); } } catch (Exception ex) { uiService.WriteOutput($"[{playListCounter}] {ex.Message}", true); } } if (tasksToWait.Any()) { uiService.WriteOutput($"Converting files, please wait..."); Task.WaitAll(tasksToWait.ToArray()); uiService.WriteOutput($"Converting files done."); } }
public async void InitPlayListFromUrl(string playListUrl, YoutubeClient client) { try { var playlist = await client.GetPlaylistAsync(YoutubeClient.ParsePlaylistId(playListUrl)); this.PlaylistAuthor.Content = playlist.Author; this.PlaylistTitle.Content = playlist.Title; for (int i = 0; i < playlist.Videos.Count; i++) { ListBoxItem item = new ListBoxItem(); PlayListItemControl playItem = new PlayListItemControl(); playItem.NumberLabel.Content = i + 1; playItem.VideoTitle.Content = playlist.Videos[i].Title; BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.UriSource = new Uri(playlist.Videos[i].Thumbnails.MediumResUrl, UriKind.Absolute); bitmap.EndInit(); playItem.VideoThumbnail.Source = bitmap; if (playlist.Videos[i].Author.Equals("")) { playItem.VideoAuthor.Content = "Youtube"; } else { playItem.VideoAuthor.Content = playlist.Videos[i].Author; } playItem.VideoDuration.Content = playlist.Videos[i].Duration; item.Content = playItem; PlayListBox.Items.Add(item); } } catch (Exception ex) { // ignored } }
public void ParsePlaylistId_Valid_Test() { string[] urls = { "https://www.youtube.com/playlist?list=PLOU2XLYxmsIJGErt5rrCqaSGTMyyqNt2H", "https://www.youtube.com/playlist?list=WL", "https://www.youtube.com/watch?v=b8m9zhNAgKs&list=PL9tY0BWXOZFuFEG_GtOBZ8-8wbkH-NVAr" }; string[] ids = { "PLOU2XLYxmsIJGErt5rrCqaSGTMyyqNt2H", "WL", "PL9tY0BWXOZFuFEG_GtOBZ8-8wbkH-NVAr" }; for (int i = 0; i < urls.Length; i++) { string url = urls[i]; string id = ids[i]; string parsed = YoutubeClient.ParsePlaylistId(url); Assert.AreEqual(id, parsed); } }
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}**"); }
public async Task AddSource() { try { if (string.IsNullOrWhiteSpace(NewSourceUrl)) { return; } var playlistid = YoutubeClient.ParsePlaylistId(NewSourceUrl); var playlist = await _ytclient.GetPlaylistAsync(playlistid); var item = new Source { Id = $"YTPl#{playlistid}", PlaylistId = playlistid, Title = playlist.Title, Author = playlist.Author, Description = playlist.Description, }; NewSourceUrl = string.Empty; await _repository.AddSource(item); } catch (Exception) { } finally { await RebuildList(); IsAdd = false; StateHasChanged(); } }
private string GetIdFromLink(string link) { return(YoutubeClient.ParsePlaylistId(link)); }
public void YoutubeClient_ParsePlaylistId_Test(string playlistUrl, string expectedPlaylistId) { var playlistId = YoutubeClient.ParsePlaylistId(playlistUrl); Assert.That(playlistId, Is.EqualTo(expectedPlaylistId)); }
public void YoutubeClient_ParsePlaylistId_Invalid_Test(string playlistUrl) { Assert.Throws <FormatException>(() => YoutubeClient.ParsePlaylistId(playlistUrl)); }
public async Task SendAudioAsync(IGuild guildObj, IMessageChannel channel, IUser user, string path) { var g = Program.GetGuild(guildObj); if (g.MessageChannel == null) { g.MessageChannel = channel; } var guild = Program.GetGuild(guildObj.Id); var youtube = new YoutubeClient(); bool playlist = false; var id = string.Empty; try { if (path.Contains("playlist?list") || path.Contains("&list")) { //Console.WriteLine("playlist gotten"); id = YoutubeClient.ParsePlaylistId(path); playlist = true; } else { id = YoutubeClient.ParseVideoId(path); } } catch (Exception e) { // invalid id // find videos var items = new VideoSearch(); var videos = new List <SearchVideoItem>(); var sb = new StringBuilder(); var index = 0; foreach (var item in items.SearchQuery(path, 1)) { if (index > 5) { break; } var itemId = YoutubeClient.ParseVideoId(item.Url); videos.Add(new SearchVideoItem( item.Url, itemId, item.Title, item.Duration)); sb.AppendLine($"{Program.Emojis[(index+1).ToString()].Name} {item.Title} ({item.Duration})"); index++; } var embed = Embeds.GetRetrievedSongs(sb.ToString(), guild.Prefix); var msg = await g.MessageChannel.SendMessageAsync(string.Empty, embed : embed); WaitingUser u = new WaitingUser(user.Id, guild.Id, msg.Id, WaitingUser.TypeOfWait.SearchingSong, videos.ToArray()); guild.WaitingUsers.Add(u); return; } if (playlist) { await ParsePlaylist(guild, channel, user, path, youtube, id); } else { await ParseVideo(guild, channel, user, path, youtube, id); } ; }
public void YoutubeClient_ParsePlaylistId_Invalid_Test() { var url = (string)TestContext.DataRow["Url"]; Assert.ThrowsException <FormatException>(() => YoutubeClient.ParsePlaylistId(url)); }
public async Task Play(CommandContext ctx, [Description("the url of a youtube music video you wish to play.")][RemainingText] string song) { // if (song.Contains("&list=")) { await ctx.RespondAsync("I don't currently accept playlist. Sorry :("); return; } if (!song.Contains("youtu")) { await ctx.RespondAsync("That doesn't seem to be a valid youtube URL. If you think this is an error, contact Draxis."); return; } ctsStop = new CancellationTokenSource(); var vNextClient = ctx.Client.GetVoiceNextClient(); var vNextConnection = vNextClient.GetConnection(ctx.Guild); if (vNextConnection == null) { await ctx.RespondAsync("I am not in any channel in the guild. Type ``//join`` for me to join a voice channel."); return; } var ytClient = new YoutubeClient(); Video ytInfo = null; string ID; if (song.Contains("&list=")) { ID = YoutubeClient.ParsePlaylistId(song); var ytPlaylist = await ytClient.GetPlaylistAsync(ID); await ctx.RespondAsync($"Now adding {ytPlaylist.Videos.Count} songs from ``{ytPlaylist.Title}``. Please Wait...."); foreach (var item in ytPlaylist.Videos) { playList.Add(item); } } else { ID = YoutubeClient.ParseVideoId(song); ytInfo = await ytClient.GetVideoAsync(ID); playList.Add(ytInfo); await ctx.RespondAsync($"Added song: {ytInfo.Title} - Author: {ytInfo.Author}"); } while (vNextConnection.IsPlaying) { await vNextConnection.WaitForPlaybackFinishAsync(); } foreach (var item in playList.ToList()) { skip = false; if (ctsStop.IsCancellationRequested) { return; } await vNextConnection.SendSpeakingAsync(true); var set = await ytClient.GetVideoMediaStreamInfosAsync(item.Id); var streamInfo = GetBestAudioStreamInfo(set); var streamFileExt = streamInfo.Container.GetFileExtension(); var streamFilePath = Path.Combine(TempDirectoryPath, $"{Guid.NewGuid()}.{streamFileExt}"); await ytClient.DownloadMediaStreamAsync(streamInfo, streamFilePath); var ytEmbded = new DiscordEmbedBuilder() .WithTitle($"Now Playing: ({item.Title})") .WithDescription($"Author: {item.Author} | Duration: {item.Duration}") .WithUrl($"{item.GetUrl()}") .WithThumbnailUrl($"{item.Thumbnails.MediumResUrl}"); await ctx.RespondAsync("", false, ytEmbded); playList.Remove(item); var psi = new ProcessStartInfo { FileName = "ffmpeg", Arguments = $@"-i ""{streamFilePath}"" -ac 2 -f s16le -ar 48000 pipe:1", RedirectStandardOutput = true, UseShellExecute = false }; var ffmpeg = Process.Start(psi); var ffout = ffmpeg.StandardOutput.BaseStream; var buff = new byte[3840]; var br = 0; while ((br = ffout.Read(buff, 0, buff.Length)) > 0 && !ctsStop.IsCancellationRequested && skip != true) { if (br < buff.Length) { for (var i = br; i < buff.Length; i++) { buff[i] = 0; } } await vNextConnection.SendAsync(buff, 20); } await vNextConnection.SendSpeakingAsync(false); while (vNextConnection.IsPlaying) { await vNextConnection.WaitForPlaybackFinishAsync(); } ffout.Flush(); ffout.Close(); ffmpeg.Close(); //Console.WriteLine("Deleting temp file..."); // File.Delete(streamFilePath); } }