From 215f137eddb0cb4bcc7c938381ed45f52e2efd3c Mon Sep 17 00:00:00 2001 From: long2ice Date: Fri, 28 Dec 2018 23:32:11 +0800 Subject: [PATCH] [huya] Add new extractor --- bin/youtube-dl | 6 --- youtube_dl/extractor/extractors.py | 3 +- youtube_dl/extractor/huya.py | 61 ++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 7 deletions(-) delete mode 100755 bin/youtube-dl create mode 100644 youtube_dl/extractor/huya.py diff --git a/bin/youtube-dl b/bin/youtube-dl deleted file mode 100755 index fc3cc8ad8..000000000 --- a/bin/youtube-dl +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env python - -import youtube_dl - -if __name__ == '__main__': - youtube_dl.main() diff --git a/youtube_dl/extractor/extractors.py b/youtube_dl/extractor/extractors.py index d72f52e36..8fa9c5391 100644 --- a/youtube_dl/extractor/extractors.py +++ b/youtube_dl/extractor/extractors.py @@ -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 diff --git a/youtube_dl/extractor/huya.py b/youtube_dl/extractor/huya.py new file mode 100644 index 000000000..3f4e35b17 --- /dev/null +++ b/youtube_dl/extractor/huya.py @@ -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\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'(.+?)', 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