This commit is contained in:
Forrest 2026-08-04 16:08:51 -04:00
parent d558aba246
commit 3bd713d667
17 changed files with 1566 additions and 132 deletions

View file

@ -23,6 +23,7 @@ class Song {
this.suffix,
this.size,
this.path,
this.created,
this.starred = false,
this.userRating,
});
@ -46,11 +47,19 @@ class Song {
final String? suffix;
final int? size;
final String? path;
/// ISO8601 date the item was added to the server (`created`), or null.
/// Powers "recently added" sort / "date added" filtering.
final String? created;
final bool starred;
/// 1–5, or null if unrated.
final int? userRating;
/// Parsed form of [created], or null if absent/unparseable.
DateTime? get createdAt =>
created == null ? null : DateTime.tryParse(created!);
factory Song.fromJson(Map<String, dynamic> j) => Song(
id: asString(j['id']) ?? '',
title: asString(j['title']),
@ -69,6 +78,7 @@ class Song {
suffix: asString(j['suffix']),
size: asInt(j['size']),
path: asString(j['path']),
created: asString(j['created']),
starred: j['starred'] != null,
userRating: asInt(j['userRating']),
);
@ -93,6 +103,7 @@ class Song {
if (suffix != null) 'suffix': suffix,
if (size != null) 'size': size,
if (path != null) 'path': path,
if (created != null) 'created': created,
if (starred) 'starred': true,
if (userRating != null) 'userRating': userRating,
};
@ -109,6 +120,7 @@ class Album {
this.duration,
this.year,
this.genre,
this.created,
this.starred = false,
this.userRating,
this.songs = const [],
@ -123,12 +135,19 @@ class Album {
final int? duration;
final int? year;
final String? genre;
/// ISO8601 date the album was added to the server (`created`), or null.
final String? created;
final bool starred;
final int? userRating;
/// Populated only by `getAlbum`.
final List<Song> songs;
/// Parsed form of [created], or null if absent/unparseable.
DateTime? get createdAt =>
created == null ? null : DateTime.tryParse(created!);
factory Album.fromJson(Map<String, dynamic> j) => Album(
id: asString(j['id']) ?? '',
name: asString(j['name']) ?? asString(j['album']),
@ -139,6 +158,7 @@ class Album {
duration: asInt(j['duration']),
year: asInt(j['year']),
genre: asString(j['genre']),
created: asString(j['created']),
starred: j['starred'] != null,
userRating: asInt(j['userRating']),
songs: oneOrMany(j['song'], Song.fromJson),