Created
December 19, 2015 18:02
-
-
Save crackwitz/e48a9b2b3722f0dfa24d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import subprocess | |
import json | |
import pprint | |
import glob | |
def getlen(filename): | |
avdata = json.loads( | |
subprocess.check_output( | |
['ffprobe', '-hide_banner', '-show_format', '-print_format', 'json', filename], | |
stderr=open(os.devnull, 'w') | |
).decode('UTF-8') | |
) | |
return float(avdata['format']['duration']) | |
if __name__ == "__main__": | |
total = { | |
root: sum( | |
getlen(os.path.join(path, file)) | |
for (path, dirs, files) in os.walk(root) # path contains root | |
for file in files | |
if file.endswith((".m2ts", ".MTS")) | |
) | |
# or just for root in sys.argv[1:] | |
for globbable in sys.argv[1:] | |
for root in glob.glob(globbable) | |
if os.path.isdir(root) | |
} | |
json.dump(total, sys.stdout, indent=1, sort_keys=True) | |
# pprint.pprint works too |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment