mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-09-29 12:52:13 +02:00
feat(albums): show formatted editorial descriptions
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import 'package:html/dom.dart';
|
||||
import 'package:html/parser.dart' as html;
|
||||
|
||||
/// Editorial text is display-only. Never load embedded media or execute markup.
|
||||
DocumentFragment parseEditorialNotes(String value) {
|
||||
final fragment = html.parseFragment(value);
|
||||
for (final element in fragment.querySelectorAll(
|
||||
'script, style, iframe, object, template',
|
||||
)) {
|
||||
element.remove();
|
||||
}
|
||||
return fragment;
|
||||
}
|
||||
|
||||
String? albumDescriptionFromMetadata(Map<String, dynamic>? metadata) {
|
||||
final notes =
|
||||
metadata?['editorial_notes'] ??
|
||||
metadata?['editorialNotes'] ??
|
||||
metadata?['description'];
|
||||
final candidates = notes is Map
|
||||
? [notes['standard'], notes['short']]
|
||||
: [notes];
|
||||
for (final candidate in candidates) {
|
||||
if (candidate is String &&
|
||||
(parseEditorialNotes(candidate).text ?? '').trim().isNotEmpty) {
|
||||
return candidate.trim();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user