mirror of
https://github.com/soimort/you-get.git
synced 2025-02-02 16:24:00 +03:00
feat(bilibili): add support for first option
This commit is contained in:
parent
2ba7493f12
commit
2fd06a4f67
@ -19,6 +19,9 @@ class Extractor():
|
||||
self.url = args[0]
|
||||
|
||||
class VideoExtractor():
|
||||
download_count = 0
|
||||
skip_count = 0
|
||||
|
||||
def __init__(self, *args):
|
||||
self.url = None
|
||||
self.title = None
|
||||
@ -177,6 +180,11 @@ class VideoExtractor():
|
||||
print("videos:")
|
||||
|
||||
def download(self, **kwargs):
|
||||
self.__class__.download_count += 1
|
||||
if self.__class__.skip_count and self.__class__.download_count < self.__class__.skip_count:
|
||||
log.i("skipped({}): {}".format(self.__class__.download_count, self.title))
|
||||
return
|
||||
|
||||
if 'json_output' in kwargs and kwargs['json_output']:
|
||||
json_output.output(self)
|
||||
elif 'info_only' in kwargs and kwargs['info_only']:
|
||||
|
@ -649,6 +649,16 @@ class Bilibili(VideoExtractor):
|
||||
log.e('[Error] Unsupported URL pattern.')
|
||||
exit(1)
|
||||
|
||||
args = kwargs.get('args')
|
||||
first = 0
|
||||
if ('first' in args and args.first!= None):
|
||||
first = int(args.first)
|
||||
if first < 0: first = 0
|
||||
if sort not in ['video', 'bangumi','bangumi_md','audio_menu']:
|
||||
args.first = None
|
||||
if first > 0:
|
||||
self.__class__.skip_count = first
|
||||
|
||||
# regular video
|
||||
if sort == 'video':
|
||||
initial_state_text = match1(html_content, r'__INITIAL_STATE__=(.*?);\(function\(\)') # FIXME
|
||||
@ -658,12 +668,16 @@ class Bilibili(VideoExtractor):
|
||||
|
||||
if pn == len(initial_state['videoData']['pages']):
|
||||
# non-interative video
|
||||
for pi in range(1, pn + 1):
|
||||
for pi in range(first+1, pn + 1):
|
||||
purl = 'https://www.bilibili.com/video/av%s?p=%s' % (aid, pi)
|
||||
self.__class__().download_by_url(purl, **kwargs)
|
||||
|
||||
else:
|
||||
# interative video
|
||||
if first > 0:
|
||||
args.first = None
|
||||
self.__class__.skip_count = first
|
||||
|
||||
search_node_list = []
|
||||
download_cid_set = set([initial_state['videoData']['cid']])
|
||||
params = {
|
||||
@ -720,7 +734,9 @@ class Bilibili(VideoExtractor):
|
||||
initial_state = json.loads(initial_state_text)
|
||||
epn, i = len(initial_state['epList']), 0
|
||||
for ep in initial_state['epList']:
|
||||
i += 1; log.w('Extracting %s of %s videos ...' % (i, epn))
|
||||
i += 1
|
||||
if i <= first: continue
|
||||
log.w('Extracting %s of %s videos ...' % (i, epn))
|
||||
ep_id = ep['id']
|
||||
epurl = 'https://www.bilibili.com/bangumi/play/ep%s/' % ep_id
|
||||
self.__class__().download_by_url(epurl, **kwargs)
|
||||
@ -730,7 +746,9 @@ class Bilibili(VideoExtractor):
|
||||
initial_state = json.loads(initial_state_text)
|
||||
epn, i = len(initial_state['mediaInfo']['episodes']), 0
|
||||
for ep in initial_state['mediaInfo']['episodes']:
|
||||
i += 1; log.w('Extracting %s of %s videos ...' % (i, epn))
|
||||
i += 1
|
||||
if i <= first: continue
|
||||
log.w('Extracting %s of %s videos ...' % (i, epn))
|
||||
ep_id = ep['ep_id']
|
||||
epurl = 'https://www.bilibili.com/bangumi/play/ep%s/' % ep_id
|
||||
self.__class__().download_by_url(epurl, **kwargs)
|
||||
@ -843,7 +861,9 @@ class Bilibili(VideoExtractor):
|
||||
menusong_info = json.loads(api_content)
|
||||
epn, i = len(menusong_info['data']['data']), 0
|
||||
for song in menusong_info['data']['data']:
|
||||
i += 1; log.w('Extracting %s of %s songs ...' % (i, epn))
|
||||
i += 1
|
||||
if i <= first: continue
|
||||
log.w('Extracting %s of %s songs ...' % (i, epn))
|
||||
url = 'https://www.bilibili.com/audio/au%s' % song['id']
|
||||
self.__class__().download_by_url(url, **kwargs)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user