Skip to content

Instantly share code, notes, and snippets.

@saulshanabrook
Created January 22, 2012 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saulshanabrook/1658588 to your computer and use it in GitHub Desktop.
Save saulshanabrook/1658588 to your computer and use it in GitHub Desktop.
Converts, imports, and then removes downloaded video files in a folder, and its subfolders, into Python.
import os
from os.path import join
from subprocess import call
source_directory = '/Users/ygbhygb/Documents/Torrents/To Be Converted'
output_directory = '/Users/ygbhygb/Music/iTunes/iTunes Media/Automatically Add to iTunes'
video_endings = ['.avi', '.mkv']
hb_options = '--preset="universal"'
hbcli_path = '/Applications/HandBrakeCLI'
def path_error(OSError):
raise OSError
for root, dirs, files in os.walk(source_directory, onerror=path_error):
for name in files:
if any(name.endswith(file_ending) for file_ending in video_endings):
call("{} -i {} -o {}".format(
hbcli_path.replace(' ', '\ '),
join(root, name).replace(' ', '\ '),
join(output_directory, name).replace(' ', '\ '),
hb_options),
shell=True)
call('rm {}'.format(join(root,name)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment