blob: 490c51da8d8f046a13821eb270d1af5b6e2328f6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:pmsna1/models/album.dart';
import 'package:pmsna1/models/artist.dart';
class MusicApi {
Uri artistUri(String artistId) => Uri.parse(
'https://musicbrainz.org/ws/2/artist/$artistId?inc=release-groups&fmt=json');
Uri releaseGroupUri(String releaseGroupId) => Uri.parse(
'https://musicbrainz.org/ws/2/release-group/$releaseGroupId?inc=artists&fmt=json');
Future<List<Album>?> getAlvvaysAlbums() async {
String id = '99450990-b24e-4132-bb68-235f8c3e2564';
http.Response result = await http.get(artistUri(id));
var list = jsonDecode(result.body)['release-groups'] as List;
if (result.statusCode != 200) {
return null;
}
return list.map((map) => Album.fromMap(map)).toList();
}
Future<List<Artist>?> getAlbumArtists(String id) async {
http.Response result = await http.get(releaseGroupUri(id));
var list = jsonDecode(result.body)['artist-credit'] as List;
if (result.statusCode != 200) {
return null;
}
return list.map((map) => Artist.fromMap(map["artist"])).toList();
}
}
|