37 lines
970 B
Python
37 lines
970 B
Python
#!/usr/bin/env python3
|
|
import os, sys, pathlib
|
|
|
|
m3u8 = pathlib.Path(sys.argv[1]).resolve()
|
|
outdir = pathlib.Path(sys.argv[2]).resolve()
|
|
print(outdir)
|
|
outdir.mkdir(parents=True, exist_ok=True)
|
|
pl_dir = m3u8.parent
|
|
|
|
with m3u8.open("r", encoding="utf-8") as f:
|
|
for line in f:
|
|
s = line.strip()
|
|
if not s or s.startswith("#"):
|
|
continue
|
|
src = pathlib.Path(s)
|
|
if not src.is_absolute():
|
|
src = (pl_dir / src).resolve()
|
|
else:
|
|
src = src.resolve()
|
|
|
|
if not src.exists():
|
|
print(f"skip (missing): {src}", file=sys.stderr)
|
|
continue
|
|
|
|
dest = outdir / src.name
|
|
|
|
if dest.exists():
|
|
print(f"skip (exists): {dest}", file=sys.stderr)
|
|
continue
|
|
|
|
try:
|
|
print(f"{src} -> {dest}")
|
|
dest.symlink_to(src)
|
|
except OSError:
|
|
# fallback to hardlink if symlink not permitted
|
|
os.link(src, dest)
|