Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from subprocess import Popen
- from multiprocessing import Pool
- from shutil import copyfile
- import os
- from pathlib import Path
- convertible_formats = ['.wav', '.flac', '.ogg', '.aiff']
- # My folder is synched with google drive and I don't want to copy google drive metadata
- ignore_formats = ['.driveupload', '.drivedownload']
- source = 'E:\\Music'
- target = 'E:\\Opus'
- def convert(src_base, src_ext, dest_base):
- print('opusenc "{0}" "{1}.opus"'.format(src_base + src_ext, dest_base).encode("utf-8"))
- Popen(['opusenc', src_base + src_ext, dest_base + '.opus']).wait()
- if __name__ == '__main__':
- pool = Pool(processes=4)
- for root, _, files in os.walk(source):
- for file in files:
- file_base, src_ext = os.path.splitext(file)
- src_base = root + os.sep + file_base
- dest_base = target + os.sep + os.path.relpath(src_base, source)
- Path(dest_base).parent.mkdir(parents=True, exist_ok=True)
- if src_ext in convertible_formats:
- pool.apply_async(convert, (src_base, src_ext, dest_base,))
- elif src_ext in ignore_formats:
- continue
- else:
- print('cp "{0}" "{1}"'.format(src_base + src_ext, dest_base + src_ext).encode("utf-8"))
- copyfile(src_base + src_ext, dest_base + src_ext)
Add Comment
Please, Sign In to add comment