]>
jfr.im git - yt-dlp.git/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
):
13 _VALID_URL
= r
'http://(?:www\.)?douyutv\.com/(?P<id>[A-Za-z0-9]+)'
15 'url': 'http://www.douyutv.com/iseven',
18 'display_id': 'iseven',
20 'title': 're:^清晨醒脑!T-ara根本停不下来! [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
21 'description': 'md5:f34981259a03e980a3c6404190a3ed61',
22 'thumbnail': 're:^https?://.*\.jpg$',
24 'uploader_id': '431925',
28 'skip_download': True,
31 'url': 'http://www.douyutv.com/85982',
34 'display_id': '85982',
36 'title': 're:^小漠从零单排记!——CSOL2躲猫猫 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
37 'description': 'md5:746a2f7a253966a06755a912f0acc0d2',
38 'thumbnail': 're:^https?://.*\.jpg$',
39 'uploader': 'douyu小漠',
40 'uploader_id': '3769985',
44 'skip_download': True,
46 'skip': 'Romm not found',
48 'url': 'http://www.douyutv.com/17732',
51 'display_id': '17732',
53 'title': 're:^清晨醒脑!T-ara根本停不下来! [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
54 'description': 'md5:f34981259a03e980a3c6404190a3ed61',
55 'thumbnail': 're:^https?://.*\.jpg$',
57 'uploader_id': '431925',
61 'skip_download': True,
65 def _real_extract(self
, url
):
66 video_id
= self
._match
_id
(url
)
68 if video_id
.isdigit():
71 page
= self
._download
_webpage
(url
, video_id
)
72 room_id
= self
._html
_search
_regex
(
73 r
'"room_id"\s*:\s*(\d+),', page
, 'room id')
75 prefix
= 'room/%s?aid=android&client_sys=android&time=%d' % (
76 room_id
, int(time
.time()))
78 auth
= hashlib
.md5((prefix
+ '1231').encode('ascii')).hexdigest()
79 config
= self
._download
_json
(
80 'http://www.douyutv.com/api/v1/%s&auth=%s' % (prefix
, auth
),
85 error_code
= config
.get('error', 0)
86 if error_code
is not 0:
87 error_desc
= 'Server reported error %i' % error_code
88 if isinstance(data
, (compat_str
, compat_basestring
)):
89 error_desc
+= ': ' + data
90 raise ExtractorError(error_desc
, expected
=True)
92 show_status
= data
.get('show_status')
93 # 1 = live, 2 = offline
94 if show_status
== '2':
96 'Live stream is offline', expected
=True)
98 base_url
= data
['rtmp_url']
99 live_path
= data
['rtmp_live']
101 title
= self
._live
_title
(unescapeHTML(data
['room_name']))
102 description
= data
.get('show_details')
103 thumbnail
= data
.get('room_src')
105 uploader
= data
.get('nickname')
106 uploader_id
= data
.get('owner_uid')
108 multi_formats
= data
.get('rtmp_multi_bitrate')
109 if not isinstance(multi_formats
, dict):
111 multi_formats
['live'] = live_path
114 'url': '%s/%s' % (base_url
, format_path
),
115 'format_id': format_id
,
116 'preference': 1 if format_id
== 'live' else 0,
117 } for format_id
, format_path
in multi_formats
.items()]
118 self
._sort
_formats
(formats
)
122 'display_id': video_id
,
124 'description': description
,
125 'thumbnail': thumbnail
,
126 'uploader': uploader
,
127 'uploader_id': uploader_id
,