Skip to content

Instantly share code, notes, and snippets.

@SuborbitalPigeon
Last active April 24, 2016 15:38
Show Gist options
  • Save SuborbitalPigeon/8ae1a0586a3714e3234dd44f33d611ed to your computer and use it in GitHub Desktop.
Save SuborbitalPigeon/8ae1a0586a3714e3234dd44f33d611ed to your computer and use it in GitHub Desktop.
from datetime import datetime
import json
import os
import subprocess
from sys import argv
dir = argv[1]
files = []
for dirpath, dirname, filenames in os.walk(dir):
for filename in filenames:
if filename.startswith('MVI_'):
files.append(os.path.join(dirpath, filename))
for old in files:
cmd = ['ffprobe', '-print_format', 'json', '-show_format', old]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
j = json.loads(out.decode())
times = j['format']['tags']['creation_time']
dt = datetime.strptime(times, '%Y-%m-%d %H:%M:%S')
newname = 'mvi_' + dt.strftime('%Y%m%d_%H%M%S') + '.mov'
new = os.path.join(os.path.dirname(old), newname)
print("Renaming {} to {}".format(old, newname))
os.rename(old, new)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment