Last active
December 13, 2020 12:42
-
-
Save qihnus/3099310 to your computer and use it in GitHub Desktop.
List video durations on a Mac
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
#!/usr/bin/env python | |
import os | |
import sys | |
import glob | |
from QTKit import QTMovie | |
TOTAL_DURATION = 0 | |
def format_duration(duration): | |
return "%5d:%02d" % (duration / 60, duration % 60) | |
def process(fn): | |
global TOTAL_DURATION | |
attributes = {'QTMovieFileNameAttribute': os.path.abspath(fn)} | |
movie, error = QTMovie.movieWithAttributes_error_(attributes, None) | |
if error or not movie: | |
print error.description() | |
return | |
duration = movie.duration()[0]/movie.duration()[1] | |
TOTAL_DURATION += duration | |
print format_duration(TOTAL_DURATION), format_duration(duration), fn | |
def main(files): | |
for fn in files: | |
process(fn) | |
if __name__ == '__main__': | |
if len(sys.argv) > 1: | |
main(sys.argv[1:]) | |
else: | |
main("*.mp4") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment