Skip to content

Instantly share code, notes, and snippets.

@feuerrot
Last active December 19, 2015 00:45
Show Gist options
  • Save feuerrot/e66c02487589f83d5b1d to your computer and use it in GitHub Desktop.
Save feuerrot/e66c02487589f83d5b1d to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import os
import subprocess
import json
import datetime
class ldict(dict):
def __missing__(self, key):
return 0
length = ldict()
def getlen(filename, category):
global length
foo = json.loads(subprocess.check_output(['avprobe', '-hide_banner', '-show_streams', '-print_format', 'json', filename], stderr=subprocess.DEVNULL).decode('UTF-8'))
length[category] += float(foo['streams'][0]['duration'])
def traversedir(root, ext, fkt):
for (dirpath, dirnames, filenames) in os.walk(root):
for file in filenames:
file = os.path.join(dirpath, file)
if file.endswith(ext):
fkt(file, root)
def getdirs():
return [dir for dir in os.listdir('.') if os.path.isdir(dir)]
for dir in getdirs():
traversedir(dir, ('m2ts', 'MTS'), getlen)
for key in length:
print('{} {}'.format(key, datetime.timedelta(seconds=int(length[key]))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment