Split discography, copy arl button, small fixes
This commit is contained in:
parent
4e5e3a3059
commit
b9004c3004
7 changed files with 227 additions and 102 deletions
|
@ -31,10 +31,13 @@ class Track {
|
|||
Lyrics lyrics;
|
||||
bool favorite;
|
||||
|
||||
//TODO: Not in DB
|
||||
int diskNumber;
|
||||
|
||||
List<dynamic> playbackDetails;
|
||||
|
||||
Track({this.id, this.title, this.duration, this.album, this.playbackDetails, this.albumArt,
|
||||
this.artists, this.trackNumber, this.offline, this.lyrics, this.favorite});
|
||||
this.artists, this.trackNumber, this.offline, this.lyrics, this.favorite, this.diskNumber});
|
||||
|
||||
String get artistString => artists.map<String>((art) => art.name).join(', ');
|
||||
String get durationString => "${duration.inMinutes}:${duration.inSeconds.remainder(60).toString().padLeft(2, '0')}";
|
||||
|
@ -130,7 +133,8 @@ class Track {
|
|||
trackNumber: int.parse((json['TRACK_NUMBER']??'0').toString()),
|
||||
playbackDetails: [json['MD5_ORIGIN'], json['MEDIA_VERSION']],
|
||||
lyrics: Lyrics(id: json['LYRICS_ID'].toString()),
|
||||
favorite: favorite
|
||||
favorite: favorite,
|
||||
diskNumber: int.parse(json['DISK_NUMBER']??'1')
|
||||
);
|
||||
}
|
||||
Map<String, dynamic> toSQL({off = false}) => {
|
||||
|
@ -164,6 +168,12 @@ class Track {
|
|||
Map<String, dynamic> toJson() => _$TrackToJson(this);
|
||||
}
|
||||
|
||||
enum AlbumType {
|
||||
ALBUM,
|
||||
SINGLE,
|
||||
FEATURED
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class Album {
|
||||
String id;
|
||||
|
@ -174,8 +184,10 @@ class Album {
|
|||
int fans;
|
||||
bool offline; //If the album is offline, or just saved in db as metadata
|
||||
bool library;
|
||||
//TODO: Not in DB
|
||||
AlbumType type;
|
||||
|
||||
Album({this.id, this.title, this.art, this.artists, this.tracks, this.fans, this.offline, this.library});
|
||||
Album({this.id, this.title, this.art, this.artists, this.tracks, this.fans, this.offline, this.library, this.type});
|
||||
|
||||
String get artistString => artists.map<String>((art) => art.name).join(', ');
|
||||
Duration get duration => Duration(seconds: tracks.fold(0, (v, t) => v += t.duration.inSeconds));
|
||||
|
@ -183,15 +195,22 @@ class Album {
|
|||
String get fansString => NumberFormat.compact().format(fans);
|
||||
|
||||
//JSON
|
||||
factory Album.fromPrivateJson(Map<dynamic, dynamic> json, {Map<dynamic, dynamic> songsJson = const {}, bool library = false}) => Album(
|
||||
id: json['ALB_ID'].toString(),
|
||||
title: json['ALB_TITLE'],
|
||||
art: ImageDetails.fromPrivateString(json['ALB_PICTURE']),
|
||||
artists: (json['ARTISTS']??[json]).map<Artist>((dynamic art) => Artist.fromPrivateJson(art)).toList(),
|
||||
tracks: (songsJson['data']??[]).map<Track>((dynamic track) => Track.fromPrivateJson(track)).toList(),
|
||||
fans: json['NB_FAN'],
|
||||
library: library
|
||||
);
|
||||
factory Album.fromPrivateJson(Map<dynamic, dynamic> json, {Map<dynamic, dynamic> songsJson = const {}, bool library = false}) {
|
||||
AlbumType type = AlbumType.ALBUM;
|
||||
if (json['TYPE'] != null && json['TYPE'].toString() == "0") type = AlbumType.SINGLE;
|
||||
if (json['ROLE_ID'] == 5) type = AlbumType.FEATURED;
|
||||
|
||||
return Album(
|
||||
id: json['ALB_ID'].toString(),
|
||||
title: json['ALB_TITLE'],
|
||||
art: ImageDetails.fromPrivateString(json['ALB_PICTURE']),
|
||||
artists: (json['ARTISTS']??[json]).map<Artist>((dynamic art) => Artist.fromPrivateJson(art)).toList(),
|
||||
tracks: (songsJson['data']??[]).map<Track>((dynamic track) => Track.fromPrivateJson(track)).toList(),
|
||||
fans: json['NB_FAN'],
|
||||
library: library,
|
||||
type: type
|
||||
);
|
||||
}
|
||||
Map<String, dynamic> toSQL({off = false}) => {
|
||||
'id': id,
|
||||
'title': title,
|
||||
|
|
|
@ -30,6 +30,7 @@ Track _$TrackFromJson(Map<String, dynamic> json) {
|
|||
? null
|
||||
: Lyrics.fromJson(json['lyrics'] as Map<String, dynamic>),
|
||||
favorite: json['favorite'] as bool,
|
||||
diskNumber: json['diskNumber'] as int,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -44,6 +45,7 @@ Map<String, dynamic> _$TrackToJson(Track instance) => <String, dynamic>{
|
|||
'offline': instance.offline,
|
||||
'lyrics': instance.lyrics,
|
||||
'favorite': instance.favorite,
|
||||
'diskNumber': instance.diskNumber,
|
||||
'playbackDetails': instance.playbackDetails,
|
||||
};
|
||||
|
||||
|
@ -65,6 +67,7 @@ Album _$AlbumFromJson(Map<String, dynamic> json) {
|
|||
fans: json['fans'] as int,
|
||||
offline: json['offline'] as bool,
|
||||
library: json['library'] as bool,
|
||||
type: _$enumDecodeNullable(_$AlbumTypeEnumMap, json['type']),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -77,8 +80,47 @@ Map<String, dynamic> _$AlbumToJson(Album instance) => <String, dynamic>{
|
|||
'fans': instance.fans,
|
||||
'offline': instance.offline,
|
||||
'library': instance.library,
|
||||
'type': _$AlbumTypeEnumMap[instance.type],
|
||||
};
|
||||
|
||||
T _$enumDecode<T>(
|
||||
Map<T, dynamic> enumValues,
|
||||
dynamic source, {
|
||||
T unknownValue,
|
||||
}) {
|
||||
if (source == null) {
|
||||
throw ArgumentError('A value must be provided. Supported values: '
|
||||
'${enumValues.values.join(', ')}');
|
||||
}
|
||||
|
||||
final value = enumValues.entries
|
||||
.singleWhere((e) => e.value == source, orElse: () => null)
|
||||
?.key;
|
||||
|
||||
if (value == null && unknownValue == null) {
|
||||
throw ArgumentError('`$source` is not one of the supported values: '
|
||||
'${enumValues.values.join(', ')}');
|
||||
}
|
||||
return value ?? unknownValue;
|
||||
}
|
||||
|
||||
T _$enumDecodeNullable<T>(
|
||||
Map<T, dynamic> enumValues,
|
||||
dynamic source, {
|
||||
T unknownValue,
|
||||
}) {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
return _$enumDecode<T>(enumValues, source, unknownValue: unknownValue);
|
||||
}
|
||||
|
||||
const _$AlbumTypeEnumMap = {
|
||||
AlbumType.ALBUM: 'ALBUM',
|
||||
AlbumType.SINGLE: 'SINGLE',
|
||||
AlbumType.FEATURED: 'FEATURED',
|
||||
};
|
||||
|
||||
Artist _$ArtistFromJson(Map<String, dynamic> json) {
|
||||
return Artist(
|
||||
id: json['id'] as String,
|
||||
|
@ -287,38 +329,6 @@ Map<String, dynamic> _$HomePageSectionToJson(HomePageSection instance) =>
|
|||
'items': HomePageSection._homePageItemToJson(instance.items),
|
||||
};
|
||||
|
||||
T _$enumDecode<T>(
|
||||
Map<T, dynamic> enumValues,
|
||||
dynamic source, {
|
||||
T unknownValue,
|
||||
}) {
|
||||
if (source == null) {
|
||||
throw ArgumentError('A value must be provided. Supported values: '
|
||||
'${enumValues.values.join(', ')}');
|
||||
}
|
||||
|
||||
final value = enumValues.entries
|
||||
.singleWhere((e) => e.value == source, orElse: () => null)
|
||||
?.key;
|
||||
|
||||
if (value == null && unknownValue == null) {
|
||||
throw ArgumentError('`$source` is not one of the supported values: '
|
||||
'${enumValues.values.join(', ')}');
|
||||
}
|
||||
return value ?? unknownValue;
|
||||
}
|
||||
|
||||
T _$enumDecodeNullable<T>(
|
||||
Map<T, dynamic> enumValues,
|
||||
dynamic source, {
|
||||
T unknownValue,
|
||||
}) {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
return _$enumDecode<T>(enumValues, source, unknownValue: unknownValue);
|
||||
}
|
||||
|
||||
const _$HomePageSectionLayoutEnumMap = {
|
||||
HomePageSectionLayout.ROW: 'ROW',
|
||||
};
|
||||
|
|
|
@ -511,7 +511,7 @@ class Download {
|
|||
if (settings.albumFolder) {
|
||||
String folderName = track.album.title.replaceAll(sanitize, '');
|
||||
//Add disk number
|
||||
if (settings.albumDiscFolder) folderName += ' - Disk ${rawTrack["DISK_NUMBER"]}';
|
||||
if (settings.albumDiscFolder) folderName += ' - Disk ${track.diskNumber}';
|
||||
|
||||
this.path = p.join(this.path, folderName);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue