diff --git a/docs/info/release-history.rst b/docs/info/release-history.rst index 50fe4343..4db93e21 100644 --- a/docs/info/release-history.rst +++ b/docs/info/release-history.rst @@ -1,4 +1,4 @@ -`.. Add log for your proposed changes here. +.. Add log for your proposed changes here. The versions shall be listed in descending order with the latest release first. @@ -32,13 +32,23 @@ The format is based on `Keep a Changelog `_, and this project adheres to `Semantic Versioning `_ +1.1.3 +===== + +Fixed +----- +* When given an empty :py:class:`.M3U` playlist file, produces expected result i.e. an empty playlist. + Previously always added all given tracks to playlist when calling :py:meth:`.M3U.load` + + 1.1.2 ===== Changed ------- * :py:meth:`.File.get_filepaths` now ignores hidden files. -* Replace os.makedirs with Pathlib implementation of ``mkdir``q everywhere. +* Replace os.makedirs with Pathlib implementation of ``mkdir`` everywhere. + 1.1.1 ===== @@ -498,4 +508,3 @@ Fixed ===== Initial release! 🎉 -` \ No newline at end of file diff --git a/musify/libraries/local/playlist/m3u.py b/musify/libraries/local/playlist/m3u.py index 799f9030..e3cdd0f8 100644 --- a/musify/libraries/local/playlist/m3u.py +++ b/musify/libraries/local/playlist/m3u.py @@ -93,6 +93,11 @@ async def load(self, tracks: Collection[LocalTrack] = ()) -> Self: paths_raw = self.path_mapper.map_many([line.strip() for line in file], check_existence=True) path_list = list(map(Path, paths_raw)) + if not path_list: # empty playlist file + self.clear() + self._original = [] + return self + self.matcher = FilterDefinedList(values=path_list) self.matcher.transform = lambda x: Path(self.path_mapper.map(x, check_existence=False)) diff --git a/pyproject.toml b/pyproject.toml index 3df01dcb..c58a2aca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -63,7 +63,7 @@ test = [ ] docs = [ "musify[build]", - "sphinx~=7.3", + "sphinx~=7.4", "renku_sphinx_theme", "graphviz~=0.20", "sphinx-autodoc-typehints~=2.2", diff --git a/tests/libraries/local/playlist/test_m3u.py b/tests/libraries/local/playlist/test_m3u.py index d9c07e1e..530306ef 100644 --- a/tests/libraries/local/playlist/test_m3u.py +++ b/tests/libraries/local/playlist/test_m3u.py @@ -41,6 +41,17 @@ def test_init_fails(self): with pytest.raises(InvalidFileType): M3U(path=path_txt) + async def test_load_from_empty_file_with_tracks(self, tracks: list[LocalTrack], tmp_path: Path): + path = tmp_path.joinpath("test").with_suffix(".m3u") + path.touch(exist_ok=True) + + pl = M3U(path=path) + await pl.load(tracks=tracks) + + assert not pl + assert not pl.tracks + assert not pl._original + async def test_load_fake_file_with_no_tracks(self, tracks: list[LocalTrack], tmp_path: Path): path_fake = tmp_path.joinpath("does_not_exist").with_suffix(".m3u")