public async Task <List <PlaylistItemsSearchComponents> > GetChannelItems(string Channelurl) { // Do search // Search address string content = await Web.getContentFromUrlWithProperty(Channelurl + "/videos"); string Playlisturl = string.Empty; // Search string string pattern = "playAllButton.*?\"commandMetadata\":\\{\"webCommandMetadata\":\\{\"url\":\"(?<URL>.*?)\""; MatchCollection result = Regex.Matches(content, pattern, RegexOptions.Singleline); if (result.Count > 0) { Playlisturl = "http://youtube.com" + result[0].Groups[1].Value.Replace(@"\u0026", "&"); } else { Playlisturl = string.Empty; } return(await new PlaylistItemsSearch().GetPlaylistItems(Playlisturl)); }
public async Task <List <ChannelSearchComponents> > GetChannels(string querystring, int querypages) { items = new List <ChannelSearchComponents>(); // Do search for (int i = 1; i <= querypages; i++) { // Search address string content = await Web.getContentFromUrlWithProperty("https://www.youtube.com/results?search_query=" + querystring.Replace(" ", "+") + "&sp=EgIQAg%253D%253D&page=" + i); content = Helper.ExtractValue(content, "window[\"ytInitialData\"]", "window[\"ytInitialPlayerResponse\"]"); // Search string string pattern = "channelRenderer\":\\{\"channelId\":\"(?<ID>.*?)\",\"title\":{\"simpleText\":\"(?<TITLE>.*?)\".*?\"canonicalBaseUrl\":\"(?<URL>.*?)\"}}.*?\\{\"thumbnails\":\\[\\{\"url\":\"(?<THUMBNAIL>.*?)\".*?videoCountText\":\\{\"runs\":\\[\\{\"text\":\"(?<VIDEOCOUNT>.*?)\".*?clickTrackingParams"; MatchCollection result = Regex.Matches(content, pattern, RegexOptions.Singleline); for (int ctr = 0; ctr <= result.Count - 1; ctr++) { if (Log.getMode()) { Log.println(Helper.Folder, "Match: " + result[ctr].Value); } // Id Id = result[ctr].Groups[1].Value; if (Log.getMode()) { Log.println(Helper.Folder, "Id: " + Id); } // Title Title = result[ctr].Groups[2].Value.Replace(@"\u0026", "&"); if (Log.getMode()) { Log.println(Helper.Folder, "Title: " + Title); } // Description Description = Helper.ExtractValue(result[ctr].Value, "\"descriptionSnippet\":{\"runs\":[{\"text\":\"", "\"}]},").Replace(@"\u0026", "&"); if (Log.getMode()) { Log.println(Helper.Folder, "Description: " + Description); } // VideoCount VideoCount = result[ctr].Groups[5].Value; if (VideoCount.Contains(" ")) // -> 1 Video { VideoCount = VideoCount.Replace(" Video", ""); } if (Log.getMode()) { Log.println(Helper.Folder, "VideoCount: " + VideoCount); } // SubscriberCount SubscriberCount = Helper.ExtractValue(result[ctr].Value, "\"subscriberCountText\":{\"simpleText\":\"", " "); if (Log.getMode()) { Log.println(Helper.Folder, "SubscriberCount: " + SubscriberCount); } // Thumbnail Thumbnail = "https:" + result[ctr].Groups[4].Value; if (Log.getMode()) { Log.println(Helper.Folder, "Thumbnail: " + Thumbnail); } // Url Url = "http://youtube.com" + result[ctr].Groups[3].Value; if (Log.getMode()) { Log.println(Helper.Folder, "Url: " + Url); } // Add item to list items.Add(new ChannelSearchComponents(Id, Utilities.HtmlDecode(Title), Utilities.HtmlDecode(Description), VideoCount, SubscriberCount, Url, Thumbnail)); } } return(items); }
public async Task <List <PlaylistItemsSearchComponents> > GetPlaylistItems(string Playlisturl) { items = new List <PlaylistItemsSearchComponents>(); // Do search // Search address string content = await Web.getContentFromUrlWithProperty(Playlisturl); // Search string string pattern = "playlistPanelVideoRenderer\":\\{\"title\":\\{\"accessibility\":\\{\"accessibilityData\":\\{\"label\":.*?\\,\"simpleText\":\"(?<TITLE>.*?)\".*?runs\":\\[\\{\"text\":\"(?<AUTHOR>.*?)\".*?\":\\{\"thumbnails\":\\[\\{\"url\":\"(?<THUMBNAIL>.*?)\".*?\"}},\"simpleText\":\"(?<DURATION>.*?)\".*?videoId\":\"(?<URL>.*?)\""; MatchCollection result = Regex.Matches(content, pattern, RegexOptions.Singleline); for (int ctr = 0; ctr <= result.Count - 1; ctr++) { if (Log.getMode()) { Log.println(Helper.Folder, "Match: " + result[ctr].Value); } // Title Title = result[ctr].Groups[1].Value.Replace(@"\u0026", "&"); if (Log.getMode()) { Log.println(Helper.Folder, "Title: " + Title); } // Author Author = result[ctr].Groups[2].Value.Replace(@"\u0026", "&"); if (Log.getMode()) { Log.println(Helper.Folder, "Author: " + Author); } // Duration Duration = result[ctr].Groups[4].Value; if (Log.getMode()) { Log.println(Helper.Folder, "Duration: " + Duration); } // Thumbnail Thumbnail = result[ctr].Groups[3].Value; if (Log.getMode()) { Log.println(Helper.Folder, "Thumbnail: " + Thumbnail); } // Url Url = "http://youtube.com/watch?v=" + result[ctr].Groups[5].Value; if (Log.getMode()) { Log.println(Helper.Folder, "Url: " + Url); } // Add item to list items.Add(new PlaylistItemsSearchComponents(Utilities.HtmlDecode(Title), Utilities.HtmlDecode(Author), Duration, Url, Thumbnail)); } return(items); }
public async Task <List <PlaylistSearchComponents> > GetPlaylistsPaged(string querystring, int querypagenum) { items = new List <PlaylistSearchComponents>(); // Do search // Search address string content = await Web.getContentFromUrlWithProperty("https://www.youtube.com/results?search_query=" + querystring.Replace(" ", "+") + "&sp=EgIQAw%253D%253D&page=" + querypagenum); // Search string string pattern = "playlistRenderer\":\\{\"playlistId\":\"(?<ID>.*?)\",\"title\":\\{\"simpleText\":\"(?<TITLE>.*?)\"},\"thumbnails\":\\[\\{\"thumbnails\":\\[\\{\"url\":\"(?<THUMBNAIL>.*?)\".*?videoCount\":\"(?<VIDEOCOUNT>.*?)\".*?\\{\"webCommandMetadata\":\\{\"url\":\"(?<URL>.*?)\".*?\"shortBylineText\":\\{\"runs\":\\[\\{\"text\":\"(?<AUTHOR>.*?)\""; MatchCollection result = Regex.Matches(content, pattern, RegexOptions.Singleline); for (int ctr = 0; ctr <= result.Count - 1; ctr++) { if (Log.getMode()) { Log.println(Helper.Folder, "Match: " + result[ctr].Value); } // Id Id = result[ctr].Groups[1].Value; if (Log.getMode()) { Log.println(Helper.Folder, "Id: " + Id); } // Title Title = result[ctr].Groups[2].Value; if (Log.getMode()) { Log.println(Helper.Folder, "Title: " + Title); } // Author Author = result[ctr].Groups[6].Value; if (Log.getMode()) { Log.println(Helper.Folder, "Author: " + Author); } // VideoCount VideoCount = result[ctr].Groups[4].Value; if (Log.getMode()) { Log.println(Helper.Folder, "VideoCount: " + VideoCount); } // Thumbnail Thumbnail = result[ctr].Groups[3].Value; if (Log.getMode()) { Log.println(Helper.Folder, "Thumbnail: " + Thumbnail); } // Url Url = "http://youtube.com" + result[ctr].Groups[5].Value.Replace(@"\u0026", "&"); if (Log.getMode()) { Log.println(Helper.Folder, "Url: " + Url); } // Add item to list items.Add(new PlaylistSearchComponents(Id, Utilities.HtmlDecode(Title), Utilities.HtmlDecode(Author), VideoCount, Thumbnail, Url)); } return(items); }