mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-08-26 06:18:29 +00:00
[ie/weibo] Fix extractors (#14012)
Closes #14012 Authored by: AzartX47, bashonly Co-authored-by: bashonly <88596187+bashonly@users.noreply.github.com>
This commit is contained in:
parent
aea85d525e
commit
8e3f8065af
@ -52,13 +52,16 @@ def _update_visitor_cookies(self, visitor_url, video_id):
|
||||
'_rand': random.random(),
|
||||
})
|
||||
|
||||
def _weibo_download_json(self, url, video_id, *args, fatal=True, note='Downloading JSON metadata', **kwargs):
|
||||
# XXX: Always fatal; _download_webpage_handle only returns False (not a tuple) on error
|
||||
webpage, urlh = self._download_webpage_handle(url, video_id, *args, fatal=fatal, note=note, **kwargs)
|
||||
def _weibo_download_json(self, url, video_id, note='Downloading JSON metadata', data=None, headers=None, query=None):
|
||||
headers = {
|
||||
'Referer': 'https://weibo.com/',
|
||||
**(headers or {}),
|
||||
}
|
||||
webpage, urlh = self._download_webpage_handle(url, video_id, note=note, data=data, headers=headers, query=query)
|
||||
if urllib.parse.urlparse(urlh.url).netloc == 'passport.weibo.com':
|
||||
self._update_visitor_cookies(urlh.url, video_id)
|
||||
webpage = self._download_webpage(url, video_id, *args, fatal=fatal, note=note, **kwargs)
|
||||
return self._parse_json(webpage, video_id, fatal=fatal)
|
||||
webpage = self._download_webpage(url, video_id, note=note, data=data, headers=headers, query=query)
|
||||
return self._parse_json(webpage, video_id)
|
||||
|
||||
def _extract_formats(self, video_info):
|
||||
media_info = traverse_obj(video_info, ('page_info', 'media_info'))
|
||||
@ -189,7 +192,8 @@ class WeiboIE(WeiboBaseIE):
|
||||
def _real_extract(self, url):
|
||||
video_id = self._match_id(url)
|
||||
|
||||
meta = self._weibo_download_json(f'https://weibo.com/ajax/statuses/show?id={video_id}', video_id)
|
||||
meta = self._weibo_download_json(
|
||||
'https://weibo.com/ajax/statuses/show', video_id, query={'id': video_id})
|
||||
mix_media_info = traverse_obj(meta, ('mix_media_info', 'items', ...))
|
||||
if not mix_media_info:
|
||||
return self._parse_video_info(meta)
|
||||
@ -205,7 +209,7 @@ def _entries(self, mix_media_info):
|
||||
|
||||
|
||||
class WeiboVideoIE(WeiboBaseIE):
|
||||
_VALID_URL = r'https?://(?:www\.)?weibo\.com/tv/show/(?P<id>\d+:\d+)'
|
||||
_VALID_URL = r'https?://(?:www\.)?weibo\.com/tv/show/(?P<id>\d+:(?:[\da-f]{32}|\d{16,}))'
|
||||
_TESTS = [{
|
||||
'url': 'https://weibo.com/tv/show/1034:4797699866951785?from=old_pc_videoshow',
|
||||
'info_dict': {
|
||||
@ -227,6 +231,27 @@ class WeiboVideoIE(WeiboBaseIE):
|
||||
'repost_count': int,
|
||||
'_old_archive_ids': ['weibomobile 4797700463137878'],
|
||||
},
|
||||
}, {
|
||||
'url': 'https://weibo.com/tv/show/1034:633c288cc043d0ca7808030f1157da64',
|
||||
'info_dict': {
|
||||
'id': '4189191225395228',
|
||||
'ext': 'mp4',
|
||||
'display_id': 'FBqgOmDxO',
|
||||
'title': '柴犬柴犬的秒拍视频',
|
||||
'alt_title': '柴犬柴犬的秒拍视频',
|
||||
'description': '午睡当然是要甜甜蜜蜜的啦![坏笑] Instagram:shibainu.gaku http://t.cn/RHbmjzW \u200B\u200B\u200B',
|
||||
'uploader': '柴犬柴犬',
|
||||
'uploader_id': '5926682210',
|
||||
'uploader_url': 'https://weibo.com/u/5926682210',
|
||||
'view_count': int,
|
||||
'like_count': int,
|
||||
'repost_count': int,
|
||||
'duration': 53,
|
||||
'thumbnail': 'https://wx1.sinaimg.cn/large/006t5KMygy1fmu31fsqbej30hs0hstav.jpg',
|
||||
'timestamp': 1514264429,
|
||||
'upload_date': '20171226',
|
||||
'_old_archive_ids': ['weibomobile 4189191225395228'],
|
||||
},
|
||||
}]
|
||||
|
||||
def _real_extract(self, url):
|
||||
@ -234,8 +259,8 @@ def _real_extract(self, url):
|
||||
|
||||
post_data = f'data={{"Component_Play_Playinfo":{{"oid":"{video_id}"}}}}'.encode()
|
||||
video_info = self._weibo_download_json(
|
||||
f'https://weibo.com/tv/api/component?page=%2Ftv%2Fshow%2F{video_id.replace(":", "%3A")}',
|
||||
video_id, headers={'Referer': url}, data=post_data)['data']['Component_Play_Playinfo']
|
||||
'https://weibo.com/tv/api/component', video_id, data=post_data, headers={'Referer': url},
|
||||
query={'page': f'/tv/show/{video_id}'})['data']['Component_Play_Playinfo']
|
||||
return self.url_result(f'https://weibo.com/0/{video_info["mid"]}', WeiboIE)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user