multimediareport.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/python
  2. # deps: dominate
  3. import re
  4. import os
  5. import sys
  6. import hashlib
  7. import os.path
  8. import subprocess
  9. import dominate
  10. from dominate import tags
  11. multimedia_filenames = r".*\.(?:webm|avi|mp4|mkv|mp3|flac|ogg|opus|wav)$"
  12. def process_dir(path, doc):
  13. for path, directories, files in os.walk(path):
  14. for f in files:
  15. if re.match(multimedia_filenames, f, re.IGNORECASE):
  16. # print('found %s' % os.path.join(path, f))
  17. identifier = hashlib.sha256(f.encode()).hexdigest()[0:16]
  18. outfilename = identifier + ".png"
  19. result = subprocess.run(['ffmpeg', '-i', os.path.join(path, f), '-filter_complex', 'showwavespic=s=640x120', '-frames:v', '1', outfilename], capture_output=True, text=True)
  20. doc += tags.div(f)
  21. doc += tags.img(src=outfilename )
  22. if __name__=='__main__':
  23. thedir = sys.argv[1]
  24. doc = dominate.document(title='Audio file report for %s' % thedir)
  25. process_dir(path=thedir, doc=doc)
  26. print(doc)