From b5a1a845a535230238bf09543aa95253cc7175c4 Mon Sep 17 00:00:00 2001 From: Ming Dai Date: Wed, 1 Jan 2014 14:25:44 +0800 Subject: [PATCH] Add support to play video in players --- src/you_get/common.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/you_get/common.py b/src/you_get/common.py index 25df1090..8a570f62 100644 --- a/src/you_get/common.py +++ b/src/you_get/common.py @@ -15,6 +15,7 @@ from .util import log, legitimize, sogou_proxy_server dry_run = False force = False +player = None sogou_proxy = None sogou_env = None @@ -78,6 +79,11 @@ def match1(text, *patterns): ret.append(match.group(1)) return ret +def launch_player(player, urls): + import subprocess + import shlex + subprocess.call(shlex.split(player) + list(urls)) + def parse_query_param(url, param): """Parses the query string of a URL and returns the value of a parameter. @@ -504,6 +510,10 @@ def download_urls(urls, title, ext, total_size, output_dir = '.', refer = None, print('Real URLs:\n', urls, '\n') return + if player: + launch_player(player, urls) + return + if not total_size: try: total_size = urls_size(urls) @@ -587,6 +597,10 @@ def download_urls_chunked(urls, title, ext, total_size, output_dir = '.', refer print('Real URLs:\n', urls, '\n') return + if player: + launch_player(player, urls) + return + assert ext in ('ts') title = legitimize(title) @@ -792,6 +806,7 @@ def script_main(script_name, download, download_playlist = None): -u | --url Display the real URLs of videos without downloading. -n | --no-merge Don't merge video parts. -o | --output-dir Set the output directory for downloaded videos. + -p | --player Directly play the video with PLAYER like vlc/smplayer -x | --http-proxy Use specific HTTP proxy for downloading. --no-proxy Don't use any proxy. (ignore $http_proxy) -S | --sogou Use a Sogou proxy server for downloading. @@ -799,8 +814,8 @@ def script_main(script_name, download, download_playlist = None): --debug Show traceback on KeyboardInterrupt. ''' - short_opts = 'VhfiunSo:x:' - opts = ['version', 'help', 'force', 'info', 'url', 'no-merge', 'no-proxy', 'debug', 'sogou', 'output-dir=', 'http-proxy=', 'sogou-proxy=', 'sogou-env='] + short_opts = 'VhfiunSo:p:x:' + opts = ['version', 'help', 'force', 'info', 'url', 'no-merge', 'no-proxy', 'debug', 'sogou', 'output-dir=', 'player=', 'http-proxy=', 'sogou-proxy=', 'sogou-env='] if download_playlist: short_opts = 'l' + short_opts opts = ['playlist'] + opts @@ -814,6 +829,7 @@ def script_main(script_name, download, download_playlist = None): global force global dry_run + global player global sogou_proxy global sogou_env @@ -841,19 +857,21 @@ def script_main(script_name, download, download_playlist = None): playlist = True elif o in ('-n', '--no-merge'): merge = False - elif o in ('--no-proxy'): + elif o in ('--no-proxy',): proxy = '' - elif o in ('--debug'): + elif o in ('--debug',): traceback = True elif o in ('-o', '--output-dir'): output_dir = a + elif o in ('-p', '--player'): + player = a elif o in ('-x', '--http-proxy'): proxy = a elif o in ('-S', '--sogou'): sogou_proxy = ("0.0.0.0", 0) - elif o in ('--sogou-proxy'): + elif o in ('--sogou-proxy',): sogou_proxy = parse_host(a) - elif o in ('--sogou-env'): + elif o in ('--sogou-env',): sogou_env = a else: log.e("try 'you-get --help' for more options")