mirror of
https://github.com/l1ving/youtube-dl
synced 2020-11-18 19:53:54 -08:00
[huya] Add new extractor
This commit is contained in:
parent
140a13f5de
commit
215f137edd
@ -1,6 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import youtube_dl
|
||||
|
||||
if __name__ == '__main__':
|
||||
youtube_dl.main()
|
@ -1386,7 +1386,7 @@ from .webofstories import (
|
||||
WebOfStoriesPlaylistIE,
|
||||
)
|
||||
from .weibo import (
|
||||
WeiboIE,
|
||||
WeiboIE,
|
||||
WeiboMobileIE
|
||||
)
|
||||
from .weiqitv import WeiqiTVIE
|
||||
@ -1495,3 +1495,4 @@ from .zattoo import (
|
||||
from .zdf import ZDFIE, ZDFChannelIE
|
||||
from .zingmp3 import ZingMp3IE
|
||||
from .zype import ZypeIE
|
||||
from .huya import HuyaIE
|
||||
|
61
youtube_dl/extractor/huya.py
Normal file
61
youtube_dl/extractor/huya.py
Normal file
@ -0,0 +1,61 @@
|
||||
# coding: utf-8
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import json
|
||||
import re
|
||||
|
||||
from youtube_dl.utils import ExtractorError
|
||||
from .common import InfoExtractor
|
||||
|
||||
|
||||
class HuyaIE(InfoExtractor):
|
||||
_VALID_URL = r'https?://www\.huya\.com/(?P<id>\w+)'
|
||||
_TEST = {
|
||||
'url': 'https://www.huya.com/100270',
|
||||
'md5': 'e2434de1928900a03bc2bd7f819c0df1',
|
||||
'info_dict': {
|
||||
'id': '100270',
|
||||
'ext': 'flv',
|
||||
'title': '瓦莉拉炉石传说直播_瓦莉拉视频直播 - 虎牙直播',
|
||||
'description': '虎牙瓦莉拉炉石传说直播,瓦莉拉与您分享炉石传说游戏乐趣。',
|
||||
'uploader': '瓦莉拉',
|
||||
'thumbnail': r're:^https?://.*\.jpg$',
|
||||
}
|
||||
}
|
||||
|
||||
def _real_extract(self, url):
|
||||
video_id = self._match_id(url)
|
||||
webpage = self._download_webpage(url, video_id)
|
||||
title = self._html_search_regex(r'<title>(.+?)</title>', webpage, 'title')
|
||||
info = self._get_info(webpage)
|
||||
ret = {
|
||||
'id': video_id,
|
||||
'title': title,
|
||||
'description': self._html_search_meta('description', webpage),
|
||||
'uploader': self._html_search_regex(r'class="host-name" title="(.+?)">', webpage, 'uploader'),
|
||||
'url': info[0],
|
||||
'thumbnail': info[1]
|
||||
}
|
||||
return ret
|
||||
|
||||
def _get_info(self, webpage):
|
||||
|
||||
try:
|
||||
p = re.compile(r'var hyPlayerConfig = (.*?);', flags=re.S | re.M)
|
||||
s = re.search(p, webpage)
|
||||
s = json.loads(s.group(1))
|
||||
if not s.get('stream'):
|
||||
raise ExtractorError('主播已下线!')
|
||||
except AttributeError:
|
||||
raise ExtractorError('May wrong URL, pls check ...')
|
||||
|
||||
s_info = s['stream']['data'][0]['gameStreamInfoList']
|
||||
screen_shot = s['stream']['data'][0]['gameLiveInfo']['screenshot']
|
||||
ret = []
|
||||
for j in s_info:
|
||||
s_flv_url = j.get('sFlvUrl')
|
||||
s_stream_name = j.get('sStreamName')
|
||||
s_flv_anti_code = j.get('sFlvAntiCode')
|
||||
ret_url = '{}/{}.flv?{}&ratio=5000'.format(s_flv_url, s_stream_name, s_flv_anti_code)
|
||||
ret.append(ret_url)
|
||||
return ret[0], screen_shot
|
Loading…
x
Reference in New Issue
Block a user