2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
15 class KuwoIE(InfoExtractor
):
17 _VALID_URL
= r
'http://www\.kuwo\.cn/yinyue/(?P<id>[0-9]+?)/'
19 'url': 'http://www.kuwo.cn/yinyue/635632/',
25 'upload_date': '20080122',
26 'description': 'md5:ed13f58e3c3bf3f7fd9fbc4e5a7aa75c'
29 'url': 'http://www.kuwo.cn/yinyue/6446136/',
35 'upload_date': '20150518',
42 {'format': 'ape', 'ext': 'ape', 'preference': 100}
,
43 {'format': 'mp3-320', 'ext': 'mp3', 'br': '320kmp3', 'abr': 320, 'preference': 80}
,
44 {'format': 'mp3-192', 'ext': 'mp3', 'br': '192kmp3', 'abr': 192, 'preference': 70}
,
45 {'format': 'mp3-128', 'ext': 'mp3', 'br': '128kmp3', 'abr': 128, 'preference': 60}
,
46 {'format': 'wma', 'ext': 'wma', 'preference': 20}
,
47 {'format': 'aac', 'ext': 'aac', 'abr': 48, 'preference': 10}
50 def _get_formats(self
, song_id
):
52 for file_format
in self
._FORMATS
:
53 song_url
= self
._download
_webpage
(
54 "http://antiserver.kuwo.cn/anti.s?format=%s&br=%s&rid=MUSIC_%s&type=convert_url&response=url" %
55 (file_format
['ext'], file_format
.get('br', ''), song_id
),
56 song_id
, note
="Download %s url info" % file_format
["format"],
58 if song_url
.startswith('http://') or song_url
.startswith('https://'):
61 'format_id': file_format
['format'],
62 'format': file_format
['format'],
63 'preference': file_format
['preference'],
64 'abr': file_format
.get('abr'),
66 self
._sort
_formats
(formats
)
69 def _real_extract(self
, url
):
70 song_id
= self
._match
_id
(url
)
71 webpage
= self
._download
_webpage
(
72 url
, song_id
, note
='Download song detail info',
73 errnote
='Unable to get song detail info')
75 song_name
= self
._html
_search
_regex
(
76 r
'<h1 title="(.+?)">', webpage
, 'song name')
77 singer_name
= self
._html
_search
_regex
(
78 r
'<div class="s_img">.+?title="(.+?)".+?</div>', webpage
, 'singer name',
79 flags
=re
.DOTALL
, default
=None)
80 lrc_content
= clean_html(get_element_by_id("lrcContent", webpage
))
81 if lrc_content
== '暂无': # indicates no lyrics
84 formats
= self
._get
_formats
(song_id
)
86 album_id
= self
._html
_search
_regex
(
87 r
'<p class="album" title=".+?">.+?<a href="http://www\.kuwo\.cn/album/([0-9]+)/" ',
88 webpage
, 'album id', default
=None, fatal
=False)
91 if album_id
is not None:
92 album_info_page
= self
._download
_webpage
(
93 "http://www.kuwo.cn/album/%s/" % album_id
, song_id
,
94 note
='Download album detail info',
95 errnote
='Unable to get album detail info')
97 publish_time
= self
._html
_search
_regex
(
98 r
'发行时间:(\d{4}-\d{2}-\d{2})', album_info_page
,
99 'publish time', default
=None)
101 publish_time
= publish_time
.replace('-', '')
106 'creator': singer_name
,
107 'upload_date': publish_time
,
108 'description': lrc_content
,
113 class KuwoAlbumIE(InfoExtractor
):
114 IE_NAME
= 'kuwo:album'
115 _VALID_URL
= r
'http://www\.kuwo\.cn/album/(?P<id>[0-9]+?)/'
117 'url': 'http://www.kuwo.cn/album/502294/',
121 'description': 'md5:6a7235a84cc6400ec3b38a7bdaf1d60c',
126 def _real_extract(self
, url
):
127 album_id
= self
._match
_id
(url
)
129 webpage
= self
._download
_webpage
(
130 url
, album_id
, note
='Download album info',
131 errnote
='Unable to get album info')
133 album_name
= self
._html
_search
_regex
(
134 r
'<div class="comm".+?<h1 title="(.+?)">.+?</h1>', webpage
,
135 'album name', flags
=re
.DOTALL
)
136 album_intro
= clean_html(
137 re
.sub(r
'^.+简介:', '', get_element_by_id("intro", webpage
).strip()))
140 self
.url_result("http://www.kuwo.cn/yinyue/%s/" % song_id
, 'Kuwo', song_id
)
141 for song_id
in re
.findall(
142 r
'<p class="listen"><a href="http://www\.kuwo\.cn/yinyue/([0-9]+)/" target="_blank" title="试听.*?"></a></p>',
145 return self
.playlist_result(entries
, album_id
, album_name
, album_intro
)
148 class KuwoChartIE(InfoExtractor
):
149 IE_NAME
= 'kuwo:chart'
150 _VALID_URL
= r
'http://yinyue\.kuwo\.cn/billboard_(?P<id>.+?).htm'
152 'url': 'http://yinyue.kuwo.cn/billboard_香港中文龙虎榜.htm',
156 'description': 're:[0-9]{4}第[0-9]{2}期',
158 'playlist_mincount': 10,
161 def _real_extract(self
, url
):
162 chart_id
= self
._match
_id
(url
)
163 webpage
= self
._download
_webpage
(
164 url
, chart_id
, note
='Download chart info',
165 errnote
='Unable to get chart info')
167 chart_name
= self
._html
_search
_regex
(
168 r
'<h1 class="unDis">(.+?)</h1>', webpage
, 'chart name')
170 chart_desc
= self
._html
_search
_regex
(
171 r
'<p class="tabDef">([0-9]{4}第[0-9]{2}期)</p>', webpage
, 'chart desc')
174 self
.url_result("http://www.kuwo.cn/yinyue/%s/" % song_id
, 'Kuwo', song_id
)
175 for song_id
in re
.findall(
176 r
'<a href="http://www\.kuwo\.cn/yinyue/([0-9]+)/" .+?>.+?</a>', webpage
)
178 return self
.playlist_result(entries
, chart_id
, chart_name
, chart_desc
)
181 class KuwoSingerIE(InfoExtractor
):
182 IE_NAME
= 'kuwo:singer'
183 _VALID_URL
= r
'http://www\.kuwo\.cn/mingxing/(?P<id>[^/]+)'
185 'url': 'http://www.kuwo.cn/mingxing/bruno+mars/',
188 'title': 'Bruno Mars',
190 'playlist_count': 10,
192 'url': 'http://www.kuwo.cn/mingxing/Ali/music.htm',
197 'playlist_mincount': 95,
200 def _real_extract(self
, url
):
201 singer_id
= self
._match
_id
(url
)
202 webpage
= self
._download
_webpage
(
203 url
, singer_id
, note
='Download singer info',
204 errnote
='Unable to get singer info')
206 singer_name
= self
._html
_search
_regex
(
207 r
'<div class="title clearfix">[\n\s\t]*?<h1>(.+?)<span', webpage
, 'singer name'
211 first_page_only
= False if re
.match(r
'.+/music(?:_[0-9]+)?\.htm', url
) else True
212 for page_num
in itertools
.count(1):
213 webpage
= self
._download
_webpage
(
214 'http://www.kuwo.cn/mingxing/%s/music_%d.htm' % (singer_id
, page_num
),
215 singer_id
, note
='Download song list page #%d' % page_num
,
216 errnote
='Unable to get song list page #%d' % page_num
)
219 self
.url_result("http://www.kuwo.cn/yinyue/%s/" % song_id
, 'Kuwo', song_id
)
220 for song_id
in re
.findall(
221 r
'<p class="m_name"><a href="http://www\.kuwo\.cn/yinyue/([0-9]+)/',
223 ][:10 if first_page_only
else None])
225 if first_page_only
or not re
.search(r
'<a href="[^"]+">下一页</a>', webpage
):
228 return self
.playlist_result(entries
, singer_id
, singer_name
)
231 class KuwoCategoryIE(InfoExtractor
):
232 IE_NAME
= 'kuwo:category'
233 _VALID_URL
= r
'http://yinyue\.kuwo\.cn/yy/cinfo_(?P<id>[0-9]+?).htm'
235 'url': 'http://yinyue.kuwo.cn/yy/cinfo_86375.htm',
239 'description': '这些都是属于八十年代的回忆!',
241 'playlist_count': 30,
244 def _real_extract(self
, url
):
245 category_id
= self
._match
_id
(url
)
246 webpage
= self
._download
_webpage
(
247 url
, category_id
, note
='Download category info',
248 errnote
='Unable to get category info')
250 category_name
= self
._html
_search
_regex
(
251 r
'<h1 title="([^<>]+?)">[^<>]+?</h1>', webpage
, 'category name')
253 category_desc
= re
.sub(
254 r
'^.+简介:', '', get_element_by_id("intro", webpage
).strip())
256 jsonm
= self
._parse
_json
(self
._html
_search
_regex
(
257 r
'var jsonm = (\{.+?\});', webpage
, 'category songs'), category_id
)
261 "http://www.kuwo.cn/yinyue/%s/" % song
['musicrid'],
262 'Kuwo', song
['musicrid'])
263 for song
in jsonm
['musiclist']
265 return self
.playlist_result(entries
, category_id
, category_name
, category_desc
)
268 class KuwoMvIE(KuwoIE
):
270 _VALID_URL
= r
'http://www\.kuwo\.cn/mv/(?P<id>[0-9]+?)/'
272 'url': 'http://www.kuwo.cn/mv/6480076/',
280 _FORMATS
= KuwoIE
._FORMATS
+ [
281 {'format': 'mkv', 'ext': 'mkv', 'preference': 250}
,
282 {'format': 'mp4', 'ext': 'mp4', 'preference': 200}
,
285 def _real_extract(self
, url
):
286 song_id
= self
._match
_id
(url
)
287 webpage
= self
._download
_webpage
(
288 url
, song_id
, note
='Download mv detail info: %s' % song_id
,
289 errnote
='Unable to get mv detail info: %s' % song_id
)
292 r
'<h1 title="(?P<song>.+?)">[^<>]+<span .+?title="(?P<singer>.+?)".+?>[^<>]+</span></h1>',
295 song_name
= mobj
.group('song')
296 singer_name
= mobj
.group('singer')
298 raise ExtractorError("Unable to find song or singer names")
300 formats
= self
._get
_formats
(song_id
)
305 'creator': singer_name
,