"""Copies NLP Quantic MP3s to nlp-quantic/audio_phone/ with phone-friendly names + ID3 tags + cover. Reuses cover/tag helpers from rename_phone_practitioner.py. Run after: python download.py --course quantic """ from __future__ import annotations import json import re import shutil import sys from pathlib import Path import rename_phone_practitioner as rp ROOT = Path(__file__).parent QUANTIC = ROOT / "nlp-quantic" AUDIO_DST = QUANTIC / "audio_phone" COVERS_DIR = AUDIO_DST / "_covers" MANIFEST = QUANTIC / "manifest.json" rp.COURSE_PREFIX = "NLP Quantic" rp.ARTIST = "cursnlp.ro" rp.ALBUM_ARTIST = "cursnlp.ro" rp.YEAR = "2023" def clean_title(t: str) -> str: return re.sub(r"\s+", " ", t.replace(",", " ")).strip() def main() -> int: manifest = json.loads(MANIFEST.read_text(encoding="utf-8")) errors = 0 for mod in manifest["modules"]: n = int(mod["name"].split()[-1]) lecs = [L for L in mod["lectures"] if L["type"] in ("audio", "vimeo")] if not lecs: continue cover = COVERS_DIR / f"M{n}.png" if not cover.exists(): rp.make_cover(n, "", cover) album = f"NLP Quantic - Modul {n}" out_dir = AUDIO_DST / f"Quantic M{n}" out_dir.mkdir(parents=True, exist_ok=True) for idx, lec in enumerate(lecs, 1): src = ROOT / lec["audio_path"] if lec.get("download_status") != "complete" or not src.exists(): print(f" MISSING: {lec['title']}") errors += 1 continue title = clean_title(lec["title"]) dst = out_dir / f"Q{n}-{idx:02d} {rp.safe_filename_part(title)}.mp3" if not (dst.exists() and dst.stat().st_size >= src.stat().st_size): shutil.copy2(src, dst) rp.tag_mp3(dst, title=title, album=album, track_num=idx, track_total=len(lecs), cover_png=cover) print(f" ok: {dst.relative_to(QUANTIC)}") print(f"\nDONE. errors={errors} Output: {AUDIO_DST}") return 0 if errors == 0 else 2 if __name__ == "__main__": sys.exit(main())