do not update tracks already referenced via relative paths

This commit is contained in:
Brennen Raimer
2026-05-04 11:28:03 -04:00
parent 92e767c3d5
commit 223d1fbc42
+10 -2
View File
@@ -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__":