mirror of
https://github.com/yt-dlp/yt-dlp
synced 2024-11-16 07:48:01 +01:00
[ie/huya:video] Add extractor (#10686)
Closes #10679 Authored by: hugepower
This commit is contained in:
parent
d02df303d8
commit
25c1cdaa26
2 changed files with 83 additions and 2 deletions
|
@ -823,7 +823,10 @@ from .hungama import (
|
||||||
HungamaIE,
|
HungamaIE,
|
||||||
HungamaSongIE,
|
HungamaSongIE,
|
||||||
)
|
)
|
||||||
from .huya import HuyaLiveIE
|
from .huya import (
|
||||||
|
HuyaLiveIE,
|
||||||
|
HuyaVideoIE,
|
||||||
|
)
|
||||||
from .hypem import HypemIE
|
from .hypem import HypemIE
|
||||||
from .hypergryph import MonsterSirenHypergryphMusicIE
|
from .hypergryph import MonsterSirenHypergryphMusicIE
|
||||||
from .hytale import HytaleIE
|
from .hytale import HytaleIE
|
||||||
|
|
|
@ -8,15 +8,19 @@ from .common import InfoExtractor
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
|
parse_duration,
|
||||||
str_or_none,
|
str_or_none,
|
||||||
try_get,
|
try_get,
|
||||||
unescapeHTML,
|
unescapeHTML,
|
||||||
|
unified_strdate,
|
||||||
update_url_query,
|
update_url_query,
|
||||||
|
url_or_none,
|
||||||
)
|
)
|
||||||
|
from ..utils.traversal import traverse_obj
|
||||||
|
|
||||||
|
|
||||||
class HuyaLiveIE(InfoExtractor):
|
class HuyaLiveIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.|m\.)?huya\.com/(?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 = 'huya.com'
|
||||||
TESTS = [{
|
TESTS = [{
|
||||||
|
@ -24,6 +28,7 @@ class HuyaLiveIE(InfoExtractor):
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '572329',
|
'id': '572329',
|
||||||
'title': str,
|
'title': str,
|
||||||
|
'ext': 'flv',
|
||||||
'description': str,
|
'description': str,
|
||||||
'is_live': True,
|
'is_live': True,
|
||||||
'view_count': int,
|
'view_count': int,
|
||||||
|
@ -131,3 +136,76 @@ class HuyaLiveIE(InfoExtractor):
|
||||||
fm = base64.b64decode(params['fm']).decode().split('_', 1)[0]
|
fm = base64.b64decode(params['fm']).decode().split('_', 1)[0]
|
||||||
ss = hashlib.md5('|'.join([params['seqid'], params['ctype'], params['t']]))
|
ss = hashlib.md5('|'.join([params['seqid'], params['ctype'], params['t']]))
|
||||||
return fm, ss
|
return fm, ss
|
||||||
|
|
||||||
|
|
||||||
|
class HuyaVideoIE(InfoExtractor):
|
||||||
|
_VALID_URL = r'https?://(?:www\.)?huya\.com/video/play/(?P<id>\d+)\.html'
|
||||||
|
IE_NAME = 'huya:video'
|
||||||
|
IE_DESC = '虎牙视频'
|
||||||
|
|
||||||
|
_TESTS = [{
|
||||||
|
'url': 'https://www.huya.com/video/play/1002412640.html',
|
||||||
|
'info_dict': {
|
||||||
|
'id': '1002412640',
|
||||||
|
'ext': 'mp4',
|
||||||
|
'title': '8月3日',
|
||||||
|
'thumbnail': r're:https?://.*\.jpg',
|
||||||
|
'duration': 14,
|
||||||
|
'uploader': '虎牙-ATS欧卡车队青木',
|
||||||
|
'uploader_id': '1564376151',
|
||||||
|
'upload_date': '20240803',
|
||||||
|
'view_count': int,
|
||||||
|
'comment_count': int,
|
||||||
|
'like_count': int,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'url': 'https://www.huya.com/video/play/556054543.html',
|
||||||
|
'info_dict': {
|
||||||
|
'id': '556054543',
|
||||||
|
'ext': 'mp4',
|
||||||
|
'title': '我不挑事 也不怕事',
|
||||||
|
'thumbnail': r're:https?://.*\.jpg',
|
||||||
|
'duration': 1864,
|
||||||
|
'uploader': '卡尔',
|
||||||
|
'uploader_id': '367138632',
|
||||||
|
'upload_date': '20210811',
|
||||||
|
'view_count': int,
|
||||||
|
'comment_count': int,
|
||||||
|
'like_count': int,
|
||||||
|
},
|
||||||
|
}]
|
||||||
|
|
||||||
|
def _real_extract(self, url: str):
|
||||||
|
video_id = self._match_id(url)
|
||||||
|
video_data = self._download_json(
|
||||||
|
'https://liveapi.huya.com/moment/getMomentContent', video_id,
|
||||||
|
query={'videoId': video_id})['data']['moment']['videoInfo']
|
||||||
|
|
||||||
|
formats = []
|
||||||
|
for definition in traverse_obj(video_data, ('definitions', lambda _, v: url_or_none(v['url']))):
|
||||||
|
formats.append({
|
||||||
|
'url': definition['url'],
|
||||||
|
**traverse_obj(definition, {
|
||||||
|
'format_id': ('defName', {str}),
|
||||||
|
'width': ('width', {int_or_none}),
|
||||||
|
'height': ('height', {int_or_none}),
|
||||||
|
'filesize': ('size', {int_or_none}),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
'id': video_id,
|
||||||
|
'formats': formats,
|
||||||
|
**traverse_obj(video_data, {
|
||||||
|
'title': ('videoTitle', {str}),
|
||||||
|
'thumbnail': ('videoCover', {url_or_none}),
|
||||||
|
'duration': ('videoDuration', {parse_duration}),
|
||||||
|
'uploader': ('nickName', {str}),
|
||||||
|
'uploader_id': ('uid', {str_or_none}),
|
||||||
|
'upload_date': ('videoUploadTime', {unified_strdate}),
|
||||||
|
'view_count': ('videoPlayNum', {int_or_none}),
|
||||||
|
'comment_count': ('videoCommentNum', {int_or_none}),
|
||||||
|
'like_count': ('favorCount', {int_or_none}),
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue