private void UpdatePlaylist_Click(object sender, RoutedEventArgs e) { List <string> playlistId = _database.GetPlaylistId(); GetSongIdTitle getSongIdTitle = new GetSongIdTitle(); List <JsonList> apiSongs = new List <JsonList>(); for (int i = 0; i < playlistId.Count; i++) { string url = $"https://www.youtube.com/playlist?list={playlistId[i]}"; List <JsonList> playlistSongsIds = getSongIdTitle.SongId(url); apiSongs = apiSongs.Concat(playlistSongsIds).ToList(); } var newSongList = apiSongs.Where(x => !Item.Any(z => x.VideoId == z.SongId)).ToList(); if (newSongList.Count > 0) { _database.AddSongs(newSongList, null, false); MessageBox.Show($"{newSongList.Count} songs have been added"); UpdateInterface(); SongGrid.ItemsSource = Item; } else { MessageBox.Show("All playlists are up to date"); } }
private void DownloadBut_Click(object sender, RoutedEventArgs e) { string[] array = UrlTextBox.Text.Split('?'); if (string.IsNullOrEmpty(UrlTextBox.Text)) { MessageBox.Show("Please provide a Url"); return; } if (string.IsNullOrEmpty(DirectoryTextBox.Text)) { MessageBox.Show("Please provide a directory"); return; } if (array[0] != "https://www.youtube.com/watch" && array[0] != "https://www.youtube.com/playlist") { MessageBox.Show("We only support Youtube.com links"); return; } if (array[0] == "https://www.youtube.com/watch") { var result = MessageBox.Show("Do you want to download this one song ?", "Download", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { progressBarSong.Maximum = 1; List <JsonList> songId = new List <JsonList>(); var songIds = UrlTextBox.Text.Split('='); songId.Add(new JsonList { VideoId = songIds[1] }); songDownloads.DownloadSongs(songId, DirectoryTextBox.Text); } return; } if (array[0] == "https://www.youtube.com/playlist") { var result = MessageBox.Show("Do you want to download a song playlist ?", "Download", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { GetSongIdTitle getSongId = new GetSongIdTitle(); List <JsonList> resultList = getSongId.SongId(UrlTextBox.Text); progressBarSong.Maximum = resultList.Count; songDownloads.DownloadSongs(resultList, DirectoryTextBox.Text); } } }
private async void SaveNewSongs_Click(object sender, RoutedEventArgs e) { var array = UrlTextBox.Text.Split('?'); if (string.IsNullOrEmpty(UrlTextBox.Text)) { MessageBox.Show("Please fill in the box"); return; } if (array[0] != "https://www.youtube.com/watch" && array[0] != "https://www.youtube.com/playlist") { MessageBox.Show("We only support Youtube.com links"); return; } if (array[0] == "https://www.youtube.com/watch") { var songIds = UrlTextBox.Text.Split('='); var youtube = new YoutubeClient(); var vid = await youtube.Videos.GetAsync(UrlTextBox.Text); _database.AddSong(songIds[1], vid.Title); MessageBox.Show("Song has been added"); UpdateInterface(); SongGrid.ItemsSource = Item; UrlTextBox.Text = ""; } if (array[0] == "https://www.youtube.com/playlist") { GetSongIdTitle getSong = new GetSongIdTitle(); List <JsonList> songs = getSong.SongId(UrlTextBox.Text); var playlistId = UrlTextBox.Text.Split('='); _database.AddSongs(songs, playlistId[1], true); MessageBox.Show("Songs have been added"); UpdateInterface(); SongGrid.ItemsSource = Item; UrlTextBox.Text = ""; } AddSongsWindow.Visibility = Visibility.Hidden; }