Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated bilibili extractor to support new site code parsing #3003

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 56 additions & 14 deletions src/you_get/extractors/bilibili.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,21 +338,55 @@ def prepare(self, **kwargs):

# bangumi
elif sort == 'bangumi':
ep_id = ""
avid = ""
cid = ""

initial_state_text = match1(html_content, r'__INITIAL_STATE__=(.*?);\(function\(\)') # FIXME
initial_state = json.loads(initial_state_text)
if (initial_state_text):
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)

# 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
self.title = initial_state['h1Title']

# set video title
self.title = initial_state['h1Title']
# construct playinfos
ep_id = initial_state['epInfo']['id']
avid = initial_state['epInfo']['aid']
cid = initial_state['epInfo']['cid']
else:
initial_state_text = match1(html_content, r'\"episodes\":(.*?)\,\"user_status')
pinitial_state = json.loads(initial_state_text)

epn = len(pinitial_state)
if epn > 1 and not kwargs.get('playlist'):
log.w('This bangumi currently has %s videos. (use --playlist to download all videos.)' % epn)

initial_state = {}
for dic in pinitial_state:
query_start = self.url.find('?')
url = ""

if query_start > 0:
url = self.url[0:query_start].rstrip('/')
else:
url = self.url.rstrip('/')

if dic['link'] == url:
initial_state = dic
break

self.title = initial_state['share_copy']

# construct playinfos
ep_id = initial_state['id']
avid = initial_state['aid']
cid = initial_state['cid']

# construct playinfos
ep_id = initial_state['epInfo']['id']
avid = initial_state['epInfo']['aid']
cid = initial_state['epInfo']['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))
Expand Down Expand Up @@ -716,10 +750,18 @@ def download_playlist_by_url(self, url, **kwargs):
self.download(**kwargs)

elif sort == 'bangumi':
episodes = []
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']:
if (initial_state_text):
# initial_state = json.loads(initial_state_text)
episodes = json.loads(initial_state_text)['epList']
else:
initial_state_text = match1(html_content, r'\"episodes\":(.*?)\,\"user_status')
# initial_state = json.loads(initial_state_text)
episodes = json.loads(initial_state_text)

epn, i = len(episodes), 0
for ep in episodes:
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
Expand Down