Created
October 1, 2019 00:31
-
-
Save schleumer/894756c71276435ee5cd4d7e1ac2a30b to your computer and use it in GitHub Desktop.
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 glob2 | |
import os | |
import re | |
from shutil import copyfile | |
fileregex = r'.*\.(avi|mp4|mkv)$' | |
srtregex = r'.*\.(srt)$' | |
def ffmpeg(filename): | |
file = os.path.abspath(filename) | |
if os.path.isfile(file) and re.match(fileregex, filename): | |
relfile = os.path.relpath(filename, os.path.abspath('./Source')) | |
newfilename = re.sub(r'\.(avi|mp4|mkv)$', '.mp4', relfile) | |
newfile = os.path.abspath(os.path.join(os.path.abspath("./Target"), newfilename)) | |
newdir = os.path.dirname(newfile) | |
if not os.path.exists(newdir): | |
os.makedirs(newdir) | |
if not os.path.exists(newfile): | |
os.system('ffmpeg -i "' + file + '" -codec:v libx264 -vf "scale=-2:480" "' + newfile + '"') | |
pass | |
elif re.match(srtregex, filename): | |
relfile = os.path.relpath(filename, os.path.abspath('./Source')) | |
newfile = os.path.abspath(os.path.join(os.path.abspath("./Target"), relfile)) | |
newdir = os.path.dirname(newfile) | |
if not os.path.exists(newdir): | |
os.makedirs(newdir) | |
copyfile(file, newfile) | |
else: | |
print(filename) | |
for filename in glob2.glob('./Source/**/*'): | |
ffmpeg(filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment