From bfe08dc6fa285daef608b637f4bc4096ae663bfd Mon Sep 17 00:00:00 2001 From: NaiJi Date: Mon, 30 Jan 2023 02:46:11 +0400 Subject: [PATCH] feat: Implement artist downloading in Dart --- lib/funkblubber.dart | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/funkblubber.dart b/lib/funkblubber.dart index 5c93bb7..24a9514 100644 --- a/lib/funkblubber.dart +++ b/lib/funkblubber.dart @@ -13,11 +13,37 @@ Future download({ await _downloadAlbum(object, path); return; + case FunkEntity.artist: + await _downloadArtist(object, path); + return; + default: return; } } +Future _downloadArtist( + final FunkObject object, + final String path, +) async { + final response = await Dio().get( + 'https://${object.domain}/api/v1/albums/?' + 'artist=${object.id}&ordering=creation_date&' + 'page=1&page_size=16&scope=all', + ); + + for (final albumResponse in response.data['results']) { + _downloadAlbum( + FunkObject( + domain: object.domain, + id: albumResponse['id'].toString(), + kind: FunkEntity.album, + ), + path, + ); + } +} + Future _downloadAlbum( final FunkObject object, final String path,