SHARE
TWEET

Untitled

a guest Oct 19th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import glob2
  2. import os
  3. import re
  4. from shutil import copyfile
  5.  
  6. fileregex = r'.*\.(avi|mp4|mkv)$'
  7. srtregex = r'.*\.(srt)$'
  8.  
  9. def ffmpeg(filename):
  10.     file = os.path.abspath(filename)
  11.     if os.path.isfile(file) and re.match(fileregex, filename):
  12.         relfile = os.path.relpath(filename, os.path.abspath('./Source'))
  13.         newfilename = re.sub(r'\.(avi|mp4|mkv)$', '.mp4', relfile)
  14.         newfile = os.path.abspath(os.path.join(os.path.abspath("./Target"), newfilename))
  15.         newdir = os.path.dirname(newfile)
  16.         if not os.path.exists(newdir):
  17.             os.makedirs(newdir)
  18.         if not os.path.exists(newfile):
  19.             os.system('ffmpeg -i "' + file + '" -codec:v libx264 -vf "scale=-2:480" "' + newfile + '"')
  20.             pass
  21.     elif re.match(srtregex, filename):
  22.         relfile = os.path.relpath(filename, os.path.abspath('./Source'))
  23.         newfile = os.path.abspath(os.path.join(os.path.abspath("./Target"), relfile))
  24.         newdir = os.path.dirname(newfile)
  25.  
  26.         if not os.path.exists(newdir):
  27.             os.makedirs(newdir)
  28.  
  29.         copyfile(file, newfile)
  30.     else:
  31.         print(filename)
  32.  
  33. for filename in glob2.glob('./Source/**/*'):
  34.     ffmpeg(filename)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top