From d4c5fd437b121d66c6908ee88d314a52fdb88fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Mon, 16 Jan 2017 00:09:49 +0100 Subject: [PATCH] script now uses argparse instead of reinventing the wheel --- coub-dl.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/coub-dl.py b/coub-dl.py index 2494552..486903c 100644 --- a/coub-dl.py +++ b/coub-dl.py @@ -2,13 +2,22 @@ from subprocess import call, Popen, PIPE, check_output, DEVNULL from os import listdir, remove from os.path import splitext, exists from re import match -from sys import argv from enum import Enum from datetime import timedelta from math import ceil +from argparse import ArgumentParser +# parse arguments +parser = ArgumentParser(description='Download player-looped videos with youtube-dl & ffmpeg.') +parser.add_argument('-nv', '--nonverbose', help='Turn off non-critical messages to user.') +parser.add_argument('url', type=str, help='The URL of the site containing the video to download.') + +args = parser.parse_args() +VERBOSE = False if args.nonverbose else True + + class Stream(Enum): AUDIO = 1 VIDEO = 2 @@ -18,7 +27,6 @@ class File(Enum): LOOP = 2 OUTPUT = 3 -VERBOSE = True def print_opt(*args, **kwargs): if VERBOSE: print(*args, **kwargs) @@ -81,11 +89,11 @@ def yes_no_question(question, default): FILES = {Stream.AUDIO: 'audio', Stream.VIDEO: 'video', File.LIST: 'list.txt', File.LOOP: 'loop', File.OUTPUT: 'output.mp4'} OUTPUT_KEYS = [File.OUTPUT] -URL = argv[1] if len(argv) > 0 else '' # youtube-dl error message will be shown if '' +URL = args.url # fetch video title -FILES[File.OUTPUT] = check_output(('/usr/bin/env', 'youtube-dl', '--get-title', argv[1])).decode('utf-8').strip() + '.mp4' +FILES[File.OUTPUT] = check_output(('/usr/bin/env', 'youtube-dl', '--get-title', args.url)).decode('utf-8').strip() + '.mp4' # ask what to do if output exists if exists(FILES[File.OUTPUT]):