]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/douyutv.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..utils
import (ExtractorError
, unescapeHTML
)
8 from ..compat
import (compat_str
, compat_basestring
)
11 class DouyuTVIE(InfoExtractor
):
12 _VALID_URL
= r
'http://(?:www\.)?douyutv\.com/(?P<id>[A-Za-z0-9]+)'
14 'url': 'http://www.douyutv.com/iseven',
17 'display_id': 'iseven',
19 'title': 're:^清晨醒脑!T-ara根本停不下来! [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
20 'description': 'md5:c93d6692dde6fe33809a46edcbecca44',
21 'thumbnail': 're:^https?://.*\.jpg$',
23 'uploader_id': '431925',
27 'skip_download': True,
30 'url': 'http://www.douyutv.com/85982',
33 'display_id': '85982',
35 'title': 're:^小漠从零单排记!——CSOL2躲猫猫 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
36 'description': 'md5:746a2f7a253966a06755a912f0acc0d2',
37 'thumbnail': 're:^https?://.*\.jpg$',
38 'uploader': 'douyu小漠',
39 'uploader_id': '3769985',
43 'skip_download': True,
47 def _real_extract(self
, url
):
48 video_id
= self
._match
_id
(url
)
50 if video_id
.isdigit():
53 page
= self
._download
_webpage
(url
, video_id
)
54 room_id
= self
._html
_search
_regex
(
55 r
'"room_id"\s*:\s*(\d+),', page
, 'room id')
57 prefix
= 'room/%s?aid=android&client_sys=android&time=%d' % (
58 room_id
, int(time
.time()))
60 auth
= hashlib
.md5((prefix
+ '1231').encode('ascii')).hexdigest()
61 config
= self
._download
_json
(
62 'http://www.douyutv.com/api/v1/%s&auth=%s' % (prefix
, auth
),
67 error_code
= config
.get('error', 0)
68 if error_code
is not 0:
69 error_desc
= 'Server reported error %i' % error_code
70 if isinstance(data
, (compat_str
, compat_basestring
)):
71 error_desc
+= ': ' + data
72 raise ExtractorError(error_desc
, expected
=True)
74 show_status
= data
.get('show_status')
75 # 1 = live, 2 = offline
76 if show_status
== '2':
78 'Live stream is offline', expected
=True)
80 base_url
= data
['rtmp_url']
81 live_path
= data
['rtmp_live']
83 title
= self
._live
_title
(unescapeHTML(data
['room_name']))
84 description
= data
.get('show_details')
85 thumbnail
= data
.get('room_src')
87 uploader
= data
.get('nickname')
88 uploader_id
= data
.get('owner_uid')
90 multi_formats
= data
.get('rtmp_multi_bitrate')
91 if not isinstance(multi_formats
, dict):
93 multi_formats
['live'] = live_path
96 'url': '%s/%s' % (base_url
, format_path
),
97 'format_id': format_id
,
98 'preference': 1 if format_id
== 'live' else 0,
99 } for format_id
, format_path
in multi_formats
.items()]
100 self
._sort
_formats
(formats
)
104 'display_id': video_id
,
106 'description': description
,
107 'thumbnail': thumbnail
,
108 'uploader': uploader
,
109 'uploader_id': uploader_id
,