def poster(prog=None, args=None): desc = 'generate poster images from videos' parser = argparse.ArgumentParser(prog=prog, description=desc) parser.add_argument('-f', '--format', dest='fmt', choices=['png', 'jpg'], default='jpg', help='out image format') parser.add_argument('--dry', action='store_true', help='print ffmpeg command but do not execute it') parser.add_argument('paths', metavar='PATH', nargs='+', help='an audio/video file') ns = parser.parse_args(args) for p in ns.paths: try: make_poster(p, ns) except Exception as e: printerr('path:', p) printerr(e)
def show(paths): for path in paths: try: vi = VideoIdentifier.from_name(path) print(vi, path, sep='\t') except Exception as e: # printerr(e) traceback.print_exc() printerr('bad file:', path)
def _printerr(*args, **kwargs): parts = [] for a in args: if isinstance(a, bytes): parts.append(a.decode()) elif isinstance(a, (deque, list, tuple)): parts.extend(a) kwargs.setdefault('sep', ':') printerr(*parts, **kwargs)
def run(prog, args): import argparse desc = 'generate entrypoint script from setup.py' pr = argparse.ArgumentParser(prog=prog, description=desc) aa = pr.add_argument aa('-d', '--dir', help='output dir') aa('path', help='path to a setup.py or its containing dir') ns = pr.parse_args(args) try: spec = inspect_setuppy(ns.path) make_entrypoint_script(spec, ns.dir) except Exception as e: printerr(e)
def add_vident_prefix(paths): groups = defaultdict(list) for path in p_filter_by_extension(paths): try: vi, path = VideoIdentifier.rename(path) except ValueError: traceback.print_exc() printerr('bad file:', path) continue groups[vi.unikey].append((vi, path)) for pairs in groups.values(): if len(pairs) < 2: continue pairs.sort(key=keyfunc, reverse=True) print('\n# ', pairs[0][1]) for _, path in pairs[1:]: print('rm -f', path)
def run(prog=None, args=None): desc = 'convert audio/video format' parser = argparse.ArgumentParser(prog=prog, description=desc) utils.add_dry_option(parser) parser.add_argument('-f', '--format', dest='fmt', default='mp4', help='out audio/video format, e.g. mp4, ogg, ...') parser.add_argument('paths', metavar='PATH', nargs='+', help='an audio/video file') ns = parser.parse_args(args) for p in ns.paths: try: convert_a_file(p, ns) except Exception as e: printerr('path:', p) printerr(e)
def run(prog=None, args=None): desc = 'Crop images with homogeneously colored margins ' pr = argparse.ArgumentParser(prog=prog, description=desc) pr.add_argument('-s', '--stdmax', default=STDMAX, type=int, help='maximum standard deviation') pr.add_argument('-B', '--no-backup', action='store_true', help='do NOT backup original file') pr.add_argument('files', nargs='*', metavar='PATH', help='paths to files to be cropped') ns = pr.parse_args(args) for path in ns.files: try: margin_crop(path, ns.stdmax, not ns.no_backup) except Exception as e: printerr('Failed:', path, '--', e) continue
def remove_vident_prefix(paths): paths = p_filter_by_extension(paths) for path in p_filter_by_prefix(paths): dir_, name = os.path.split(path) regex = VideoIdentifier.get_regex() new_name = regex.sub('', name) if new_name.startswith('.'): new_name = new_name[1:] new_path = os.path.join(dir_, new_name) if new_name and not os.path.exists(new_path): os.rename(path, new_path) else: printerr('cannot rename:') printerr(' from "{}"'.format(path)) printerr(' to "{}"'.format(new_path))