-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support episode
s when retrieving items from playlist
#181
Comments
This kind of breaks the current BasePage(this._paging, ParserFunction<T> pageItemParser,
[Object? pageContainer]) {
_items = _paging.itemsNative!.map(pageItemParser);
_container = pageContainer;
}
BasePage.fromParserMap(
this._paging, Map<String, ParserFunction<dynamic>> parserMap,
[Object? pageContainer]) {
_items = _paging.itemsNative!.map((item) {
// so according to the spotify documentation,
// a json key `track` can either be a `Track` or `Episode` object.
// Distinguishing between the two types is therefore only
// possible by checking their `type` and therefore
// run the according parser through that json object.
var type = item["track"]["type"] as String; // <-- this is the line I don't like, needs further discussion
if (parserMap.containsKey(type)) {
return parserMap[type]!(item);
}
throw TypeError();
});
_container = pageContainer;
}
...
class Page ... {
Page.fromParserMap(
Paging<T> paging, Map<String, ParserFunction<dynamic>> parserMap,
[Object? pageContainer])
: super.fromParserMap(paging, parserMap);
}
...
/// Handles retrieval of a page with multiple types
class MultiPage extends SinglePages<dynamic, Page<dynamic>> with OffsetStrategy<Page<dynamic>> {
final Map<String, ParserFunction<dynamic>> _pageMappers;
MultiPage(SpotifyApiBase api, String path, this._pageMappers)
: super(api, path, null, null);
@override
Future<Page<dynamic>> getPage(int limit, [int offset = 0]) async {
var pathDelimiter = _path.contains('?') ? '&' : '?';
var newPath = '$_path${pathDelimiter}limit=$limit&offset=$offset';
var jsonString = await _api._get(newPath);
var paging = Paging.fromJson(json.decode(jsonString));
return Page.fromParserMap(paging, _pageMappers);
}
} And finally, distinguishing types in this new var items = spotify.playlists.getItemsByPlaylistId('...');
var page = (await items.first()).items;
expect(page?.first?.runtimeType, Track); I marked the line, where we could discuss this a bit more @rinukkusu . |
So far only
track
s are retrieved fromgetTracksByPlaylistId
. Spotify however also returnsepisode
s.The text was updated successfully, but these errors were encountered: