Initial commit
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
class Song {
|
||||
final int? id;
|
||||
final String titel;
|
||||
final String kuenstler;
|
||||
final String album;
|
||||
final int dauerSekunden;
|
||||
final String dateiPfad;
|
||||
final String? coverPfad;
|
||||
final int groesseBytes;
|
||||
final bool istHeruntergeladen;
|
||||
final String hinzugefuegtAm;
|
||||
final String downloadQuelle; // "local", "youtube"
|
||||
int? zuletztPosition; // Sekunden, für Wiederaufnahme
|
||||
|
||||
Song({
|
||||
this.id,
|
||||
required this.titel,
|
||||
required this.kuenstler,
|
||||
this.album = '',
|
||||
required this.dauerSekunden,
|
||||
required this.dateiPfad,
|
||||
this.coverPfad,
|
||||
this.groesseBytes = 0,
|
||||
this.istHeruntergeladen = false,
|
||||
String? hinzugefuegtAm,
|
||||
this.downloadQuelle = 'local',
|
||||
this.zuletztPosition,
|
||||
}) : hinzugefuegtAm = hinzugefuegtAm ?? DateTime.now().toIso8601String();
|
||||
|
||||
Map<String, dynamic> toMap() => {
|
||||
'id': id,
|
||||
'titel': titel,
|
||||
'kuenstler': kuenstler,
|
||||
'album': album,
|
||||
'dauer_sekunden': dauerSekunden,
|
||||
'datei_pfad': dateiPfad,
|
||||
'cover_pfad': coverPfad,
|
||||
'groesse_bytes': groesseBytes,
|
||||
'ist_heruntergeladen': istHeruntergeladen ? 1 : 0,
|
||||
'hinzugefuegt_am': hinzugefuegtAm,
|
||||
'download_quelle': downloadQuelle,
|
||||
'zuletzt_position': zuletztPosition,
|
||||
};
|
||||
|
||||
factory Song.fromMap(Map<String, dynamic> m) => Song(
|
||||
id: m['id'] as int?,
|
||||
titel: m['titel'] as String,
|
||||
kuenstler: m['kuenstler'] as String,
|
||||
album: m['album'] as String? ?? '',
|
||||
dauerSekunden: m['dauer_sekunden'] as int,
|
||||
dateiPfad: m['datei_pfad'] as String,
|
||||
coverPfad: m['cover_pfad'] as String?,
|
||||
groesseBytes: m['groesse_bytes'] as int? ?? 0,
|
||||
istHeruntergeladen: (m['ist_heruntergeladen'] as int?) == 1,
|
||||
hinzugefuegtAm: m['hinzugefuegt_am'] as String?,
|
||||
downloadQuelle: m['download_quelle'] as String? ?? 'local',
|
||||
zuletztPosition: m['zuletzt_position'] as int?,
|
||||
);
|
||||
|
||||
String get dauerFormatiert {
|
||||
final min = dauerSekunden ~/ 60;
|
||||
final sek = dauerSekunden % 60;
|
||||
return '$min:${sek.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
String get groesseFormatiert {
|
||||
if (groesseBytes < 1048576) return '${(groesseBytes / 1024).toStringAsFixed(0)} KB';
|
||||
return '${(groesseBytes / 1048576).toStringAsFixed(1)} MB';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user