📋 Feature: Playlisten-Sync vom Navidrome-Server (Phase 2, Part 6/X)
- getPlaylists() + getPlaylistSongs() APIs für Subsonic-Playlist-Laden - syncPlaylistsFromServer() in PlaylistService importiert alle Server-Playlisten als lokale - Benennung mit 🌐 Präfix um Server-Playlisten zu kennzeichnen - Settings-Button lädt alle Playlisten mit ihren Songs vom Server - Zeigt Anzahl importierter Playlisten mit SnackBar Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XJzQjUtnvYUtHdnTs3iCru
This commit is contained in:
co-authored by
Claude Haiku 4.5
parent
95cbd093e8
commit
221e6fd923
@@ -341,6 +341,56 @@ class NavidromeService {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Lädt alle Playlisten vom Server.
|
||||
Future<List<SubsonicPlaylist>> getPlaylists() async {
|
||||
if (!istVerbunden) return [];
|
||||
try {
|
||||
final uri = _uri('getPlaylists.view');
|
||||
final response = await http.get(uri).timeout(const Duration(seconds: 10));
|
||||
if (response.statusCode != 200) return [];
|
||||
|
||||
final json = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
final subsonicResponse = json['subsonic-response'] as Map<String, dynamic>?;
|
||||
if (subsonicResponse == null) return [];
|
||||
|
||||
final playlists = subsonicResponse['playlists'] as List<dynamic>?;
|
||||
if (playlists == null) return [];
|
||||
|
||||
return playlists
|
||||
.cast<Map<String, dynamic>>()
|
||||
.map(SubsonicPlaylist.fromJson)
|
||||
.toList();
|
||||
} catch (e) {
|
||||
debugPrint('getPlaylists Fehler: $e');
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/// Lädt alle Songs einer Playlist vom Server.
|
||||
Future<List<SubsonicSong>> getPlaylistSongs(String playlistId) async {
|
||||
if (!istVerbunden) return [];
|
||||
try {
|
||||
final uri = _uri('getPlaylist.view', {'id': playlistId});
|
||||
final response = await http.get(uri).timeout(const Duration(seconds: 10));
|
||||
if (response.statusCode != 200) return [];
|
||||
|
||||
final json = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
final subsonicResponse = json['subsonic-response'] as Map<String, dynamic>?;
|
||||
if (subsonicResponse == null) return [];
|
||||
|
||||
final playlist = subsonicResponse['playlist'] as Map<String, dynamic>?;
|
||||
if (playlist == null) return [];
|
||||
|
||||
final songs = playlist['entry'] as List<dynamic>?;
|
||||
if (songs == null) return [];
|
||||
|
||||
return songs.cast<Map<String, dynamic>>().map(SubsonicSong.fromJson).toList();
|
||||
} catch (e) {
|
||||
debugPrint('getPlaylistSongs Fehler: $e');
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SubsonicArtist {
|
||||
@@ -358,6 +408,27 @@ class SubsonicArtist {
|
||||
);
|
||||
}
|
||||
|
||||
class SubsonicPlaylist {
|
||||
final String id;
|
||||
final String name;
|
||||
final String? comment;
|
||||
final int songCount;
|
||||
|
||||
const SubsonicPlaylist({
|
||||
required this.id,
|
||||
required this.name,
|
||||
this.comment,
|
||||
this.songCount = 0,
|
||||
});
|
||||
|
||||
factory SubsonicPlaylist.fromJson(Map<String, dynamic> j) => SubsonicPlaylist(
|
||||
id: j['id'] as String,
|
||||
name: j['name'] as String? ?? 'Unbekannt',
|
||||
comment: j['comment'] as String?,
|
||||
songCount: (j['songCount'] as int?) ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
class Lyrics {
|
||||
final String? text;
|
||||
final bool isEmpty;
|
||||
|
||||
Reference in New Issue
Block a user