public Player() : base() { OnError += delegate(object sender, string msg) { AeroError.EmitError(msg); }; SongManager.OnErrorEvent += delegate(string errorMsg) { ErrorDialog dialog = new ErrorDialog(errorMsg); dialog.ShowDialog(); }; SongManager.OnPlaylistChange += delegate(object sender, PlayList playlist, bool delete) { if (delete) { PlayLists.Remove(playlist); return; ///////////////// LEAVE FUNCTION } //If not deleting this playlist, we are editing the existing one, or adding a new one if not found. int index = PlayLists.Select((Playlist, index) => new { Playlist, index }) .First(s => s.Playlist.DisplayName == playlist.DisplayName).index; if (index >= 0 && index > PlayLists.Count - 1) { PlayLists.Add(playlist); } else { PlayLists[index] = playlist; } }; LoadPlayLists(); }
public static void ClearTemp() { foreach (var file in Directory.GetFiles(SongPath)) { try { File.Delete(file); } catch (Exception e) { AeroError.EmitError(e.ToString()); } } }
public static async Task <List <YoutubeResult> > GetYoutubeQuery(string query) { var youtubeResults = new List <YoutubeResult>(); try { string url = string.Format("https://www.youtube.com/results?search_query='{0}'", query); string htmlText = await GetContentFromUrl(url); var html = new HtmlDocument(); html.LoadHtml(htmlText); //File.WriteAllText("test.html", htmlText); var youtubeResultNodes = html.DocumentNode.CssSelect("#dismissable"); if (youtubeResultNodes == null || youtubeResultNodes.Count() == 0) { AeroError.EmitError("No Results found"); return(null); } int youtubeResultCount = youtubeResultNodes.Count(); for (int i = 0; i < youtubeResultCount; i++) { HtmlNode node = youtubeResultNodes.ElementAt(i); var titleNode = node.CssSelect("#video-title"); string YoutubeUrl = titleNode.Count() == 0 ? null : titleNode.First()?.Attributes?.GetKey("href"); string Title = node.CssSelect("#video-title > yt-formatted-string").First().InnerText.Trim(); if (string.IsNullOrEmpty(YoutubeUrl)) { continue; } YoutubeUrl = string.Format("https://www.youtube.com{0}", YoutubeUrl); string ThumbnailImage = node.CssSelect("#img")?.First().Attributes.GetKey("src"); var result = new YoutubeResult { Url = YoutubeUrl, ImgUrl = ThumbnailImage, Title = Title, ImagePath = Path.Join(output, i.ToString() + ".jpg"), }; youtubeResults.Add(result); } var playlistResults = html.DocumentNode.CssSelect("#contents > ytd-playlist-renderer"); Console.WriteLine("playlists count = {0}", playlistResults.Count()); for (int i = 0; i < playlistResults.Count(); i++) { var playlistVideoHeader = playlistResults.ElementAt(i); string YoutubeUrl = playlistVideoHeader.CssSelect("#content > a")?.First()?.Attributes?.GetKey("href"); YoutubeUrl = string.Format("https://www.youtube.com{0}", YoutubeUrl); string thumbnailUrl = playlistVideoHeader.CssSelect("#img")?.First().Attributes.GetKey("src"); if (string.IsNullOrEmpty(YoutubeUrl)) { continue; } string playlistCount = playlistVideoHeader.CssSelect("#overlays > ytd-thumbnail-overlay-side-panel-renderer > yt-formatted-string")?.First().InnerText; var youtubeResult = new YoutubeResult { Url = YoutubeUrl, ImgUrl = thumbnailUrl, Title = playlistVideoHeader.CssSelect("#video-title")?.First()?.Attributes?.GetKey("title") + " PLAYLIST", ImagePath = Path.Join(output, (i + youtubeResultCount).ToString() + ".jpg"), IsPlayList = true, PlayListCount = playlistCount, }; youtubeResults.Add(youtubeResult); } //END OF LOOP await DownloadThumbnails(youtubeResults); } catch (Exception e) { Console.WriteLine(e.ToString()); OnError(e.ToString()); } return(youtubeResults); }