Dup Ver Goto 📝

Pathlib Examples 1

PT2/lang/python/fs does not exist
To
29 lines, 79 words, 735 chars Page 'PathLibExamples_01' does not exist.

Get Info Of Mp4 Files

Here we use Path(...).glob("**/*.mp4") to do a recursive glob.

#!/usr/bin/env python

import pathlib
from subprocess import run, DEVNULL
import json

root = pathlib.Path(".")
files = root.glob("**/*.mp4")
data = {}
errors = {}
for fn in files:
  fn = str(fn)
  print(f"{fn}... ",end="")
  m = run(["ffprobe","-print_format","json","-show_streams","-show_format",fn],capture_output=True,stdin=DEVNULL)
  if m.returncode != 0:
    print(f"ffprobe on {fn} returned {m.returncode}")
    errors[fn] = m.stderr.decode()
    continue
  data[fn] = json.loads(m.stdout.decode())
  print("done.")

with open("mp4s.json","wt") as f:
  json.dump(data,f)
with open("errors.json","wt") as f:
  json.dump(errors,f)