mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-10 01:02:13 +01:00
[ie/bilibili] Fix --geo-verification-proxy
support (#9817)
Closes #9797 Authored by: fireattack
This commit is contained in:
parent
06d52c8731
commit
2338827072
1 changed files with 10 additions and 8 deletions
|
@ -93,11 +93,11 @@ def extract_formats(self, play_info):
|
||||||
|
|
||||||
return formats
|
return formats
|
||||||
|
|
||||||
def _download_playinfo(self, video_id, cid):
|
def _download_playinfo(self, video_id, cid, headers=None):
|
||||||
return self._download_json(
|
return self._download_json(
|
||||||
'https://api.bilibili.com/x/player/playurl', video_id,
|
'https://api.bilibili.com/x/player/playurl', video_id,
|
||||||
query={'bvid': video_id, 'cid': cid, 'fnval': 4048},
|
query={'bvid': video_id, 'cid': cid, 'fnval': 4048},
|
||||||
note=f'Downloading video formats for cid {cid}')['data']
|
note=f'Downloading video formats for cid {cid}', headers=headers)['data']
|
||||||
|
|
||||||
def json2srt(self, json_data):
|
def json2srt(self, json_data):
|
||||||
srt_data = ''
|
srt_data = ''
|
||||||
|
@ -493,7 +493,8 @@ class BiliBiliIE(BilibiliBaseIE):
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
webpage, urlh = self._download_webpage_handle(url, video_id)
|
headers = self.geo_verification_headers()
|
||||||
|
webpage, urlh = self._download_webpage_handle(url, video_id, headers=headers)
|
||||||
if not self._match_valid_url(urlh.url):
|
if not self._match_valid_url(urlh.url):
|
||||||
return self.url_result(urlh.url)
|
return self.url_result(urlh.url)
|
||||||
|
|
||||||
|
@ -531,7 +532,7 @@ def _real_extract(self, url):
|
||||||
self._download_json(
|
self._download_json(
|
||||||
'https://api.bilibili.com/x/player/pagelist', video_id,
|
'https://api.bilibili.com/x/player/pagelist', video_id,
|
||||||
fatal=False, query={'bvid': video_id, 'jsonp': 'jsonp'},
|
fatal=False, query={'bvid': video_id, 'jsonp': 'jsonp'},
|
||||||
note='Extracting videos in anthology'),
|
note='Extracting videos in anthology', headers=headers),
|
||||||
'data', expected_type=list) or []
|
'data', expected_type=list) or []
|
||||||
is_anthology = len(page_list_json) > 1
|
is_anthology = len(page_list_json) > 1
|
||||||
|
|
||||||
|
@ -552,7 +553,7 @@ def _real_extract(self, url):
|
||||||
|
|
||||||
festival_info = {}
|
festival_info = {}
|
||||||
if is_festival:
|
if is_festival:
|
||||||
play_info = self._download_playinfo(video_id, cid)
|
play_info = self._download_playinfo(video_id, cid, headers=headers)
|
||||||
|
|
||||||
festival_info = traverse_obj(initial_state, {
|
festival_info = traverse_obj(initial_state, {
|
||||||
'uploader': ('videoInfo', 'upName'),
|
'uploader': ('videoInfo', 'upName'),
|
||||||
|
@ -666,14 +667,15 @@ class BiliBiliBangumiIE(BilibiliBaseIE):
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
episode_id = self._match_id(url)
|
episode_id = self._match_id(url)
|
||||||
webpage = self._download_webpage(url, episode_id)
|
headers = self.geo_verification_headers()
|
||||||
|
webpage = self._download_webpage(url, episode_id, headers=headers)
|
||||||
|
|
||||||
if '您所在的地区无法观看本片' in webpage:
|
if '您所在的地区无法观看本片' in webpage:
|
||||||
raise GeoRestrictedError('This video is restricted')
|
raise GeoRestrictedError('This video is restricted')
|
||||||
elif '正在观看预览,大会员免费看全片' in webpage:
|
elif '正在观看预览,大会员免费看全片' in webpage:
|
||||||
self.raise_login_required('This video is for premium members only')
|
self.raise_login_required('This video is for premium members only')
|
||||||
|
|
||||||
headers = {'Referer': url, **self.geo_verification_headers()}
|
headers['Referer'] = url
|
||||||
play_info = self._download_json(
|
play_info = self._download_json(
|
||||||
'https://api.bilibili.com/pgc/player/web/v2/playurl', episode_id,
|
'https://api.bilibili.com/pgc/player/web/v2/playurl', episode_id,
|
||||||
'Extracting episode', query={'fnval': '4048', 'ep_id': episode_id},
|
'Extracting episode', query={'fnval': '4048', 'ep_id': episode_id},
|
||||||
|
@ -724,7 +726,7 @@ def _real_extract(self, url):
|
||||||
'duration': float_or_none(play_info.get('timelength'), scale=1000),
|
'duration': float_or_none(play_info.get('timelength'), scale=1000),
|
||||||
'subtitles': self.extract_subtitles(episode_id, episode_info.get('cid'), aid=aid),
|
'subtitles': self.extract_subtitles(episode_id, episode_info.get('cid'), aid=aid),
|
||||||
'__post_extractor': self.extract_comments(aid),
|
'__post_extractor': self.extract_comments(aid),
|
||||||
'http_headers': headers,
|
'http_headers': {'Referer': url},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue