generated from brennen/python_project
do not update tracks already referenced via relative paths
This commit is contained in:
@@ -12,13 +12,21 @@ def main(music_folder: Path):
|
|||||||
with m3u.open("r") as contents:
|
with m3u.open("r") as contents:
|
||||||
tracks = [Path(p).resolve() for p in contents.readlines()]
|
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")
|
warning(f"{m3u} contains references to tracks that are not in {music_folder} and will be skipped")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
with m3u.open("w") as updated_contents:
|
with m3u.open("w") as updated_contents:
|
||||||
for track in tracks:
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user