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
import json
import re
from ..common import *
from ..extractor import VideoExtractor
@ -339,21 +341,15 @@ class Bilibili(VideoExtractor):
# bangumi
elif sort == 'bangumi':
initial_state_text = match1(html_content, r'__INITIAL_STATE__=(.*?);\(function\(\)') # FIXME
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)
eposide = kwargs['eposide_data']
# set video title
self.title = initial_state['h1Title']
self.title = eposide['long_title']
# construct playinfos
ep_id = initial_state['epInfo']['id']
avid = initial_state['epInfo']['aid']
cid = initial_state['epInfo']['cid']
ep_id = eposide['ep_id']
avid = eposide['aid']
cid = eposide['cid']
playinfos = []
api_url = self.bilibili_bangumi_api(avid, cid, ep_id)
api_content = get_content(api_url, headers=self.bilibili_headers(referer=self.url))
@ -717,13 +713,17 @@ class Bilibili(VideoExtractor):
self.download(**kwargs)
elif sort == 'bangumi':
initial_state_text = match1(html_content, r'__INITIAL_STATE__=(.*?);\(function\(\)') # FIXME
initial_state = json.loads(initial_state_text)
epn, i = len(initial_state['epList']), 0
for ep in initial_state['epList']:
epId = re.search(r'"videoId":"ep(.*?)"', html_content).group(1)
eposide_content = get_content(url="https://api.bilibili.com/pgc/view/web/ep/list?ep_id=%s" % (epId),
headers=self.bilibili_headers(referer=self.url))
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))
ep_id = 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)
elif sort == 'bangumi_md':