mirror of
https://github.com/soimort/you-get.git
synced 2025-01-23 21:45:02 +03:00
--json option now can support more extractors not using VideoExtractor
This commit is contained in:
parent
5eb9cebe4e
commit
1d7758b107
@ -12,8 +12,10 @@ from urllib import request, parse
|
|||||||
from .version import __version__
|
from .version import __version__
|
||||||
from .util import log
|
from .util import log
|
||||||
from .util.strings import get_filename, unescape_html
|
from .util.strings import get_filename, unescape_html
|
||||||
|
from . import json_output as json_output_
|
||||||
|
|
||||||
dry_run = False
|
dry_run = False
|
||||||
|
json_output = False
|
||||||
force = False
|
force = False
|
||||||
player = None
|
player = None
|
||||||
extractor_proxy = None
|
extractor_proxy = None
|
||||||
@ -519,6 +521,9 @@ def get_output_filename(urls, title, ext, output_dir, merge):
|
|||||||
|
|
||||||
def download_urls(urls, title, ext, total_size, output_dir='.', refer=None, merge=True, faker=False):
|
def download_urls(urls, title, ext, total_size, output_dir='.', refer=None, merge=True, faker=False):
|
||||||
assert urls
|
assert urls
|
||||||
|
if json_output:
|
||||||
|
json_output_.download_urls(urls=urls, title=title, ext=ext, total_size=total_size, refer=refer)
|
||||||
|
return
|
||||||
if dry_run:
|
if dry_run:
|
||||||
print('Real URLs:\n%s' % '\n'.join(urls))
|
print('Real URLs:\n%s' % '\n'.join(urls))
|
||||||
return
|
return
|
||||||
@ -724,6 +729,9 @@ def playlist_not_supported(name):
|
|||||||
return f
|
return f
|
||||||
|
|
||||||
def print_info(site_info, title, type, size):
|
def print_info(site_info, title, type, size):
|
||||||
|
if json_output:
|
||||||
|
json_output_.print_info(site_info=site_info, title=title, type=type, size=size)
|
||||||
|
return
|
||||||
if type:
|
if type:
|
||||||
type = type.lower()
|
type = type.lower()
|
||||||
if type in ['3gp']:
|
if type in ['3gp']:
|
||||||
@ -880,12 +888,12 @@ def script_main(script_name, download, download_playlist = None):
|
|||||||
|
|
||||||
global force
|
global force
|
||||||
global dry_run
|
global dry_run
|
||||||
|
global json_output
|
||||||
global player
|
global player
|
||||||
global extractor_proxy
|
global extractor_proxy
|
||||||
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
|
||||||
@ -912,8 +920,8 @@ def script_main(script_name, download, download_playlist = None):
|
|||||||
elif o in ('--json', ):
|
elif o in ('--json', ):
|
||||||
json_output = True
|
json_output = True
|
||||||
# to fix extractors not use VideoExtractor
|
# to fix extractors not use VideoExtractor
|
||||||
info_only = True
|
|
||||||
dry_run = True
|
dry_run = True
|
||||||
|
info_only = False
|
||||||
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)
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
# save info from common.print_info()
|
||||||
|
last_info = None
|
||||||
|
|
||||||
def output(video_extractor, pretty_print=True):
|
def output(video_extractor, pretty_print=True):
|
||||||
ve = video_extractor
|
ve = video_extractor
|
||||||
out = {}
|
out = {}
|
||||||
@ -13,3 +16,30 @@ def output(video_extractor, pretty_print=True):
|
|||||||
else:
|
else:
|
||||||
print(json.dumps(out))
|
print(json.dumps(out))
|
||||||
|
|
||||||
|
# a fake VideoExtractor object to save info
|
||||||
|
class VideoExtractor(object):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def print_info(site_info=None, title=None, type=None, size=None):
|
||||||
|
global last_info
|
||||||
|
# create a VideoExtractor and save info for download_urls()
|
||||||
|
ve = VideoExtractor()
|
||||||
|
last_info = ve
|
||||||
|
ve.name = site_info
|
||||||
|
ve.title = title
|
||||||
|
ve.url = None
|
||||||
|
|
||||||
|
def download_urls(urls=None, title=None, ext=None, total_size=None, refer=None):
|
||||||
|
ve = last_info
|
||||||
|
# save download info in streams
|
||||||
|
stream = {}
|
||||||
|
stream['container'] = ext
|
||||||
|
stream['size'] = total_size
|
||||||
|
stream['src'] = urls
|
||||||
|
if refer:
|
||||||
|
stream['refer'] = refer
|
||||||
|
stream['video_profile'] = '__default__'
|
||||||
|
ve.streams = {}
|
||||||
|
ve.streams['__default__'] = stream
|
||||||
|
output(ve)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user