def __init__(self, input_dir, output_dir, **kwargs): # Get keyword arguments. flac_exe = kwargs.get(str('flac_executable'), '/usr/local/bin/flac') lame_exe = kwargs.get(str('lame_executable'), '/usr/local/bin/lame') metaflac_exe = kwargs.get(str('metaflac_executable'), '/usr/local/bin/metaflac') copy_tags = kwargs.get(str('copy_tags'), False) quality = kwargs.get(str('quality'), 'V0') # Check for required external executables. if not os.path.isfile(flac_exe): sys.exit('flac not found at "%s"' % flac_exe) if not os.path.isfile(lame_exe): sys.exit('lame not found at "%s"' % lame_exe) if not os.path.isfile(metaflac_exe): sys.exit('metaflac not found at "%s"' % metaflac_exe) # Process files and directories. for item_name in os.listdir(input_dir): item_path = os.path.join(input_dir, item_name) if os.path.isfile(item_path): self.transcode_file(item_path, output_dir, copy_tags, flac_exe, lame_exe, metaflac_exe, quality) elif os.path.isdir(item_path): output_sub_dir = os.path.join(output_dir, item_name) os.makedirs(output_sub_dir) contained_files = get_file_paths_from_directory(item_path) for contained_file in contained_files: self.transcode_file(contained_file, output_sub_dir, copy_tags, flac_exe, lame_exe, metaflac_exe, quality)
def __init__(self, input_dir, output_dir, **kwargs): # Get keyword arguments. tesseract_exe = kwargs.get(str('tesseract_executable'), '/usr/local/bin/tesseract') language = kwargs.get(str('language'), 'eng') boxes = kwargs.get(str('boxes'), False) config = kwargs.get(str('config'), '') # Check for required external executable. if not os.path.isfile(tesseract_exe): sys.exit('tesseract not found at "%s"' % tesseract_exe) # Process files and directories. for item_name in os.listdir(input_dir): item_path = os.path.join(input_dir, item_name) if os.path.isfile(item_path): self.run_ocr(item_path, output_dir, tesseract_exe, language, boxes, config) elif os.path.isdir(item_path): output_sub_dir = os.path.join(output_dir, item_name) os.makedirs(output_sub_dir) contained_files = get_file_paths_from_directory(item_path) for contained_file in contained_files: self.run_ocr(contained_file, output_sub_dir, tesseract_exe, language, boxes, config)
def __init__(self, input_dir, output_dir, **kwargs): # Get keyword arguments. degrees = kwargs.get(str('degrees'), 90.0) expand_arg = kwargs.get(str('expand'), True) # Check arguments. if expand_arg is True: expand = 1 elif expand_arg is False: expand = 0 else: sys.exit('Argument expand invalid') # Process files and directories. for item_name in os.listdir(input_dir): item_path = os.path.join(input_dir, item_name) if os.path.isfile(item_path): self.rotate_file(item_path, output_dir, degrees, expand) elif os.path.isdir(item_path): output_sub_dir = os.path.join(output_dir, item_name) os.makedirs(output_sub_dir) contained_files = get_file_paths_from_directory(item_path) for contained_file in contained_files: self.rotate_file(contained_file, output_sub_dir, degrees, expand)
def __init__(self, input_dir, output_dir, **kwargs): # Get keyword arguments. ffmpeg_exe = kwargs.get(str('ffmpeg_executable'), '/usr/local/bin/ffmpeg') extension = kwargs.get(str('extension'), 'm4v') other_args = kwargs.get(str('other_args'), '') # Check for required external executable. if not os.path.isfile(ffmpeg_exe): sys.exit('ffmpeg not found at "%s"' % ffmpeg_exe) # Process files and directories. for item_name in os.listdir(input_dir): item_path = os.path.join(input_dir, item_name) if os.path.isfile(item_path): self.transcode_file(item_path, output_dir, ffmpeg_exe, extension, other_args) elif os.path.isdir(item_path): output_sub_dir = os.path.join(output_dir, item_name) os.makedirs(output_sub_dir) contained_files = get_file_paths_from_directory(item_path) for contained_file in contained_files: self.transcode_file(contained_file, output_sub_dir, ffmpeg_exe, extension, other_args)
def __init__(self, input_dir, output_dir, **kwargs): # Get keyword arguments. opusenc_exe = kwargs.get(str('lopusenc_executable'), '/usr/local/bin/opusenc') bitrate = kwargs.get(str('bitrate'), '80') # Check for required external executable. if not os.path.isfile(opusenc_exe): sys.exit('opusenc not found at "%s"' % opusenc_exe) # Process files and directories. for item_name in os.listdir(input_dir): item_path = os.path.join(input_dir, item_name) if os.path.isfile(item_path): self.transcode_file(item_path, output_dir, opusenc_exe, bitrate) elif os.path.isdir(item_path): output_sub_dir = os.path.join(output_dir, item_name) os.makedirs(output_sub_dir) contained_files = get_file_paths_from_directory(item_path) for contained_file in contained_files: self.transcode_file(contained_file, output_sub_dir, opusenc_exe, bitrate)
def __init__(self, input_dir, output_dir, **kwargs): # Get keyword arguments. ebookconvert_exe = kwargs.get( str('ebookconvert_executable'), '/Applications/calibre.app/Contents/MacOS/ebook-convert') extension = kwargs.get(str('extension'), 'mobi') # Check for required external executable. if not os.path.isfile(ebookconvert_exe): sys.exit('ebook-convert not found at "%s"' % ebookconvert_exe) # Process files and directories. for item_name in os.listdir(input_dir): item_path = os.path.join(input_dir, item_name) if os.path.isfile(item_path): self.convert_book(item_path, output_dir, ebookconvert_exe, extension) elif os.path.isdir(item_path): output_sub_dir = os.path.join(output_dir, item_name) os.makedirs(output_sub_dir) contained_files = get_file_paths_from_directory(item_path) for contained_file in contained_files: self.convert_book(contained_file, output_sub_dir, ebookconvert_exe, extension)
def __init__(self, input_dir, output_dir, **kwargs): # Process files and directories. for item_name in os.listdir(input_dir): item_path = os.path.join(input_dir, item_name) if os.path.isfile(item_path): self.convert_to_html(item_path, output_dir) elif os.path.isdir(item_path): output_sub_dir = os.path.join(output_dir, item_name) os.makedirs(output_sub_dir) contained_files = get_file_paths_from_directory(item_path) for contained_file in contained_files: self.convert_to_html(contained_file, output_sub_dir)
def __init__(self, input_dir, output_dir, **kwargs): other_args = kwargs.get(str('other_args'), '') # Process files and directories. for item_name in os.listdir(input_dir): item_path = os.path.join(input_dir, item_name) if os.path.isfile(item_path): self.extract_strings(item_path, output_dir, other_args) elif os.path.isdir(item_path): output_sub_dir = os.path.join(output_dir, item_name) os.makedirs(output_sub_dir) contained_files = get_file_paths_from_directory(item_path) for contained_file in contained_files: self.extract_strings(contained_file, output_dir, other_args)
def __init__(self, input_dir, output_dir, **kwargs): # Get keyword arguments. extension = kwargs.get(str('extension'), 'jpg') # Process files and directories. for item_name in os.listdir(input_dir): item_path = os.path.join(input_dir, item_name) if os.path.isfile(item_path): self.convert_file(item_path, output_dir, extension) elif os.path.isdir(item_path): output_sub_dir = os.path.join(output_dir, item_name) os.makedirs(output_sub_dir) contained_files = get_file_paths_from_directory(item_path) for contained_file in contained_files: self.convert_file(contained_file, output_sub_dir, extension)
def __init__(self, input_dir, output_dir, **kwargs): # Get keyword arguments. section_start_regex = re.compile(kwargs.get(str('section_start_regex'), r'^# TOC$')) section_end_regex = re.compile(kwargs.get(str('section_end_regex'), r'^---$')) # Process files and directories. for item_name in os.listdir(input_dir): item_path = os.path.join(input_dir, item_name) if os.path.isfile(item_path): self.remove_section(item_path, output_dir, section_start_regex, section_end_regex) elif os.path.isdir(item_path): output_sub_dir = os.path.join(output_dir, item_name) os.makedirs(output_sub_dir) contained_files = get_file_paths_from_directory(item_path) for contained_file in contained_files: self.remove_section(contained_file, output_sub_dir, section_start_regex, section_end_regex)
def __init__(self, input_dir, output_dir, **kwargs): # Get keyword arguments. width = kwargs.get(str('width'), 800) height = kwargs.get(str('height'), 600) image_filter = kwargs.get(str('filter'), 'antialias') # Check arguments. if image_filter == 'antialias': resample = Image.ANTIALIAS elif image_filter == 'box': resample = Image.BOX elif image_filter == 'bilinear': resample = Image.BILINEAR elif image_filter == 'hamming': resample = Image.HAMMING elif image_filter == 'bicubic': resample = Image.BICUBIC elif image_filter == 'nearest': resample = Image.NEAREST else: sys.exit('No valid filter passed') # Process files and directories. for item_name in os.listdir(input_dir): item_path = os.path.join(input_dir, item_name) if os.path.isfile(item_path): self.resize_file(item_path, output_dir, width, height, resample) elif os.path.isdir(item_path): output_sub_dir = os.path.join(output_dir, item_name) os.makedirs(output_sub_dir) contained_files = get_file_paths_from_directory(item_path) for contained_file in contained_files: self.resize_file(contained_file, output_sub_dir, width, height, resample)
def __init__(self, input_dir, output_dir, **kwargs): # Get keyword arguments. target_file = kwargs.get(str('target_file'), '') # Check required argument. if len(target_file) > 0: target_file = os.path.expanduser(target_file) print('Appending to "%s".' % target_file) if not os.path.isfile(target_file): touch_file(target_file) else: sys.exit('No target_file passed to append to') # Process files and directories. for item_name in os.listdir(input_dir): item_path = os.path.join(input_dir, item_name) if os.path.isfile(item_path): self.append_to_file(item_path, target_file) elif os.path.isdir(item_path): contained_files = get_file_paths_from_directory(item_path) for contained_file in contained_files: self.append_to_file(contained_file, target_file)
def test_get_file_paths_from_directory(): return_value = get_file_paths_from_directory(dir_path='%s' % files_dir) assert ('%s' % files_dir.join('IMG_1248.JPG') in return_value) is True