mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-03-01 15:40:28 +01:00
[ie/weibo] Support playlists (#12284)
Closes #12283 Authored by: 4ft35t
This commit is contained in:
parent
7508e34f20
commit
0bb3978862
@ -12,6 +12,7 @@ from ..utils import (
|
|||||||
str_or_none,
|
str_or_none,
|
||||||
strip_jsonp,
|
strip_jsonp,
|
||||||
traverse_obj,
|
traverse_obj,
|
||||||
|
truncate_string,
|
||||||
url_or_none,
|
url_or_none,
|
||||||
urlencode_postdata,
|
urlencode_postdata,
|
||||||
urljoin,
|
urljoin,
|
||||||
@ -96,7 +97,8 @@ class WeiboBaseIE(InfoExtractor):
|
|||||||
})
|
})
|
||||||
return formats
|
return formats
|
||||||
|
|
||||||
def _parse_video_info(self, video_info, video_id=None):
|
def _parse_video_info(self, video_info):
|
||||||
|
video_id = traverse_obj(video_info, (('id', 'id_str', 'mid'), {str_or_none}, any))
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'extractor_key': WeiboIE.ie_key(),
|
'extractor_key': WeiboIE.ie_key(),
|
||||||
@ -105,9 +107,10 @@ class WeiboBaseIE(InfoExtractor):
|
|||||||
'http_headers': {'Referer': 'https://weibo.com/'},
|
'http_headers': {'Referer': 'https://weibo.com/'},
|
||||||
'_old_archive_ids': [make_archive_id('WeiboMobile', video_id)],
|
'_old_archive_ids': [make_archive_id('WeiboMobile', video_id)],
|
||||||
**traverse_obj(video_info, {
|
**traverse_obj(video_info, {
|
||||||
'id': (('id', 'id_str', 'mid'), {str_or_none}),
|
|
||||||
'display_id': ('mblogid', {str_or_none}),
|
'display_id': ('mblogid', {str_or_none}),
|
||||||
'title': ('page_info', 'media_info', ('video_title', 'kol_title', 'name'), {str}, filter),
|
'title': ('page_info', 'media_info', ('video_title', 'kol_title', 'name'),
|
||||||
|
{lambda x: x.replace('\n', ' ')}, {truncate_string(left=50)}, filter),
|
||||||
|
'alt_title': ('page_info', 'media_info', ('video_title', 'kol_title', 'name'), {str}, filter),
|
||||||
'description': ('text_raw', {str}),
|
'description': ('text_raw', {str}),
|
||||||
'duration': ('page_info', 'media_info', 'duration', {int_or_none}),
|
'duration': ('page_info', 'media_info', 'duration', {int_or_none}),
|
||||||
'timestamp': ('page_info', 'media_info', 'video_publish_time', {int_or_none}),
|
'timestamp': ('page_info', 'media_info', 'video_publish_time', {int_or_none}),
|
||||||
@ -129,9 +132,11 @@ class WeiboIE(WeiboBaseIE):
|
|||||||
'url': 'https://weibo.com/7827771738/N4xlMvjhI',
|
'url': 'https://weibo.com/7827771738/N4xlMvjhI',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '4910815147462302',
|
'id': '4910815147462302',
|
||||||
|
'_old_archive_ids': ['weibomobile 4910815147462302'],
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'display_id': 'N4xlMvjhI',
|
'display_id': 'N4xlMvjhI',
|
||||||
'title': '【睡前消息暑假版第一期:拉泰国一把 对中国有好处】',
|
'title': '【睡前消息暑假版第一期:拉泰国一把 对中国有好处】',
|
||||||
|
'alt_title': '【睡前消息暑假版第一期:拉泰国一把 对中国有好处】',
|
||||||
'description': 'md5:e2637a7673980d68694ea7c43cf12a5f',
|
'description': 'md5:e2637a7673980d68694ea7c43cf12a5f',
|
||||||
'duration': 918,
|
'duration': 918,
|
||||||
'timestamp': 1686312819,
|
'timestamp': 1686312819,
|
||||||
@ -149,9 +154,11 @@ class WeiboIE(WeiboBaseIE):
|
|||||||
'url': 'https://m.weibo.cn/status/4189191225395228',
|
'url': 'https://m.weibo.cn/status/4189191225395228',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '4189191225395228',
|
'id': '4189191225395228',
|
||||||
|
'_old_archive_ids': ['weibomobile 4189191225395228'],
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'display_id': 'FBqgOmDxO',
|
'display_id': 'FBqgOmDxO',
|
||||||
'title': '柴犬柴犬的秒拍视频',
|
'title': '柴犬柴犬的秒拍视频',
|
||||||
|
'alt_title': '柴犬柴犬的秒拍视频',
|
||||||
'description': 'md5:80f461ab5cdae6bbdb70efbf5a1db24f',
|
'description': 'md5:80f461ab5cdae6bbdb70efbf5a1db24f',
|
||||||
'duration': 53,
|
'duration': 53,
|
||||||
'timestamp': 1514264429,
|
'timestamp': 1514264429,
|
||||||
@ -166,34 +173,35 @@ class WeiboIE(WeiboBaseIE):
|
|||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
'url': 'https://m.weibo.cn/detail/4189191225395228',
|
'url': 'https://m.weibo.cn/detail/4189191225395228',
|
||||||
'info_dict': {
|
'only_matching': True,
|
||||||
'id': '4189191225395228',
|
|
||||||
'ext': 'mp4',
|
|
||||||
'display_id': 'FBqgOmDxO',
|
|
||||||
'title': '柴犬柴犬的秒拍视频',
|
|
||||||
'description': '午睡当然是要甜甜蜜蜜的啦![坏笑] Instagram:shibainu.gaku http://t.cn/RHbmjzW ',
|
|
||||||
'duration': 53,
|
|
||||||
'timestamp': 1514264429,
|
|
||||||
'upload_date': '20171226',
|
|
||||||
'thumbnail': r're:https://.*\.jpg',
|
|
||||||
'uploader': '柴犬柴犬',
|
|
||||||
'uploader_id': '5926682210',
|
|
||||||
'uploader_url': 'https://weibo.com/u/5926682210',
|
|
||||||
'view_count': int,
|
|
||||||
'like_count': int,
|
|
||||||
'repost_count': int,
|
|
||||||
},
|
|
||||||
}, {
|
}, {
|
||||||
'url': 'https://weibo.com/0/4224132150961381',
|
'url': 'https://weibo.com/0/4224132150961381',
|
||||||
'note': 'no playback_list example',
|
'note': 'no playback_list example',
|
||||||
'only_matching': True,
|
'only_matching': True,
|
||||||
|
}, {
|
||||||
|
'url': 'https://m.weibo.cn/detail/5120561132606436',
|
||||||
|
'info_dict': {
|
||||||
|
'id': '5120561132606436',
|
||||||
|
},
|
||||||
|
'playlist_count': 9,
|
||||||
}]
|
}]
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
|
|
||||||
return self._parse_video_info(self._weibo_download_json(
|
meta = self._weibo_download_json(f'https://weibo.com/ajax/statuses/show?id={video_id}', video_id)
|
||||||
f'https://weibo.com/ajax/statuses/show?id={video_id}', video_id))
|
mix_media_info = traverse_obj(meta, ('mix_media_info', 'items', ...))
|
||||||
|
if not mix_media_info:
|
||||||
|
return self._parse_video_info(meta)
|
||||||
|
|
||||||
|
return self.playlist_result(self._entries(mix_media_info), video_id)
|
||||||
|
|
||||||
|
def _entries(self, mix_media_info):
|
||||||
|
for media_info in traverse_obj(mix_media_info, lambda _, v: v['type'] != 'pic'):
|
||||||
|
yield self._parse_video_info(traverse_obj(media_info, {
|
||||||
|
'id': ('data', 'object_id'),
|
||||||
|
'page_info': {'media_info': ('data', 'media_info', {dict})},
|
||||||
|
}))
|
||||||
|
|
||||||
|
|
||||||
class WeiboVideoIE(WeiboBaseIE):
|
class WeiboVideoIE(WeiboBaseIE):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user