]>
Commit | Line | Data |
---|---|---|
a172d962 | 1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
5 | ||
6 | from ..utils import ( | |
7 | ExtractorError, | |
8 | ) | |
9 | ||
10 | class DouyutvIE(InfoExtractor): | |
11 | _VALID_URL = r'http://(?:www\.)?douyutv\.com/(?P<id>[A-Za-z0-9]+)' | |
12 | ||
13 | ''' | |
14 | show_status: 1 直播中 ,2 没有直播 | |
15 | ''' | |
16 | ||
17 | _TEST = { | |
18 | 'url': 'http://www.douyutv.com/iseven', | |
19 | 'info_dict': { | |
20 | 'id': 'iseven', | |
21 | 'title': '清晨醒脑!T-ara根本停不下来!', | |
22 | 'ext': 'flv', | |
23 | 'thumbnail': 're:^https?://.*\.jpg$', | |
24 | 'is_live': True, | |
25 | } | |
26 | } | |
27 | ||
28 | def _real_extract(self, url): | |
29 | video_id = self._match_id(url) | |
30 | info_url = 'http://www.douyutv.com/api/client/room/' + video_id | |
31 | ||
32 | config = self._download_json(info_url, video_id) | |
33 | ||
34 | error_code = config.get('error') | |
35 | show_status = config['data'].get('show_status') | |
36 | if error_code is not 0: | |
37 | raise ExtractorError('Server reported error %i' % error_code, | |
38 | expected=True) | |
39 | ||
40 | if show_status == '2': | |
41 | raise ExtractorError('The live show has not yet started', | |
42 | expected=True) | |
43 | ||
44 | title = config['data'].get('room_name') | |
45 | rtmp_url = config['data'].get('rtmp_url') | |
46 | rtmp_live = config['data'].get('rtmp_live') | |
47 | thumbnail = config['data'].get('room_src') | |
48 | ||
49 | url = rtmp_url+'/'+rtmp_live | |
50 | ||
51 | return { | |
52 | 'id': video_id, | |
53 | 'title': title, | |
54 | 'ext':'flv', | |
55 | 'url': url, | |
56 | 'thumbnail': thumbnail, | |
57 | 'is_live': True, | |
58 | # TODO more properties (see youtube_dl/extractor/common.py) | |
59 | } |