Skip to content

Commit

Permalink
Merge branch 'sceext2-json-output' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
soimort committed Sep 25, 2015
2 parents 27e2a85 + 0c18a08 commit 2f0e374
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/you_get/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
--no-proxy Don't use any proxy. (ignore $http_proxy)
--debug Show traceback on KeyboardInterrupt.
--json Output the information of videos in json text without downloading.
'''

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:
short_opts = 'l' + short_opts
opts = ['playlist'] + opts
Expand All @@ -884,6 +885,7 @@ def script_main(script_name, download, download_playlist = None):
global cookies_txt
cookies_txt = None

json_output = False
info_only = False
playlist = False
merge = True
Expand All @@ -907,6 +909,11 @@ def script_main(script_name, download, download_playlist = None):
info_only = True
elif o in ('-u', '--url'):
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'):
from http import cookiejar
cookies_txt = cookiejar.MozillaCookieJar(a)
Expand Down Expand Up @@ -943,14 +950,14 @@ def script_main(script_name, download, download_playlist = None):
try:
if stream_id:
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:
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:
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:
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:
if traceback:
raise
Expand Down
5 changes: 4 additions & 1 deletion src/you_get/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from .common import match1, download_urls, parse_host, set_proxy, unset_proxy
from .util import log
from . import json_output

class Extractor():
def __init__(self, *args):
Expand Down Expand Up @@ -136,7 +137,9 @@ def p_playlist(self, stream_id=None):
print("videos:")

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']:
# Display the stream
stream_id = kwargs['stream_id']
Expand Down
15 changes: 15 additions & 0 deletions src/you_get/json_output.py
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit 2f0e374

Please sign in to comment.