From 95eea9f5113099bf1d620ef1038acb9f147a98a5 Mon Sep 17 00:00:00 2001 From: Mort Yao Date: Sat, 28 Jun 2014 18:10:29 +0200 Subject: [PATCH] add option: --format --- README.md | 1 + README.txt | 1 + src/you_get/common.py | 21 ++++++++++++++------- src/you_get/extractor/__main__.py | 8 ++++---- src/you_get/extractor/youku.py | 5 +++++ 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a776f827..1c2b3270 100644 --- a/README.md +++ b/README.md @@ -176,6 +176,7 @@ For a complete list of all available options, see: -i | --info Display the information of videos without downloading. -u | --url Display the real URLs of videos without downloading. -n | --no-merge Don't merge video parts. + -F | --format Video format code. -c | --cookies Load NetScape's cookies.txt file. -o | --output-dir Set the output directory for downloaded videos. -p | --player Directly play the video with PLAYER like vlc/smplayer. diff --git a/README.txt b/README.txt index 805dc9e7..7b91e048 100644 --- a/README.txt +++ b/README.txt @@ -184,6 +184,7 @@ For a complete list of all available options, see:: -i | --info Display the information of videos without downloading. -u | --url Display the real URLs of videos without downloading. -n | --no-merge Don't merge video parts. + -F | --format Video format code. -c | --cookies Load NetScape's cookies.txt file. -o | --output-dir Set the output directory for downloaded videos. -p | --player Directly play the video with PLAYER like vlc/smplayer. diff --git a/src/you_get/common.py b/src/you_get/common.py index 9e6b18c0..7375c524 100644 --- a/src/you_get/common.py +++ b/src/you_get/common.py @@ -790,7 +790,7 @@ def set_http_proxy(proxy): opener = request.build_opener(proxy_support) request.install_opener(opener) -def download_main(download, download_playlist, urls, playlist, output_dir, merge, info_only): +def download_main(download, download_playlist, urls, playlist, **kwargs): for url in urls: if url.startswith('https://'): url = url[8:] @@ -798,9 +798,9 @@ def download_main(download, download_playlist, urls, playlist, output_dir, merge url = 'http://' + url if playlist: - download_playlist(url, output_dir = output_dir, merge = merge, info_only = info_only) + download_playlist(url, **kwargs) else: - download(url, output_dir = output_dir, merge = merge, info_only = info_only) + download(url, **kwargs) def get_version(): try: @@ -825,6 +825,7 @@ def script_main(script_name, download, download_playlist = None): -u | --url Display the real URLs of videos without downloading. -c | --cookies Load NetScape's cookies.txt file. -n | --no-merge Don't merge video parts. + -F | --format Video format code. -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. @@ -835,8 +836,8 @@ def script_main(script_name, download, download_playlist = None): --debug Show traceback on KeyboardInterrupt. ''' - short_opts = 'Vhfiuc:nSo:p:x:y:' - opts = ['version', 'help', 'force', 'info', 'url', 'cookies', 'no-merge', 'no-proxy', 'debug', 'sogou', 'output-dir=', 'player=', 'http-proxy=', 'extractor-proxy=', 'sogou-proxy=', 'sogou-env='] + short_opts = 'Vhfiuc:nSF:o:p:x:y:' + opts = ['version', 'help', 'force', 'info', 'url', 'cookies', 'no-merge', 'no-proxy', 'debug', 'sogou', 'format=', 'stream=', 'output-dir=', 'player=', 'http-proxy=', 'extractor-proxy=', 'sogou-proxy=', 'sogou-env='] if download_playlist: short_opts = 'l' + short_opts opts = ['playlist'] + opts @@ -860,6 +861,7 @@ def script_main(script_name, download, download_playlist = None): info_only = False playlist = False merge = True + stream_id = None output_dir = '.' proxy = None extractor_proxy = None @@ -890,6 +892,8 @@ def script_main(script_name, download, download_playlist = None): proxy = '' elif o in ('--debug',): traceback = True + elif o in ('-F', '--format', '--stream'): + stream_id = a elif o in ('-o', '--output-dir'): output_dir = a elif o in ('-p', '--player'): @@ -927,7 +931,10 @@ def script_main(script_name, download, download_playlist = None): set_http_proxy(proxy) try: - download_main(download, download_playlist, args, playlist, output_dir, merge, info_only) + if stream_id: + download_main(download, download_playlist, args, playlist, stream_id=stream_id, output_dir=output_dir, merge=merge, info_only=info_only) + else: + download_main(download, download_playlist, args, playlist, output_dir=output_dir, merge=merge, info_only=info_only) except KeyboardInterrupt: if traceback: raise @@ -992,7 +999,7 @@ class VideoExtractor(): print(" size: %s MiB (%s bytes)" % (round(stream['size'] / 1048576, 1), stream['size'])) else: print(" size: Unknown") - #print(" # download-with: \033[4myou-get --stream=%s\033[0m" % stream_id) + print(" # download-with: \033[4myou-get --format=%s [URL]\033[0m" % stream_id) print() def p(self, stream_id=None): diff --git a/src/you_get/extractor/__main__.py b/src/you_get/extractor/__main__.py index bbe15a33..6b8a6da8 100644 --- a/src/you_get/extractor/__main__.py +++ b/src/you_get/extractor/__main__.py @@ -82,13 +82,13 @@ def url_to_module(url): else: return url_to_module(location) -def any_download(url, output_dir='.', merge=True, info_only=False): +def any_download(url, **kwargs): m, url = url_to_module(url) - m.download(url, output_dir=output_dir, merge=merge, info_only=info_only) + m.download(url, **kwargs) -def any_download_playlist(url, output_dir='.', merge=True, info_only=False): +def any_download_playlist(url, **kwargs): m, url = url_to_module(url) - m.download_playlist(url, output_dir=output_dir, merge=merge, info_only=info_only) + m.download_playlist(url, **kwargs) def main(): script_main('you-get', any_download, any_download_playlist) diff --git a/src/you_get/extractor/youku.py b/src/you_get/extractor/youku.py index 998c1579..cfbfd609 100644 --- a/src/you_get/extractor/youku.py +++ b/src/you_get/extractor/youku.py @@ -61,6 +61,11 @@ class Youku(VideoExtractor): if 'stream_id' in kwargs and kwargs['stream_id']: # Extract the stream stream_id = kwargs['stream_id'] + + if stream_id not in self.streams: + log.e('[Failed] Invalid video format.') + log.e('Use without specifying any video format to check all available formats.') + exit(2) else: # Extract stream with the best quality stream_id = self.streams_sorted[0]['id']