Created
April 29, 2016 10:03
-
-
Save aljungberg/c7e72cbfd1e6eb1bf4621a62fad82278 to your computer and use it in GitHub Desktop.
Repackage all h264 mkv files to mp4 files in the current folder.
This file contains 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/env python | |
import os | |
import sh | |
import re | |
for fname in os.listdir("."): | |
if not fname.endswith(".mkv"): | |
continue | |
new_name = fname[:-4] + ".mp4" | |
if os.path.exists(new_name): | |
continue | |
meta = "" | |
series = re.search(r'S(\d\d)', fname) | |
episode = re.search(r'E(\d\d)', fname) | |
meta = { | |
'title': new_name[:-4] | |
} | |
if series and episode: | |
meta['episode_id'] = '{}x{}'.format(int(series.group(1)), int(episode.group(1))) | |
show_name = re.match(r'^(.*) S\d\d.*E\d\d.*', fname) | |
meta['show'] = '{}'.format(show_name.group(1)) | |
args = ["-i", fname, '-vcodec', 'copy', '-acodec', 'copy'] | |
for k, v in meta.items(): | |
args += ['-metadata', "{}={}".format(k, v)] | |
args += [new_name] | |
try: | |
print fname | |
sh.ffmpeg(*args) | |
except Exception as e: | |
print e.stderr | |
raise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment