Files
relative-playlist-maker/relative-playlist-maker.py
T
2026-05-04 11:07:01 -04:00

42 lines
1.1 KiB
Python

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)