mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-12 23:45:18 +00:00
102 lines
2.7 KiB
Dart
102 lines
2.7 KiB
Dart
import 'package:hetu_script/hetu_script.dart';
|
|
import 'package:hetu_script/values.dart';
|
|
import 'package:spotube/models/metadata/metadata.dart';
|
|
|
|
class MetadataPluginArtistEndpoint {
|
|
final Hetu hetu;
|
|
MetadataPluginArtistEndpoint(this.hetu);
|
|
|
|
HTInstance get hetuMetadataArtist =>
|
|
(hetu.fetch("metadataPlugin") as HTInstance).memberGet("artist")
|
|
as HTInstance;
|
|
|
|
Future<SpotubeFullArtistObject> getArtist(String id) async {
|
|
final raw = await hetuMetadataArtist
|
|
.invoke("getArtist", positionalArgs: [id]) as Map;
|
|
|
|
return SpotubeFullArtistObject.fromJson(
|
|
raw.cast<String, dynamic>(),
|
|
);
|
|
}
|
|
|
|
Future<SpotubePaginationResponseObject<SpotubeFullTrackObject>> topTracks(
|
|
String id, {
|
|
int? offset,
|
|
int? limit,
|
|
}) async {
|
|
final raw = await hetuMetadataArtist.invoke(
|
|
"topTracks",
|
|
positionalArgs: [id],
|
|
namedArgs: {
|
|
"offset": offset,
|
|
"limit": limit,
|
|
}..removeWhere((key, value) => value == null),
|
|
) as Map;
|
|
|
|
return SpotubePaginationResponseObject<SpotubeFullTrackObject>.fromJson(
|
|
raw.cast<String, dynamic>(),
|
|
(Map json) => SpotubeFullTrackObject.fromJson(
|
|
json.cast<String, dynamic>(),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<SpotubePaginationResponseObject<SpotubeSimpleAlbumObject>> albums(
|
|
String id, {
|
|
int? offset,
|
|
int? limit,
|
|
}) async {
|
|
final raw = await hetuMetadataArtist.invoke(
|
|
"albums",
|
|
positionalArgs: [id],
|
|
namedArgs: {
|
|
"offset": offset,
|
|
"limit": limit,
|
|
}..removeWhere((key, value) => value == null),
|
|
) as Map;
|
|
|
|
return SpotubePaginationResponseObject<SpotubeSimpleAlbumObject>.fromJson(
|
|
raw.cast<String, dynamic>(),
|
|
(Map json) => SpotubeSimpleAlbumObject.fromJson(
|
|
json.cast<String, dynamic>(),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> save(List<String> ids) async {
|
|
await hetuMetadataArtist.invoke(
|
|
"save",
|
|
positionalArgs: [ids],
|
|
);
|
|
}
|
|
|
|
Future<void> unsave(List<String> ids) async {
|
|
await hetuMetadataArtist.invoke(
|
|
"unsave",
|
|
positionalArgs: [ids],
|
|
);
|
|
}
|
|
|
|
Future<SpotubePaginationResponseObject<SpotubeFullArtistObject>> related(
|
|
String id, {
|
|
int? offset,
|
|
int? limit,
|
|
}) async {
|
|
final raw = await hetuMetadataArtist.invoke(
|
|
"related",
|
|
positionalArgs: [id],
|
|
namedArgs: {
|
|
"offset": offset,
|
|
"limit": limit ?? 20,
|
|
}..removeWhere((key, value) => value == null),
|
|
) as Map;
|
|
|
|
return SpotubePaginationResponseObject<SpotubeFullArtistObject>.fromJson(
|
|
raw.cast<String, dynamic>(),
|
|
(Map json) => SpotubeFullArtistObject.fromJson(
|
|
json.cast<String, dynamic>(),
|
|
),
|
|
);
|
|
}
|
|
}
|