mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-06-27 17:08:32 +00:00
parent
3bd3029160
commit
2600849bad
@ -7,12 +7,13 @@
|
|||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
|
clean_html,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
parse_duration,
|
parse_duration,
|
||||||
str_or_none,
|
str_or_none,
|
||||||
try_get,
|
try_get,
|
||||||
unescapeHTML,
|
unescapeHTML,
|
||||||
unified_strdate,
|
update_url,
|
||||||
update_url_query,
|
update_url_query,
|
||||||
url_or_none,
|
url_or_none,
|
||||||
)
|
)
|
||||||
@ -22,8 +23,8 @@
|
|||||||
class HuyaLiveIE(InfoExtractor):
|
class HuyaLiveIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.|m\.)?huya\.com/(?!(?:video/play/))(?P<id>[^/#?&]+)(?:\D|$)'
|
_VALID_URL = r'https?://(?:www\.|m\.)?huya\.com/(?!(?:video/play/))(?P<id>[^/#?&]+)(?:\D|$)'
|
||||||
IE_NAME = 'huya:live'
|
IE_NAME = 'huya:live'
|
||||||
IE_DESC = 'huya.com'
|
IE_DESC = '虎牙直播'
|
||||||
TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'https://www.huya.com/572329',
|
'url': 'https://www.huya.com/572329',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '572329',
|
'id': '572329',
|
||||||
@ -149,63 +150,94 @@ class HuyaVideoIE(InfoExtractor):
|
|||||||
'id': '1002412640',
|
'id': '1002412640',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': '8月3日',
|
'title': '8月3日',
|
||||||
'thumbnail': r're:https?://.*\.jpg',
|
'categories': ['主机游戏'],
|
||||||
'duration': 14,
|
'duration': 14.0,
|
||||||
'uploader': '虎牙-ATS欧卡车队青木',
|
'uploader': '虎牙-ATS欧卡车队青木',
|
||||||
'uploader_id': '1564376151',
|
'uploader_id': '1564376151',
|
||||||
'upload_date': '20240803',
|
'upload_date': '20240803',
|
||||||
'view_count': int,
|
'view_count': int,
|
||||||
'comment_count': int,
|
'comment_count': int,
|
||||||
'like_count': int,
|
'like_count': int,
|
||||||
|
'thumbnail': r're:https?://.+\.jpg',
|
||||||
|
'timestamp': 1722675433,
|
||||||
},
|
},
|
||||||
},
|
}, {
|
||||||
{
|
|
||||||
'url': 'https://www.huya.com/video/play/556054543.html',
|
'url': 'https://www.huya.com/video/play/556054543.html',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '556054543',
|
'id': '556054543',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': '我不挑事 也不怕事',
|
'title': '我不挑事 也不怕事',
|
||||||
'thumbnail': r're:https?://.*\.jpg',
|
'categories': ['英雄联盟'],
|
||||||
'duration': 1864,
|
'description': 'md5:58184869687d18ce62dc7b4b2ad21201',
|
||||||
|
'duration': 1864.0,
|
||||||
'uploader': '卡尔',
|
'uploader': '卡尔',
|
||||||
'uploader_id': '367138632',
|
'uploader_id': '367138632',
|
||||||
'upload_date': '20210811',
|
'upload_date': '20210811',
|
||||||
'view_count': int,
|
'view_count': int,
|
||||||
'comment_count': int,
|
'comment_count': int,
|
||||||
'like_count': int,
|
'like_count': int,
|
||||||
|
'tags': 'count:4',
|
||||||
|
'thumbnail': r're:https?://.+\.jpg',
|
||||||
|
'timestamp': 1628675950,
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
# Only m3u8 available
|
||||||
|
'url': 'https://www.huya.com/video/play/1063345618.html',
|
||||||
|
'info_dict': {
|
||||||
|
'id': '1063345618',
|
||||||
|
'ext': 'mp4',
|
||||||
|
'title': '峡谷第一中!黑铁上钻石顶级教学对抗elo',
|
||||||
|
'categories': ['英雄联盟'],
|
||||||
|
'comment_count': int,
|
||||||
|
'duration': 21603.0,
|
||||||
|
'like_count': int,
|
||||||
|
'thumbnail': r're:https?://.+\.jpg',
|
||||||
|
'timestamp': 1749668803,
|
||||||
|
'upload_date': '20250611',
|
||||||
|
'uploader': '北枫CC',
|
||||||
|
'uploader_id': '2183525275',
|
||||||
|
'view_count': int,
|
||||||
},
|
},
|
||||||
}]
|
}]
|
||||||
|
|
||||||
def _real_extract(self, url: str):
|
def _real_extract(self, url: str):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
video_data = self._download_json(
|
moment = self._download_json(
|
||||||
'https://liveapi.huya.com/moment/getMomentContent', video_id,
|
'https://liveapi.huya.com/moment/getMomentContent',
|
||||||
query={'videoId': video_id})['data']['moment']['videoInfo']
|
video_id, query={'videoId': video_id})['data']['moment']
|
||||||
|
|
||||||
formats = []
|
formats = []
|
||||||
for definition in traverse_obj(video_data, ('definitions', lambda _, v: url_or_none(v['url']))):
|
for definition in traverse_obj(moment, (
|
||||||
formats.append({
|
'videoInfo', 'definitions', lambda _, v: url_or_none(v['m3u8']),
|
||||||
'url': definition['url'],
|
)):
|
||||||
**traverse_obj(definition, {
|
fmts = self._extract_m3u8_formats(definition['m3u8'], video_id, 'mp4', fatal=False)
|
||||||
'format_id': ('defName', {str}),
|
for fmt in fmts:
|
||||||
'width': ('width', {int_or_none}),
|
fmt.update(**traverse_obj(definition, {
|
||||||
'height': ('height', {int_or_none}),
|
|
||||||
'filesize': ('size', {int_or_none}),
|
'filesize': ('size', {int_or_none}),
|
||||||
}),
|
'format_id': ('defName', {str}),
|
||||||
})
|
'height': ('height', {int_or_none}),
|
||||||
|
'quality': ('definition', {int_or_none}),
|
||||||
|
'width': ('width', {int_or_none}),
|
||||||
|
}))
|
||||||
|
formats.extend(fmts)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
**traverse_obj(video_data, {
|
**traverse_obj(moment, {
|
||||||
|
'comment_count': ('commentCount', {int_or_none}),
|
||||||
|
'description': ('content', {clean_html}, filter),
|
||||||
|
'like_count': ('favorCount', {int_or_none}),
|
||||||
|
'timestamp': ('cTime', {int_or_none}),
|
||||||
|
}),
|
||||||
|
**traverse_obj(moment, ('videoInfo', {
|
||||||
'title': ('videoTitle', {str}),
|
'title': ('videoTitle', {str}),
|
||||||
'thumbnail': ('videoCover', {url_or_none}),
|
'categories': ('category', {str}, filter, all, filter),
|
||||||
'duration': ('videoDuration', {parse_duration}),
|
'duration': ('videoDuration', {parse_duration}),
|
||||||
|
'tags': ('tags', ..., {str}, filter, all, filter),
|
||||||
|
'thumbnail': (('videoBigCover', 'videoCover'), {url_or_none}, {update_url(query=None)}, any),
|
||||||
'uploader': ('nickName', {str}),
|
'uploader': ('nickName', {str}),
|
||||||
'uploader_id': ('uid', {str_or_none}),
|
'uploader_id': ('uid', {str_or_none}),
|
||||||
'upload_date': ('videoUploadTime', {unified_strdate}),
|
|
||||||
'view_count': ('videoPlayNum', {int_or_none}),
|
'view_count': ('videoPlayNum', {int_or_none}),
|
||||||
'comment_count': ('videoCommentNum', {int_or_none}),
|
})),
|
||||||
'like_count': ('favorCount', {int_or_none}),
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user