bilibili download support

This commit is contained in:
ed 2024-09-03 09:44:30 +08:00
parent 59e1b4d6ef
commit abd65c3c14

View File

@ -1,4 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
import json
import re
from ..common import * from ..common import *
from ..extractor import VideoExtractor from ..extractor import VideoExtractor
@ -339,21 +341,15 @@ class Bilibili(VideoExtractor):
# bangumi # bangumi
elif sort == 'bangumi': elif sort == 'bangumi':
initial_state_text = match1(html_content, r'__INITIAL_STATE__=(.*?);\(function\(\)') # FIXME eposide = kwargs['eposide_data']
initial_state = json.loads(initial_state_text)
# warn if this bangumi has more than 1 video
epn = len(initial_state['epList'])
if epn > 1 and not kwargs.get('playlist'):
log.w('This bangumi currently has %s videos. (use --playlist to download all videos.)' % epn)
# set video title # set video title
self.title = initial_state['h1Title'] self.title = eposide['long_title']
# construct playinfos # construct playinfos
ep_id = initial_state['epInfo']['id'] ep_id = eposide['ep_id']
avid = initial_state['epInfo']['aid'] avid = eposide['aid']
cid = initial_state['epInfo']['cid'] cid = eposide['cid']
playinfos = [] playinfos = []
api_url = self.bilibili_bangumi_api(avid, cid, ep_id) api_url = self.bilibili_bangumi_api(avid, cid, ep_id)
api_content = get_content(api_url, headers=self.bilibili_headers(referer=self.url)) api_content = get_content(api_url, headers=self.bilibili_headers(referer=self.url))
@ -717,13 +713,17 @@ class Bilibili(VideoExtractor):
self.download(**kwargs) self.download(**kwargs)
elif sort == 'bangumi': elif sort == 'bangumi':
initial_state_text = match1(html_content, r'__INITIAL_STATE__=(.*?);\(function\(\)') # FIXME epId = re.search(r'"videoId":"ep(.*?)"', html_content).group(1)
initial_state = json.loads(initial_state_text) eposide_content = get_content(url="https://api.bilibili.com/pgc/view/web/ep/list?ep_id=%s" % (epId),
epn, i = len(initial_state['epList']), 0 headers=self.bilibili_headers(referer=self.url))
for ep in initial_state['epList']: eposide_json = json.loads(eposide_content)["result"]["episodes"]
epn, i = len(eposide_json), 0
for ep in eposide_json:
i += 1; log.w('Extracting %s of %s videos ...' % (i, epn)) i += 1; log.w('Extracting %s of %s videos ...' % (i, epn))
ep_id = ep['id'] ep_id = ep['id']
epurl = 'https://www.bilibili.com/bangumi/play/ep%s/' % ep_id epurl = 'https://www.bilibili.com/bangumi/play/ep%s/' % ep_id
kwargs['eposide_data'] = ep
ep['long_title']= ("%02d" % i) + ep['long_title']
self.__class__().download_by_url(epurl, **kwargs) self.__class__().download_by_url(epurl, **kwargs)
elif sort == 'bangumi_md': elif sort == 'bangumi_md':