From 06b0b26ccfe522e4e071b3674396027bb9feb7c0 Mon Sep 17 00:00:00 2001 From: Derek Yang <115889767+DerekYang2@users.noreply.github.com> Date: Sat, 5 Oct 2024 12:08:30 -0400 Subject: [PATCH] Update youtube api versions, fix qobuz changes and other minor bugs --- FluentDL.csproj | 4 ++-- Services/QobuzApi.cs | 32 ++++++++++++++++---------------- Services/YoutubeApi.cs | 9 +++++++-- Views/QueuePage.xaml.cs | 2 +- Views/Search.xaml.cs | 3 ++- Views/SettingsPage.xaml.cs | 2 +- 6 files changed, 29 insertions(+), 23 deletions(-) diff --git a/FluentDL.csproj b/FluentDL.csproj index da4036f..f43ed40 100644 --- a/FluentDL.csproj +++ b/FluentDL.csproj @@ -50,8 +50,8 @@ - - + + diff --git a/Services/QobuzApi.cs b/Services/QobuzApi.cs index d541777..1438087 100644 --- a/Services/QobuzApi.cs +++ b/Services/QobuzApi.cs @@ -59,7 +59,7 @@ public static async Task GeneralSearch(ObservableCollection it return; } - var results = await Task.Run(() => apiService.SearchTracks(query, limit), token); + var results = await Task.Run(() => apiService.SearchTracks(query, limit, withAuth: true), token); if (results == null || results.Tracks == null) { @@ -100,7 +100,7 @@ public static async Task AdvancedSearch(ObservableCollection i if (!string.IsNullOrWhiteSpace(albumName)) { - var albumResults = await Task.Run(() => apiService.SearchAlbums(albumName, 5), token); + var albumResults = await Task.Run(() => apiService.SearchAlbums(albumName, 5, withAuth: true), token); if (token.IsCancellationRequested) return; // Check if task is cancelled @@ -129,7 +129,7 @@ public static async Task AdvancedSearch(ObservableCollection i if (oneArtistMatch && CloseMatch(albumName, album.Title)) { - var fullAlbumObj = await Task.Run(() => apiService.GetAlbum(album.Id), token); + var fullAlbumObj = await Task.Run(() => apiService.GetAlbum(album.Id, withAuth: true), token); if (fullAlbumObj == null || fullAlbumObj.Tracks == null || fullAlbumObj.Tracks.Items.Count == 0) continue; @@ -179,7 +179,7 @@ public static async Task AdvancedSearch(ObservableCollection i do // Iterate through all tracks of the artist { - var result = await Task.Run(() => apiService.SearchTracks(artistName + " " + trackName, 10, offset), token); + var result = await Task.Run(() => apiService.SearchTracks(artistName + " " + trackName, 10, offset, withAuth: true), token); if (token.IsCancellationRequested) return; // Check if task is cancelled @@ -221,7 +221,7 @@ public static async Task AdvancedSearch(ObservableCollection i do { - var result = await Task.Run(() => apiService.SearchTracks(artistName, 10, offset), token); + var result = await Task.Run(() => apiService.SearchTracks(artistName, 10, offset, withAuth: true), token); if (token.IsCancellationRequested) return; // Check if task is cancelled if (result.Tracks != null && result.Tracks.Items.Count > 0) @@ -269,14 +269,14 @@ public static async Task AddTracksFromLink(ObservableCollectionQobuz Loaded track {track.Title}"); // Show a success message } else if (isAlbum) { - var album = await Task.Run(() => apiService.GetAlbum(id), token); + var album = await Task.Run(() => apiService.GetAlbum(id, withAuth: true), token); if (album.Tracks != null && album.Tracks.Items.Count > 0) { @@ -298,7 +298,7 @@ public static async Task AddTracksFromLink(ObservableCollection apiService.GetPlaylist(id, withAuth: IsInitialized), token); + var playlist = await Task.Run(() => apiService.GetPlaylist(id, withAuth: true), token); if (playlist.Tracks != null && playlist.Tracks.Items.Count > 0) { @@ -312,7 +312,7 @@ public static async Task AddTracksFromLink(ObservableCollection ConvertSongSearchObject(apiService.GetTrack(track.Id.ToString())), token)); + itemSource.Add(await Task.Run(() => ConvertSongSearchObject(apiService.GetTrack(track.Id.ToString(), withAuth: true)), token)); } statusUpdate?.Invoke(InfoBarSeverity.Success, $"Qobuz Loaded playlist {playlist.Name}"); // Show a success message @@ -380,7 +380,7 @@ public static SongSearchObject CreateSongSearchObject(Track track, Album album) public static async Task GetInternalTrack(string id) { - return await Task.Run(() => apiService.GetTrack(id)); + return await Task.Run(() => apiService.GetTrack(id, withAuth: true)); } public static async Task GetTrackAsync(int? id, CancellationToken token = default) @@ -391,7 +391,7 @@ public static async Task GetInternalTrack(string id) public static async Task GetTrackAsync(string id, CancellationToken token = default) { - var track = await Task.Run(() => apiService.GetTrack(id), token); + var track = await Task.Run(() => apiService.GetTrack(id, withAuth: true), token); if (track == null) { return null; @@ -408,7 +408,7 @@ public static async Task GetInternalTrack(string id) public static SongSearchObject? GetTrack(string id) { - var track = apiService.GetTrack(id); + var track = apiService.GetTrack(id, withAuth: true); if (track == null) { return null; @@ -429,7 +429,7 @@ public static async Task GetInternalTrack(string id) do { - var result = await Task.Run(() => apiService.SearchTracks(query, 5, offset), token); // Search through chunks of 5 tracks + var result = await Task.Run(() => apiService.SearchTracks(query, 5, offset, withAuth: true), token); // Search through chunks of 5 tracks if (token.IsCancellationRequested) return null; if (result.Tracks == null || result.Tracks.Items.Count == 0) @@ -470,7 +470,7 @@ public static async Task GetInternalTrack(string id) var trackName = songObj.Title; // Search by album - var albumResults = await Task.Run(() => apiService.SearchAlbums(albumName, 5), token); + var albumResults = await Task.Run(() => apiService.SearchAlbums(albumName, 5, withAuth: true), token); if (token.IsCancellationRequested) return null; // Check if task is cancelled @@ -494,7 +494,7 @@ public static async Task GetInternalTrack(string id) if (oneArtistMatch && CloseMatch(albumName, album.Title)) // Album close match { - var fullAlbumObj = await Task.Run(() => apiService.GetAlbum(album.Id), token); + var fullAlbumObj = await Task.Run(() => apiService.GetAlbum(album.Id, withAuth: true), token); if (fullAlbumObj == null || fullAlbumObj.Tracks == null || fullAlbumObj.Tracks.Items.Count == 0) continue; @@ -525,7 +525,7 @@ public static async Task GetInternalTrack(string id) } // Try searching without album, same as above - var searchResult = await Task.Run(() => apiService.SearchTracks(query, 10), token); + var searchResult = await Task.Run(() => apiService.SearchTracks(query, 10, withAuth: true), token); if (token.IsCancellationRequested) return null; // Check if task is cancelled diff --git a/Services/YoutubeApi.cs b/Services/YoutubeApi.cs index 1e9d364..18ea9e1 100644 --- a/Services/YoutubeApi.cs +++ b/Services/YoutubeApi.cs @@ -311,7 +311,7 @@ public static async Task AdvancedSearch(ObservableCollection i public static async Task AddTracksFromLink(ObservableCollection itemSource, string url, CancellationToken token, Search.UrlStatusUpdateCallback? statusUpdate) { - if (url.StartsWith("https://www.youtube.com/watch?")) + if (url.StartsWith("https://www.youtube.com/watch?") || url.StartsWith("https://youtube.com/watch?")) // Youtube video { var video = await youtube.Videos.GetAsync(url); var songObj = await ConvertSongSearchObject(video); @@ -343,13 +343,18 @@ public static async Task AddTracksFromLink(ObservableCollectionYouTube Loading playlist {playlistName}", -1); + itemSource.Clear(); // Clear the item source + try { await foreach (var playlistVideo in youtube.Playlists.GetVideosAsync(url, token)) diff --git a/Views/QueuePage.xaml.cs b/Views/QueuePage.xaml.cs index 2f662f3..98b64e9 100644 --- a/Views/QueuePage.xaml.cs +++ b/Views/QueuePage.xaml.cs @@ -448,7 +448,7 @@ private async Task DownloadSong(SongSearchObject? songObj) } } - ShowInfoBarPermanent(InfoBarSeverity.Informational, $"Saving {songObj.Title} to {Path.GetDirectoryName(directory)}", title: "Download in Progress"); + ShowInfoBarPermanent(InfoBarSeverity.Informational, $"Saving {songObj.Title} to {directory}", title: "Download in Progress"); InfobarProgress.Visibility = Visibility.Visible; // Show the infobar's progress bar diff --git a/Views/Search.xaml.cs b/Views/Search.xaml.cs index 70bd6b3..d10be0b 100644 --- a/Views/Search.xaml.cs +++ b/Views/Search.xaml.cs @@ -411,6 +411,7 @@ private async void SearchBox_OnQuerySubmitted(AutoSuggestBox sender, AutoSuggest } }; + if (generalQuery.StartsWith("https://open.spotify.com/")) { await SpotifyApi.AddTracksFromLink((ObservableCollection)CustomListView.ItemsSource, generalQuery, cancellationTokenSource.Token, statusUpdate); @@ -429,7 +430,7 @@ private async void SearchBox_OnQuerySubmitted(AutoSuggestBox sender, AutoSuggest { await QobuzApi.AddTracksFromLink((ObservableCollection)CustomListView.ItemsSource, generalQuery, cancellationTokenSource.Token, statusUpdate); } - else if (generalQuery.StartsWith("https://www.youtube.com/") || generalQuery.StartsWith("https://music.youtube.com/")) + else if (generalQuery.StartsWith("https://www.youtube.com/") || generalQuery.StartsWith("https://youtube.com/") || generalQuery.StartsWith("https://music.youtube.com/")) { await YoutubeApi.AddTracksFromLink((ObservableCollection)CustomListView.ItemsSource, generalQuery, cancellationTokenSource.Token, statusUpdate); } diff --git a/Views/SettingsPage.xaml.cs b/Views/SettingsPage.xaml.cs index e0f0e09..2bfdc20 100644 --- a/Views/SettingsPage.xaml.cs +++ b/Views/SettingsPage.xaml.cs @@ -92,7 +92,7 @@ private async void SettingsPage_Loaded(object sender, RoutedEventArgs e) QobuzTokenInput.LostFocus += QobuzTokenInput_OnLostFocus; // Set source combo box - var searchSource = await localSettings.ReadSettingAsync(SettingsViewModel.SearchSource); + var searchSource = await localSettings.ReadSettingAsync(SettingsViewModel.SearchSource) ?? "Deezer"; foreach (ComboBoxItem cbi in SearchSourceComboBox.Items) { if (cbi.Content as string == searchSource)