parseSongRun function
- JsonMap run
Parses song run.
Implementation
JsonMap parseSongRun(JsonMap run) {
final text = run['text'];
if (run.containsKey('navigationEndpoint')) {
final item = {
'name': text,
'id': nav(run, NAVIGATION_BROWSE_ID, nullIfAbsent: true),
};
final id = item['id'] as String?;
if (id != null &&
(id.startsWith('MPRE') || id.contains('release_detail'))) {
return {'type': 'album', 'data': item};
} else {
return {'type': 'artist', 'data': item};
}
} else {
final durationReg = RegExp(r'^(\d+:)*\d+:\d+$');
final yearReg = RegExp(r'^\d{4}$');
if (durationReg.hasMatch(text as String)) {
return {'type': 'duration', 'data': text};
} else if (yearReg.hasMatch(text)) {
return {'type': 'year', 'data': text};
} else if (parseViews(text) != null) {
return {'type': 'views', 'data': parseViews(text)};
} else if (!API_RESULT_TYPES.contains(text.toLowerCase())) {
return {
'type': 'artist',
'data': {'name': text, 'id': null},
};
} else {
return {'type': 'other', 'data': null};
}
}
}