You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.4 KiB

class SongModel {
final String mid;
final String? id;
final String name;
final String artist;
final String album;
final int duration; // 毫秒
final String? albumPic;
SongModel({
required this.mid,
this.id,
required this.name,
required this.artist,
required this.album,
required this.duration,
this.albumPic,
});
factory SongModel.fromJson(Map<String, dynamic> json) {
return SongModel(
mid: json['mid'] ?? '',
id: json['id'],
name: json['name'] ?? '',
artist: json['artist'] ?? json['singer'] ?? '',
album: json['album'] ?? '',
duration: json['duration'] ?? 0,
albumPic: json['albumPic'] ?? json['pic'] ?? json['coverUri'],
);
}
Map<String, dynamic> toJson() {
return {
'mid': mid,
'id': id,
'name': name,
'artist': artist,
'singer': artist, // 兼容性字段
'album': album,
'duration': duration,
'albumPic': albumPic,
'pic': albumPic, // 兼容性字段
'coverUri': albumPic, // 兼容性字段
};
}
@override
String toString() {
return 'SongModel(mid: $mid, name: $name, artist: $artist, album: $album, duration: $duration)';
}
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is SongModel && other.mid == mid;
}
@override
int get hashCode => mid.hashCode;
}