From a172d96292abda037b23b1f2b14dd2c6e65b56bb Mon Sep 17 00:00:00 2001 From: bonfy Date: Sat, 7 Mar 2015 14:05:56 +0800 Subject: [PATCH] [douyutv] Add new extractor --- youtube_dl/extractor/__init__.py | 1 + youtube_dl/extractor/douyutv.py | 59 ++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 youtube_dl/extractor/douyutv.py diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index ffcc7d9ab..7d0798176 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -106,6 +106,7 @@ from .dctp import DctpTvIE from .deezer import DeezerPlaylistIE from .dfb import DFBIE from .dotsub import DotsubIE +from .douyutv import DouyutvIE from .dreisat import DreiSatIE from .drbonanza import DRBonanzaIE from .drtuber import DrTuberIE diff --git a/youtube_dl/extractor/douyutv.py b/youtube_dl/extractor/douyutv.py new file mode 100644 index 000000000..e9b92eb3b --- /dev/null +++ b/youtube_dl/extractor/douyutv.py @@ -0,0 +1,59 @@ +# coding: utf-8 +from __future__ import unicode_literals + +from .common import InfoExtractor + +from ..utils import ( + ExtractorError, +) + +class DouyutvIE(InfoExtractor): + _VALID_URL = r'http://(?:www\.)?douyutv\.com/(?P[A-Za-z0-9]+)' + + ''' + show_status: 1 直播中 ,2 没有直播 + ''' + + _TEST = { + 'url': 'http://www.douyutv.com/iseven', + 'info_dict': { + 'id': 'iseven', + 'title': '清晨醒脑!T-ara根本停不下来!', + 'ext': 'flv', + 'thumbnail': 're:^https?://.*\.jpg$', + 'is_live': True, + } + } + + def _real_extract(self, url): + video_id = self._match_id(url) + info_url = 'http://www.douyutv.com/api/client/room/' + video_id + + config = self._download_json(info_url, video_id) + + error_code = config.get('error') + show_status = config['data'].get('show_status') + if error_code is not 0: + raise ExtractorError('Server reported error %i' % error_code, + expected=True) + + if show_status == '2': + raise ExtractorError('The live show has not yet started', + expected=True) + + title = config['data'].get('room_name') + rtmp_url = config['data'].get('rtmp_url') + rtmp_live = config['data'].get('rtmp_live') + thumbnail = config['data'].get('room_src') + + url = rtmp_url+'/'+rtmp_live + + return { + 'id': video_id, + 'title': title, + 'ext':'flv', + 'url': url, + 'thumbnail': thumbnail, + 'is_live': True, + # TODO more properties (see youtube_dl/extractor/common.py) + } \ No newline at end of file -- 2.39.5