Skip to content

Commit

Permalink
Update youtube api versions, fix qobuz changes and other minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekYang2 committed Oct 5, 2024
1 parent 564e438 commit 06b0b26
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 23 deletions.
4 changes: 2 additions & 2 deletions FluentDL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
<PackageReference Include="SpotifyAPI.Web" Version="7.1.1" />
<PackageReference Include="TagLibSharp" Version="2.3.0" />
<PackageReference Include="WinUIEx" Version="2.3.2" />
<PackageReference Include="YoutubeExplode" Version="6.4.1" />
<PackageReference Include="YouTubeMusicAPI" Version="1.3.0" />
<PackageReference Include="YoutubeExplode" Version="6.4.2" />
<PackageReference Include="YouTubeMusicAPI" Version="1.3.1" />
</ItemGroup>

<ItemGroup>
Expand Down
32 changes: 16 additions & 16 deletions Services/QobuzApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static async Task GeneralSearch(ObservableCollection<SongSearchObject> 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)
{
Expand Down Expand Up @@ -100,7 +100,7 @@ public static async Task AdvancedSearch(ObservableCollection<SongSearchObject> 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

Expand Down Expand Up @@ -129,7 +129,7 @@ public static async Task AdvancedSearch(ObservableCollection<SongSearchObject> 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;

Expand Down Expand Up @@ -179,7 +179,7 @@ public static async Task AdvancedSearch(ObservableCollection<SongSearchObject> 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

Expand Down Expand Up @@ -221,7 +221,7 @@ public static async Task AdvancedSearch(ObservableCollection<SongSearchObject> 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)
Expand Down Expand Up @@ -269,14 +269,14 @@ public static async Task AddTracksFromLink(ObservableCollection<SongSearchObject

if (isTrack)
{
var track = apiService.GetTrack(id);
var track = apiService.GetTrack(id, withAuth: true);
itemSource.Add(ConvertSongSearchObject(track));

statusUpdate?.Invoke(InfoBarSeverity.Success, $"<b>Qobuz</b> Loaded track <a href=\"{url}\">{track.Title}</a>"); // 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)
{
Expand All @@ -298,7 +298,7 @@ public static async Task AddTracksFromLink(ObservableCollection<SongSearchObject
}
else if (isPlaylist)
{
var playlist = await Task.Run(() => 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)
{
Expand All @@ -312,7 +312,7 @@ public static async Task AddTracksFromLink(ObservableCollection<SongSearchObject
return;
}

itemSource.Add(await Task.Run(() => 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, $"<b>Qobuz</b> Loaded playlist <a href='{url}'>{playlist.Name}</a>"); // Show a success message
Expand Down Expand Up @@ -380,7 +380,7 @@ public static SongSearchObject CreateSongSearchObject(Track track, Album album)

public static async Task<Track> GetInternalTrack(string id)
{
return await Task.Run(() => apiService.GetTrack(id));
return await Task.Run(() => apiService.GetTrack(id, withAuth: true));
}

public static async Task<SongSearchObject?> GetTrackAsync(int? id, CancellationToken token = default)
Expand All @@ -391,7 +391,7 @@ public static async Task<Track> GetInternalTrack(string id)

public static async Task<SongSearchObject?> 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;
Expand All @@ -408,7 +408,7 @@ public static async Task<Track> 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;
Expand All @@ -429,7 +429,7 @@ public static async Task<Track> 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)
Expand Down Expand Up @@ -470,7 +470,7 @@ public static async Task<Track> 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

Expand All @@ -494,7 +494,7 @@ public static async Task<Track> 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;

Expand Down Expand Up @@ -525,7 +525,7 @@ public static async Task<Track> 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

Expand Down
9 changes: 7 additions & 2 deletions Services/YoutubeApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public static async Task AdvancedSearch(ObservableCollection<SongSearchObject> i

public static async Task AddTracksFromLink(ObservableCollection<SongSearchObject> 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);
Expand Down Expand Up @@ -343,13 +343,18 @@ public static async Task AddTracksFromLink(ObservableCollection<SongSearchObject
}
}

if (url.StartsWith("https://www.youtube.com/playlist?") || url.StartsWith("https://music.youtube.com/playlist?"))
if (url.StartsWith("https://www.youtube.com/playlist?") || url.StartsWith("https://youtube.com/playlist?") || url.StartsWith("https://music.youtube.com/playlist?"))
{
// remove &si= and everything after in the url if it exists
url = url.Split("&si=")[0];

var playlistName = (await youtube.Playlists.GetAsync(url)).Title;

// Show a permanent, loading message
statusUpdate?.Invoke(InfoBarSeverity.Informational, $"<b>YouTube</b> Loading playlist <a href='{url}'>{playlistName}</a>", -1);

itemSource.Clear(); // Clear the item source

try
{
await foreach (var playlistVideo in youtube.Playlists.GetVideosAsync(url, token))
Expand Down
2 changes: 1 addition & 1 deletion Views/QueuePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ private async Task DownloadSong(SongSearchObject? songObj)
}
}

ShowInfoBarPermanent(InfoBarSeverity.Informational, $"Saving <a href='{ApiHelper.GetUrl(songObj)}'>{songObj.Title}</a> to <a href='{directory}'>{Path.GetDirectoryName(directory)}</a>", title: "Download in Progress");
ShowInfoBarPermanent(InfoBarSeverity.Informational, $"Saving <a href='{ApiHelper.GetUrl(songObj)}'>{songObj.Title}</a> to <a href='{directory}'>{directory}</a>", title: "Download in Progress");

InfobarProgress.Visibility = Visibility.Visible; // Show the infobar's progress bar

Expand Down
3 changes: 2 additions & 1 deletion Views/Search.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ private async void SearchBox_OnQuerySubmitted(AutoSuggestBox sender, AutoSuggest
}
};


if (generalQuery.StartsWith("https://open.spotify.com/"))
{
await SpotifyApi.AddTracksFromLink((ObservableCollection<SongSearchObject>)CustomListView.ItemsSource, generalQuery, cancellationTokenSource.Token, statusUpdate);
Expand All @@ -429,7 +430,7 @@ private async void SearchBox_OnQuerySubmitted(AutoSuggestBox sender, AutoSuggest
{
await QobuzApi.AddTracksFromLink((ObservableCollection<SongSearchObject>)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<SongSearchObject>)CustomListView.ItemsSource, generalQuery, cancellationTokenSource.Token, statusUpdate);
}
Expand Down
2 changes: 1 addition & 1 deletion Views/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(SettingsViewModel.SearchSource);
var searchSource = await localSettings.ReadSettingAsync<string>(SettingsViewModel.SearchSource) ?? "Deezer";
foreach (ComboBoxItem cbi in SearchSourceComboBox.Items)
{
if (cbi.Content as string == searchSource)
Expand Down

0 comments on commit 06b0b26

Please sign in to comment.