mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
fix: artist page error #1018
This commit is contained in:
parent
27057ea0c8
commit
8cd650b07e
@ -162,4 +162,60 @@ class CustomSpotifyEndpoints {
|
|||||||
result["tracks"].map((track) => Track.fromJson(track)).toList(),
|
result["tracks"].map((track) => Track.fromJson(track)).toList(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<Artist> artist({required String id}) async {
|
||||||
|
final pathQuery = "$_baseUrl/artists/$id";
|
||||||
|
|
||||||
|
final res = await _client.get(
|
||||||
|
Uri.parse(pathQuery),
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json",
|
||||||
|
if (accessToken.isNotEmpty) "authorization": "Bearer $accessToken",
|
||||||
|
"accept": "application/json",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
final data = jsonDecode(res.body);
|
||||||
|
|
||||||
|
return Artist.fromJson(_purifyArtistResponse(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<List<Artist>> relatedArtists({required String id}) async {
|
||||||
|
final pathQuery = "$_baseUrl/artists/$id/related-artists";
|
||||||
|
|
||||||
|
final res = await _client.get(
|
||||||
|
Uri.parse(pathQuery),
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json",
|
||||||
|
if (accessToken.isNotEmpty) "authorization": "Bearer $accessToken",
|
||||||
|
"accept": "application/json",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
final data = jsonDecode(res.body);
|
||||||
|
|
||||||
|
return List.castFrom<dynamic, Artist>(
|
||||||
|
data["artists"]
|
||||||
|
.map((artist) => Artist.fromJson(_purifyArtistResponse(artist)))
|
||||||
|
.toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> _purifyArtistResponse(Map<String, dynamic> data) {
|
||||||
|
if (data["popularity"] != null) {
|
||||||
|
data["popularity"] = data["popularity"].toInt();
|
||||||
|
}
|
||||||
|
if (data["followers"]?["total"] != null) {
|
||||||
|
data["followers"]["total"] = data["followers"]["total"].toInt();
|
||||||
|
}
|
||||||
|
if (data["images"] != null) {
|
||||||
|
data["images"] = data["images"].map((e) {
|
||||||
|
e["height"] = e["height"].toInt();
|
||||||
|
e["width"] = e["width"].toInt();
|
||||||
|
return e;
|
||||||
|
}).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|||||||
import 'package:spotify/spotify.dart';
|
import 'package:spotify/spotify.dart';
|
||||||
import 'package:spotube/hooks/spotify/use_spotify_infinite_query.dart';
|
import 'package:spotube/hooks/spotify/use_spotify_infinite_query.dart';
|
||||||
import 'package:spotube/hooks/spotify/use_spotify_query.dart';
|
import 'package:spotube/hooks/spotify/use_spotify_query.dart';
|
||||||
|
import 'package:spotube/provider/custom_spotify_endpoint_provider.dart';
|
||||||
import 'package:spotube/provider/user_preferences/user_preferences_provider.dart';
|
import 'package:spotube/provider/user_preferences/user_preferences_provider.dart';
|
||||||
import 'package:spotube/services/wikipedia/wikipedia.dart';
|
import 'package:spotube/services/wikipedia/wikipedia.dart';
|
||||||
import 'package:wikipedia_api/wikipedia_api.dart';
|
import 'package:wikipedia_api/wikipedia_api.dart';
|
||||||
@ -15,9 +16,10 @@ class ArtistQueries {
|
|||||||
WidgetRef ref,
|
WidgetRef ref,
|
||||||
String artist,
|
String artist,
|
||||||
) {
|
) {
|
||||||
|
final customSpotify = ref.watch(customSpotifyEndpointProvider);
|
||||||
return useSpotifyQuery<Artist, dynamic>(
|
return useSpotifyQuery<Artist, dynamic>(
|
||||||
"artist-profile/$artist",
|
"artist-profile/$artist",
|
||||||
(spotify) => spotify.artists.get(artist),
|
(spotify) => customSpotify.artist(id: artist),
|
||||||
ref: ref,
|
ref: ref,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -125,10 +127,11 @@ class ArtistQueries {
|
|||||||
WidgetRef ref,
|
WidgetRef ref,
|
||||||
String artist,
|
String artist,
|
||||||
) {
|
) {
|
||||||
|
final customSpotify = ref.watch(customSpotifyEndpointProvider);
|
||||||
return useSpotifyQuery<Iterable<Artist>, dynamic>(
|
return useSpotifyQuery<Iterable<Artist>, dynamic>(
|
||||||
"artist-related-artist-query/$artist",
|
"artist-related-artist-query/$artist",
|
||||||
(spotify) {
|
(spotify) {
|
||||||
return spotify.artists.relatedArtists(artist);
|
return customSpotify.relatedArtists(id: artist);
|
||||||
},
|
},
|
||||||
ref: ref,
|
ref: ref,
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user