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,
193 def _real_extract(self
, url
):
194 singer_id
= self
._match
_id
(url
)
195 webpage
= self
._download
_webpage
(
196 url
, singer_id
, note
='Download singer info',
197 errnote
='Unable to get singer info')
199 singer_name
= self
._html
_search
_regex
(
200 r
'姓名:<span>(.+?)</span>', webpage
, 'singer name')
203 self
.url_result("http://www.kuwo.cn/yinyue/%s/" % song_id
, 'Kuwo', song_id
)
204 for song_id
in re
.findall(
205 r
'<a href="http://www\.kuwo\.cn/yinyue/([0-9]+)/" .+?>.+?</a>',
206 webpage
, flags
=re
.DOTALL
)
208 return self
.playlist_result(entries
, singer_id
, singer_name
)
211 class KuwoSingerMusicIE(InfoExtractor
):
212 IE_NAME
= 'kuwo:singermusic'
213 _VALID_URL
= r
'http://www\.kuwo\.cn/mingxing/(?P<id>[^/]+?)/music(_[0-9]+)?.htm'
215 'url': 'http://www.kuwo.cn/mingxing/Ali/music.htm',
220 'playlist_mincount': 95,
223 def _real_extract(self
, url
):
224 singer_id
= self
._match
_id
(url
)
228 for page_num
in itertools
.count(1):
229 webpage
= self
._download
_webpage
(
230 'http://www.kuwo.cn/mingxing/%s/music_%d.htm' % (singer_id
, page_num
),
231 singer_id
, note
='Download song list page #%d' % page_num
,
232 errnote
='Unable to get song list page #%d' % page_num
)
234 if list_name
is None:
235 list_name
= self
._html
_search
_regex
(
236 r
'<h1>([^<>]+)<span>', webpage
, 'list name')
239 self
.url_result("http://www.kuwo.cn/yinyue/%s/" % song_id
, 'Kuwo', song_id
)
240 for song_id
in re
.findall(
241 r
'<p class="m_name"><a href="http://www\.kuwo\.cn/yinyue/([0-9]+)/',
244 if not re
.search(r
'<a href="[^"]+">下一页</a>', webpage
):
247 return self
.playlist_result(entries
, singer_id
, list_name
)
250 class KuwoCategoryIE(InfoExtractor
):
251 IE_NAME
= 'kuwo:category'
252 _VALID_URL
= r
'http://yinyue\.kuwo\.cn/yy/cinfo_(?P<id>[0-9]+?).htm'
254 'url': 'http://yinyue.kuwo.cn/yy/cinfo_86375.htm',
258 'description': '这些都是属于八十年代的回忆!',
260 'playlist_count': 30,
263 def _real_extract(self
, url
):
264 category_id
= self
._match
_id
(url
)
265 webpage
= self
._download
_webpage
(
266 url
, category_id
, note
='Download category info',
267 errnote
='Unable to get category info')
269 category_name
= self
._html
_search
_regex
(
270 r
'<h1 title="([^<>]+?)">[^<>]+?</h1>', webpage
, 'category name')
272 category_desc
= re
.sub(
273 r
'^.+简介:', '', get_element_by_id("intro", webpage
).strip())
275 jsonm
= self
._parse
_json
(self
._html
_search
_regex
(
276 r
'var jsonm = (\{.+?\});', webpage
, 'category songs'), category_id
)
280 "http://www.kuwo.cn/yinyue/%s/" % song
['musicrid'],
281 'Kuwo', song
['musicrid'])
282 for song
in jsonm
['musiclist']
284 return self
.playlist_result(entries
, category_id
, category_name
, category_desc
)
287 class KuwoMvIE(KuwoIE
):
289 _VALID_URL
= r
'http://www\.kuwo\.cn/mv/(?P<id>[0-9]+?)/'
291 'url': 'http://www.kuwo.cn/mv/6480076/',
299 _FORMATS
= KuwoIE
._FORMATS
+ [
300 {'format': 'mkv', 'ext': 'mkv', 'preference': 250}
,
301 {'format': 'mp4', 'ext': 'mp4', 'preference': 200}
,
304 def _real_extract(self
, url
):
305 song_id
= self
._match
_id
(url
)
306 webpage
= self
._download
_webpage
(
307 url
, song_id
, note
='Download mv detail info: %s' % song_id
,
308 errnote
='Unable to get mv detail info: %s' % song_id
)
311 r
'<h1 title="(?P<song>.+?)">[^<>]+<span .+?title="(?P<singer>.+?)".+?>[^<>]+</span></h1>',
314 song_name
= mobj
.group('song')
315 singer_name
= mobj
.group('singer')
317 raise ExtractorError("Unable to find song or singer names")
319 formats
= self
._get
_formats
(song_id
)
324 'creator': singer_name
,