Created
December 26, 2013 04:56
-
-
Save marconi/8129975 to your computer and use it in GitHub Desktop.
Compute total number of hours of all avi, mkv and mp4 videos on a directory.
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 | |
from hachoir_metadata import extractMetadata | |
from hachoir_parser import createParser | |
def getinfo(rootdir, extensions=(".avi", ".mp4", ".mkv")): | |
if not isinstance(rootdir, unicode): | |
rootdir = rootdir.decode(sys.getfilesystemencoding()) | |
for dirpath, dirs, files in os.walk(rootdir): | |
dirs.sort() # traverse directories in sorted order | |
files.sort() | |
for filename in files: | |
if filename.endswith(extensions): | |
path = os.path.join(dirpath, filename) | |
yield path, extractMetadata(createParser(path)) | |
total_minutes = 0 | |
no_duration = 0 | |
for path, metadata in getinfo(u"/Volumes/Cloud/TV Series"): | |
if metadata.has('duration'): | |
minutes = int(metadata.get('duration').total_seconds() / 60) | |
total_minutes += minutes | |
print "TOTAL: %s" % total_minutes | |
else: | |
no_duration += 1 | |
print "TOTAL: %s hours" % (total_minutes / 60) | |
print "NO DURATION: %s" % no_duration |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment