initial code added

This commit is contained in:
Brennen Raimer
2026-05-04 11:07:01 -04:00
parent 0f1e810a40
commit 92e767c3d5
4 changed files with 63 additions and 1 deletions
+41
View File
@@ -0,0 +1,41 @@
from argparse import ArgumentParser
from pathlib import Path
from logging import basicConfig, warning, WARNING
from shutil import copyfile
def main(music_folder: Path):
music_folder = music_folder.resolve()
for m3u in music_folder.rglob("*.m3u"):
copyfile(m3u, m3u.with_suffix(".m3u.bak"))
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):
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 __name__ == "__main__":
basicConfig(
level=WARNING,
)
parser = ArgumentParser(
description=""
)
parser.add_argument(
"music_folder",
required=True,
type=Path
)
args = parser.parse_args()
main(args.music_folder)