Merge branch 'sceext2-json-output' into develop

This commit is contained in:
Mort Yao 2015-09-25 21:49:17 +02:00
commit 2f0e374fbd
3 changed files with 31 additions and 6 deletions

View File

@ -862,10 +862,11 @@ def script_main(script_name, download, download_playlist = None):
-y | --extractor-proxy <HOST:PORT> Use specific HTTP proxy for extracting stream data. -y | --extractor-proxy <HOST:PORT> Use specific HTTP proxy for extracting stream data.
--no-proxy Don't use any proxy. (ignore $http_proxy) --no-proxy Don't use any proxy. (ignore $http_proxy)
--debug Show traceback on KeyboardInterrupt. --debug Show traceback on KeyboardInterrupt.
--json Output the information of videos in json text without downloading.
''' '''
short_opts = 'Vhfiuc:nF:o:p:x:y:' short_opts = 'Vhfiuc:nF:o:p:x:y:'
opts = ['version', 'help', 'force', 'info', 'url', 'cookies', 'no-merge', 'no-proxy', 'debug', 'format=', 'stream=', 'itag=', 'output-dir=', 'player=', 'http-proxy=', 'extractor-proxy=', 'lang='] opts = ['version', 'help', 'force', 'info', 'url', 'cookies', 'no-merge', 'no-proxy', 'debug', 'json', 'format=', 'stream=', 'itag=', 'output-dir=', 'player=', 'http-proxy=', 'extractor-proxy=', 'lang=']
if download_playlist: if download_playlist:
short_opts = 'l' + short_opts short_opts = 'l' + short_opts
opts = ['playlist'] + opts opts = ['playlist'] + opts
@ -884,6 +885,7 @@ def script_main(script_name, download, download_playlist = None):
global cookies_txt global cookies_txt
cookies_txt = None cookies_txt = None
json_output = False
info_only = False info_only = False
playlist = False playlist = False
merge = True merge = True
@ -907,6 +909,11 @@ def script_main(script_name, download, download_playlist = None):
info_only = True info_only = True
elif o in ('-u', '--url'): elif o in ('-u', '--url'):
dry_run = True dry_run = True
elif o in ('--json', ):
json_output = True
# to fix extractors not use VideoExtractor
info_only = True
dry_run = True
elif o in ('-c', '--cookies'): elif o in ('-c', '--cookies'):
from http import cookiejar from http import cookiejar
cookies_txt = cookiejar.MozillaCookieJar(a) cookies_txt = cookiejar.MozillaCookieJar(a)
@ -943,14 +950,14 @@ def script_main(script_name, download, download_playlist = None):
try: try:
if stream_id: if stream_id:
if not extractor_proxy: if not extractor_proxy:
download_main(download, download_playlist, args, playlist, stream_id=stream_id, output_dir=output_dir, merge=merge, info_only=info_only) download_main(download, download_playlist, args, playlist, stream_id=stream_id, output_dir=output_dir, merge=merge, info_only=info_only, json_output=json_output)
else: else:
download_main(download, download_playlist, args, playlist, stream_id=stream_id, extractor_proxy=extractor_proxy, output_dir=output_dir, merge=merge, info_only=info_only) download_main(download, download_playlist, args, playlist, stream_id=stream_id, extractor_proxy=extractor_proxy, output_dir=output_dir, merge=merge, info_only=info_only, json_output=json_output)
else: else:
if not extractor_proxy: if not extractor_proxy:
download_main(download, download_playlist, args, playlist, output_dir=output_dir, merge=merge, info_only=info_only) download_main(download, download_playlist, args, playlist, output_dir=output_dir, merge=merge, info_only=info_only, json_output=json_output)
else: else:
download_main(download, download_playlist, args, playlist, extractor_proxy=extractor_proxy, output_dir=output_dir, merge=merge, info_only=info_only) download_main(download, download_playlist, args, playlist, extractor_proxy=extractor_proxy, output_dir=output_dir, merge=merge, info_only=info_only, json_output=json_output)
except KeyboardInterrupt: except KeyboardInterrupt:
if traceback: if traceback:
raise raise

View File

@ -2,6 +2,7 @@
from .common import match1, download_urls, parse_host, set_proxy, unset_proxy from .common import match1, download_urls, parse_host, set_proxy, unset_proxy
from .util import log from .util import log
from . import json_output
class Extractor(): class Extractor():
def __init__(self, *args): def __init__(self, *args):
@ -136,7 +137,9 @@ class VideoExtractor():
print("videos:") print("videos:")
def download(self, **kwargs): def download(self, **kwargs):
if 'info_only' in kwargs and kwargs['info_only']: if 'json_output' in kwargs and kwargs['json_output']:
json_output.output(self)
elif 'info_only' in kwargs and kwargs['info_only']:
if 'stream_id' in kwargs and kwargs['stream_id']: if 'stream_id' in kwargs and kwargs['stream_id']:
# Display the stream # Display the stream
stream_id = kwargs['stream_id'] stream_id = kwargs['stream_id']

View File

@ -0,0 +1,15 @@
import json
def output(video_extractor, pretty_print=True):
ve = video_extractor
out = {}
out['url'] = ve.url
out['title'] = ve.title
out['site'] = ve.name
out['streams'] = ve.streams
if pretty_print:
print(json.dumps(out, indent=4, sort_keys=True, ensure_ascii=False))
else:
print(json.dumps(out))