Created
January 22, 2012 20:04
-
-
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.
This file contains 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 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