public async Task <YoutubePlaylist> GetPlaylistRecommendation(string videoId) { string requestUrl = YOUTUBE_BASE_URL + "watch?v=" + videoId; string pageContent = await Utils.GetSourceFromUrl(httpClient, requestUrl); string regexPattern = "\"compactRadioRenderer\"(.+?)\"compactVideoRenderer\""; Match matcher = Regex.Match(pageContent, regexPattern, RegexOptions.IgnoreCase); if (matcher.Success) { string compactRadioRenderer = matcher.Value; // Get Json String compactRadioRenderer = "{" + compactRadioRenderer.Substring(0, compactRadioRenderer.Length - ",{\"compactVideoRenderer\"".Length); JObject compactRadioRendererObject = JObject.Parse(compactRadioRenderer)["compactRadioRenderer"].Value <JObject>(); return(YoutubePlaylist.ParseCompactRadioRenderer(compactRadioRendererObject)); } throw new NoResultFoundException("Cannot find any recommendation for videoId: " + videoId); }
public static void m() { //var list = new List<int>(); //var k =list[2]; while (true) { try { Console.Write("Youtube Playlist ID: "); var id = Console.ReadLine(); var playlist = new YoutubePlaylist(id, PlaylistRefreshFlags.All); Console.WriteLine("Refreshing..."); Console.WriteLine(); //playlist.Refresh(); //Console.WriteLine(video.Url); Console.WriteLine("Title: {0}", playlist.Title); Console.WriteLine("Length: {0}", playlist.Count); Console.WriteLine("Views: {0}", playlist.Views); Console.WriteLine(); } catch (Exception ex) { Console.WriteLine("Error: {0}", ex.Message); } } }
public void FillPlaylist(YoutubePlaylist list, IEnumerable <YoutubeClip> clips) { var itemsRq = service.PlaylistItems.List("snippet"); itemsRq.PlaylistId = list.PlaylistId; var items = itemsRq.Execute().Items; foreach (var e in items) { service.PlaylistItems.Delete(e.Id).Execute(); } foreach (var e in clips) { var item = new PlaylistItem { Snippet = new PlaylistItemSnippet { PlaylistId = list.PlaylistId, ResourceId = new ResourceId { Kind = "youtube#video", VideoId = e.Id } } }; service.PlaylistItems.Insert(item, "snippet").Execute(); } }
public void DeletePlaylist(YoutubePlaylist playlist) { try { service.Playlists.Delete(playlist.PlaylistId).Execute(); } catch { } }
public static YoutubePlaylist RequestAllParts(this YoutubePlaylist playlist) { return(playlist.RequestContentDetails() .RequestStatus() .RequestLocalizations() .RequestPlayer() .RequestSnippet()); }
private StackPanel CreatePanel(YoutubePlaylist a_ChanelYT) { StackPanel t_StackPanel = new StackPanel(); t_StackPanel.Children.Add(CreateBouton(a_ChanelYT)); t_StackPanel.Children.Add(CreateTextBlock(a_ChanelYT)); return(t_StackPanel); }
private TextBlock CreateTextBlock(YoutubePlaylist a_ChanelYT) { TextBlock t_TextBlock = new TextBlock(); t_TextBlock.Text = a_ChanelYT.description; t_TextBlock.TextWrapping = TextWrapping.Wrap; t_TextBlock.FontSize = 12; return(t_TextBlock); }
public static async Task AsyncMain() { HttpClient httpClient = new HttpClient(); // Initialize YoutubeClient YoutubeClient ytClient = new YoutubeClient(httpClient); // Get sond PlaylistRecommendation by video Id. YoutubePlaylist youtubePlaylist = await ytClient.GetPlaylistRecommendation("9CyMi-n36rg"); Console.WriteLine(youtubePlaylist); }
private Button CreateBouton(YoutubePlaylist a_ChanelYT) { Button t_Buuton = new Button(); t_Buuton.Content = a_ChanelYT.title; t_Buuton.FontSize = 12; t_Buuton.Height = 50; t_Buuton.Background = new SolidColorBrush(Colors.White); t_Buuton.Foreground = new SolidColorBrush(Colors.Black); t_Buuton.Click += (object Object, RoutedEventArgs e) => { System.Diagnostics.Process.Start("https://www.youtube.com/channel/" + a_ChanelYT.channelId); }; return(t_Buuton); }
public YoutubePlaylist GetPlaylist(string id) { throw new NotImplementedException(); var res = new YoutubePlaylist(); var searher = _youtubeService.PlaylistItems.List("snippet"); searher.PlaylistId = id; var response = searher.Execute(); foreach (var item in response.Items) { } }
private void DownloadPlaylistItems(string playlistId) { var api = new Swagger.YTAPI.Api.PlaylistApi(); Model = api.Get(playlistId); // var youtubeService = new YouTubeService(new BaseClientService.Initializer // { // ApplicationName = "YoutubeListSyncronizer", // ApiKey = "AIzaSyDgUR4esr5twkPl5jRwGlx6yPGR8e6zBPs" // }); // // //fetch playlist name // { // var request = youtubeService.Playlists.List("snippet"); // request.Id = PlaylistID; // var response = request.Execute(); // try // { // PlaylistName = response.Items[0].Snippet.Title; // } // catch (Exception ex) // { // if (Debugger.IsAttached) // throw; // PlaylistName = "Youtube"; // } // } // ReportProgress(30); // // var nextPageToken = ""; // while (nextPageToken != null) // { // var request = youtubeService.PlaylistItems.List("snippet"); // request.PlaylistId = playlistId; // request.MaxResults = 20; // request.PageToken = nextPageToken; // // var response = request.Execute(); // // foreach (var playlistItem in response.Items) // { // var videoId = playlistItem.Snippet.ResourceId.VideoId; // if (VideoIDsDictionary.ContainsKey(videoId)) // continue; // var title = playlistItem.Snippet.Title; // VideoIDsDictionary.Add(videoId, title); // } // // nextPageToken = response.NextPageToken; // } }
public ActionResult <YoutubePlaylist> Get(string playlistid) { var youtubeService = new YouTubeService(new BaseClientService.Initializer { ApplicationName = _configuration["AppName"], ApiKey = _configuration["ApiKey"] }); var result = new YoutubePlaylist { ID = playlistid }; //fetch playlist name { var request = youtubeService.Playlists.List("snippet"); request.Id = playlistid; var response = request.Execute(); if (response.Items == null || response.Items.Count == 0) { return(new YoutubePlaylist()); } result.PlaylistName = response.Items[0].Snippet.Title; } var nextPageToken = ""; while (nextPageToken != null) { var request = youtubeService.PlaylistItems.List("snippet"); request.PlaylistId = playlistid; request.MaxResults = 20; request.PageToken = nextPageToken; var response = request.Execute(); foreach (var playlistItem in response.Items) { var videoId = playlistItem.Snippet.ResourceId.VideoId; if (result.VideoIDsDictionary.ContainsKey(videoId)) { continue; } var title = playlistItem.Snippet.Title; result.VideoIDsDictionary.Add(videoId, title); } nextPageToken = response.NextPageToken; } return(result); }
public YoutubePlaylist CreatePlaylist(string name) { var list = new Playlist(); list.Snippet = new PlaylistSnippet(); list.Snippet.Title = name; list.Status = new PlaylistStatus(); list.Status.PrivacyStatus = "public"; list = service.Playlists.Insert(list, "snippet,status").Execute(); var playlist = new YoutubePlaylist(); playlist.PlaylistId = list.Id; playlist.PlaylistTitle = list.Snippet.Title; return(playlist); }
private void RecreateSaved() { LOGGER.Debug($"Recreating cache of saved playlists"); Saved = new YoutubePlaylistContainer(); foreach (var playlist in Container.RegisteredPlaylists) { LOGGER.Debug($"Recreating cache for playlist '{playlist.Title}'"); var newPlaylist = new YoutubePlaylist() { Id = playlist.Id, Title = playlist.Title, PublishedAt = playlist.PublishedAt }; Saved.RegisterPlaylist(newPlaylist); } }
public static YoutubePlaylistItems Items(this YoutubePlaylist playlist) { return(PlaylistItems(playlist.Id)); }
public static YoutubePlaylist RequestSnippet(this YoutubePlaylist playlist) { return(playlist.RequestPart(PartType.Snippet)); }
public static YoutubePlaylist RequestPlayer(this YoutubePlaylist playlist) { return(playlist.RequestPart(PartType.Player)); }
public static YoutubePlaylist RequestLocalizations(this YoutubePlaylist playlist) { return(playlist.RequestPart(PartType.Localizations)); }
public static YoutubePlaylist RequestStatus(this YoutubePlaylist playlist) { return(playlist.RequestPart(PartType.Status)); }
public static YoutubePlaylist RequestContentDetails(this YoutubePlaylist playlist) { return(playlist.RequestPart(PartType.ContentDetails)); }
public static YoutubePlaylist RequestPart(this YoutubePlaylist playlist, PartType partType) { return(Playlist(playlist.Settings.Clone(), playlist.PartTypes.Append(partType).ToArray())); }
public void OneTimeSetUp() { newPath = $"{path}/{title}"; YoutubePlaylist.DownloadPlayListInformation(url, path, numberOfVideos).Wait(); }
public async Task <ActionResult <dynamic> > PostYoutubeSong(YoutubeLink youtubeLink) { var SongCount = _context.TSongs.ToList <YoutubeSong>().Count; var PlaylistCount = _playlistContext.TPlaylist.ToList <YoutubePlaylist>().Count; var SongPlaylistCount = _songPlaylistContext.TSongPlaylist.ToList <SongPlaylist>().Count; // This gets the YoutubeVideo object and downloads the mp3 _youtube = new Youtube(youtubeLink.Url, @"C:\Users\nsedler\source\repos\WebApplication3\WebApplication3\Files\"); Tuple <Video, Playlist> VideoPlaylist = await _youtube.GetYoutubeVideoAsync(); await _youtube.DownloadYoutubeVideoAsync(); //Sets the Songs fields YoutubeSong _song = new YoutubeSong(); if (VideoPlaylist.Item1 != null) { _song = new YoutubeSong(); var video = VideoPlaylist.Item1; _song.Title = video.Title; _song.Length = video.Duration.Ticks; _song.Url = $"https://localhost:44370/StaticSongs/{video.Title}.mp3"; _song.Id = SongCount + 1; _context.TSongs.Add(_song); await _context.SaveChangesAsync(); } else { YoutubePlaylist YoutubePlaylist = new YoutubePlaylist(); var Playlist = await _YoutubeClient.Playlists.GetAsync(VideoPlaylist.Item2.Id); YoutubePlaylist.Name = Playlist.Title; YoutubePlaylist.Id = PlaylistCount + 1; _playlistContext.TPlaylist.Add(YoutubePlaylist); await _playlistContext.SaveChangesAsync(); await foreach (var video in _YoutubeClient.Playlists.GetVideosAsync(VideoPlaylist.Item2.Id)) { _song = new YoutubeSong(); _song.Title = video.Title; _song.Length = video.Duration.Ticks; _song.Url = $"https://localhost:44370/StaticSongs/{video.Title}.mp3"; _song.Id = SongCount + 1; _context.TSongs.Add(_song); await _context.SaveChangesAsync(); SongPlaylist SongPlaylist = new SongPlaylist(); SongPlaylist.Id = SongPlaylistCount + 1; SongPlaylist.SongId = _song.Id; SongPlaylist.PlaylistId = YoutubePlaylist.Id; _songPlaylistContext.TSongPlaylist.Add(SongPlaylist); await _songPlaylistContext.SaveChangesAsync(); SongPlaylistCount++; SongCount++; } return(CreatedAtAction("GetYoutubeSong", new { id = YoutubePlaylist.Id }, YoutubePlaylist)); } return(CreatedAtAction("GetYoutubeSong", new { id = _song.Id }, _song)); }