fix for playlist editing
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Mon, 16 May 2022 23:09:57 +0000 (01:09 +0200)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Mon, 16 May 2022 23:09:57 +0000 (01:09 +0200)
music_assistant/controllers/music/playlists.py
music_assistant/controllers/music/providers/filesystem.py

index 18aeab195977b303c75eb8d76061e886766bd408..b918854451698299a0e87004db0d6fff5643fd12 100644 (file)
@@ -110,7 +110,7 @@ class PlaylistController(MediaControllerBase[Playlist]):
                 continue
             if playlist_prov.prov_type.is_file():
                 # the file provider can handle uri's from all providers so simply add the uri
-                track_id_to_add = track.uri
+                track_id_to_add = track_version.url
                 break
             if track_version.prov_id == playlist_prov.prov_id:
                 track_id_to_add = track_version.item_id
index b0acff18f7b346ffe03e33c129e1944797d6bb75..50822e5350c5896b7946fea8dfceccb3dce20ef5 100644 (file)
@@ -248,17 +248,29 @@ class FileSystemProvider(MusicProvider):
         itempath = await self.get_filepath(prov_playlist_id)
         if not self.exists(itempath):
             raise MediaNotFoundError(f"Playlist path does not exist: {itempath}")
-        async with self.open_file(itempath, "a") as _file:
+        async with self.open_file(itempath, "r") as _file:
+            cur_data = await _file.read()
+        async with self.open_file(itempath, "w") as _file:
+            await _file.write(cur_data)
             for uri in prov_track_ids:
-                await _file.writeline(uri)
+                await _file.write(f"\n{uri}")
 
     async def remove_playlist_tracks(
         self, prov_playlist_id: str, prov_track_ids: List[str]
     ) -> None:
         """Remove track(s) from playlist."""
-        # TODO !
-        if MediaType.PLAYLIST in self.supported_mediatypes:
-            raise NotImplementedError
+        itempath = await self.get_filepath(prov_playlist_id)
+        if not self.exists(itempath):
+            raise MediaNotFoundError(f"Playlist path does not exist: {itempath}")
+        cur_lines = []
+        async with self.open_file(itempath, "r") as _file:
+            for line in await _file.readlines():
+                line = urllib.parse.unquote(line.strip())
+                if line not in prov_track_ids:
+                    cur_lines.append(line)
+        async with self.open_file(itempath, "w") as _file:
+            for uri in cur_lines:
+                await _file.write(f"{uri}\n")
 
     async def get_stream_details(self, item_id: str) -> StreamDetails:
         """Return the content details for the given track when it will be streamed."""