diff --git a/relative-playlist-maker.py b/relative-playlist-maker.py index c93e7cd..e12f0f2 100644 --- a/relative-playlist-maker.py +++ b/relative-playlist-maker.py @@ -12,13 +12,21 @@ def main(music_folder: Path): with m3u.open("r") as contents: tracks = [Path(p).resolve() for p in contents.readlines()] - if not all(music_folder in track.parents for track in tracks): + if not all( + music_folder in track.parents + if track.is_absolute() + else music_folder in m3u.parent.joinpath(track).resolve().parents + for track in tracks + ): warning(f"{m3u} contains references to tracks that are not in {music_folder} and will be skipped") continue with m3u.open("w") as updated_contents: for track in tracks: - updated_contents.write(str(track.relative_to(m3u, walk_up=True)).replace("\\", "/")) + if track.is_absolute(): + updated_contents.write(str(track.relative_to(m3u, walk_up=True).as_posix())) + else: + updated_contents.write(str(track.as_posix())) if __name__ == "__main__":