Guest User

Untitled

a guest
Jan 23rd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. from subprocess import Popen
  2. from multiprocessing import Pool
  3. from shutil import copyfile
  4. import os
  5. from pathlib import Path
  6.  
  7. convertible_formats = ['.wav', '.flac', '.ogg', '.aiff']
  8.  
  9. # My folder is synched with google drive and I don't want to copy google drive metadata
  10. ignore_formats = ['.driveupload', '.drivedownload']
  11.  
  12. source = 'E:\\Music'
  13. target = 'E:\\Opus'
  14.  
  15.  
  16. def convert(src_base, src_ext, dest_base):
  17. print('opusenc "{0}" "{1}.opus"'.format(src_base + src_ext, dest_base).encode("utf-8"))
  18. Popen(['opusenc', src_base + src_ext, dest_base + '.opus']).wait()
  19.  
  20.  
  21. if __name__ == '__main__':
  22. pool = Pool(processes=4)
  23. for root, _, files in os.walk(source):
  24. for file in files:
  25. file_base, src_ext = os.path.splitext(file)
  26. src_base = root + os.sep + file_base
  27. dest_base = target + os.sep + os.path.relpath(src_base, source)
  28. Path(dest_base).parent.mkdir(parents=True, exist_ok=True)
  29. if src_ext in convertible_formats:
  30. pool.apply_async(convert, (src_base, src_ext, dest_base,))
  31. elif src_ext in ignore_formats:
  32. continue
  33. else:
  34. print('cp "{0}" "{1}"'.format(src_base + src_ext, dest_base + src_ext).encode("utf-8"))
  35. copyfile(src_base + src_ext, dest_base + src_ext)
Add Comment
Please, Sign In to add comment