Skip to content

Commit 9bf85ae

Browse files
committed
Improve playlist line parsing
1 parent f65a918 commit 9bf85ae

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

music_assistant/providers/filesystem_local/__init__.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import os
99
import os.path
1010
import time
11+
import urllib.parse
1112
from collections.abc import AsyncGenerator, Iterator, Sequence
13+
from pathlib import Path
1214
from typing import TYPE_CHECKING, Any, cast
1315

1416
import aiofiles
@@ -718,17 +720,25 @@ async def _process_podcast_episode(item: FileSystemItem) -> None:
718720
async def _parse_playlist_line(self, line: str, playlist_path: str) -> Track | None:
719721
"""Try to parse a track from a playlist line."""
720722
try:
721-
# if a relative path was given in an upper level from the playlist,
722-
# try to resolve it
723-
for parentpart in ("../", "..\\"):
724-
while line.startswith(parentpart):
725-
if len(playlist_path) < 3:
726-
break # guard
727-
playlist_path = os.path.dirname(playlist_path)
728-
line = line[3:]
723+
line = line.replace("file://", "").strip()
724+
725+
# handle relative paths in a level which is above the playlist itself
726+
if ".." in line:
727+
abs_playlist_path = self.get_absolute_path(playlist_path)
728+
line = (Path(abs_playlist_path) / line).resolve().as_posix()
729729

730730
# try to resolve the filename
731-
for filename in (line, os.path.join(playlist_path, line)):
731+
# we try to resolve the playlist line from a few perspectives:
732+
# - as an absolute path
733+
# - relative to the playlist path
734+
# - relative to our base path
735+
for filename in (
736+
line,
737+
os.path.join(playlist_path, line),
738+
# also try with url decoding the line as e.g. VLC seems to encode some characters
739+
urllib.parse.unquote(line),
740+
os.path.join(playlist_path, urllib.parse.unquote(line)),
741+
):
732742
with contextlib.suppress(FileNotFoundError):
733743
file_item = await self.resolve(filename)
734744
tags = await async_parse_tags(file_item.absolute_path, file_item.file_size)

0 commit comments

Comments
 (0)