2 from __future__ import unicode_literals
7 from .common import InfoExtractor
16 class KuwoBaseIE(InfoExtractor):
18 {'format': 'ape', 'ext': 'ape', 'preference': 100},
19 {'format': 'mp3-320', 'ext': 'mp3', 'br': '320kmp3', 'abr': 320, 'preference': 80},
20 {'format': 'mp3-192', 'ext': 'mp3', 'br': '192kmp3', 'abr': 192, 'preference': 70},
21 {'format': 'mp3-128', 'ext': 'mp3', 'br': '128kmp3', 'abr': 128, 'preference': 60},
22 {'format': 'wma', 'ext': 'wma', 'preference': 20},
23 {'format': 'aac', 'ext': 'aac', 'abr': 48, 'preference': 10}
26 def _get_formats(self, song_id):
28 for file_format in self._FORMATS:
29 song_url = self._download_webpage(
30 'http://antiserver.kuwo.cn/anti.s?format=%s&br=%s&rid=MUSIC_%s&type=convert_url&response=url' %
31 (file_format['ext'], file_format.get('br', ''), song_id),
32 song_id, note='Download %s url info' % file_format['format'],
34 if song_url.startswith('http://') or song_url.startswith('https://'):
37 'format_id': file_format['format'],
38 'format': file_format['format'],
39 'preference': file_format['preference'],
40 'abr': file_format.get('abr'),
42 self._sort_formats(formats)
46 class KuwoIE(KuwoBaseIE):
49 _VALID_URL = r'http://www\.kuwo\.cn/yinyue/(?P<id>\d+?)/'
51 'url': 'http://www.kuwo.cn/yinyue/635632/',
57 'upload_date': '20080122',
58 'description': 'md5:ed13f58e3c3bf3f7fd9fbc4e5a7aa75c'
60 'skip': 'this song has been offline because of copyright issues',
62 'url': 'http://www.kuwo.cn/yinyue/6446136/',
68 'upload_date': '20150518',
75 def _real_extract(self, url):
76 song_id = self._match_id(url)
77 webpage = self._download_webpage(
78 url, song_id, note='Download song detail info',
79 errnote='Unable to get song detail info')
80 if '对不起,该歌曲由于版权问题已被下线,将返回网站首页' in webpage:
81 raise ExtractorError('this song has been offline because of copyright issues', expected=True)
83 song_name = self._html_search_regex(
84 r'(?s)class="(?:[^"\s]+\s+)*title(?:\s+[^"\s]+)*".*?<h1[^>]+title="([^"]+)"', webpage, 'song name')
85 singer_name = self._html_search_regex(
86 r'<div[^>]+class="s_img">\s*<a[^>]+title="([^>]+)"',
87 webpage, 'singer name', fatal=False)
88 lrc_content = clean_html(get_element_by_id('lrcContent', webpage))
89 if lrc_content == '暂无': # indicates no lyrics
92 formats = self._get_formats(song_id)
94 album_id = self._html_search_regex(
95 r'<p[^>]+class="album"[^<]+<a[^>]+href="http://www\.kuwo\.cn/album/(\d+)/"',
96 webpage, 'album id', fatal=False)
99 if album_id is not None:
100 album_info_page = self._download_webpage(
101 'http://www.kuwo.cn/album/%s/' % album_id, song_id,
102 note='Download album detail info',
103 errnote='Unable to get album detail info')
105 publish_time = self._html_search_regex(
106 r'发行时间:(\d{4}-\d{2}-\d{2})', album_info_page,
107 'publish time', fatal=False)
109 publish_time = publish_time.replace('-', '')
114 'creator': singer_name,
115 'upload_date': publish_time,
116 'description': lrc_content,
121 class KuwoAlbumIE(InfoExtractor):
122 IE_NAME = 'kuwo:album'
123 IE_DESC = '酷我音乐 - 专辑'
124 _VALID_URL = r'http://www\.kuwo\.cn/album/(?P<id>\d+?)/'
126 'url': 'http://www.kuwo.cn/album/502294/',
130 'description': 'md5:6a7235a84cc6400ec3b38a7bdaf1d60c',
135 def _real_extract(self, url):
136 album_id = self._match_id(url)
138 webpage = self._download_webpage(
139 url, album_id, note='Download album info',
140 errnote='Unable to get album info')
142 album_name = self._html_search_regex(
143 r'<div[^>]+class="comm"[^<]+<h1[^>]+title="([^"]+)"', webpage,
145 album_intro = remove_start(
146 clean_html(get_element_by_id('intro', webpage)),
147 '%s简介:' % album_name)
150 self.url_result(song_url, 'Kuwo') for song_url in re.findall(
151 r'<p[^>]+class="listen"><a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+/)"',
154 return self.playlist_result(entries, album_id, album_name, album_intro)
157 class KuwoChartIE(InfoExtractor):
158 IE_NAME = 'kuwo:chart'
159 IE_DESC = '酷我音乐 - 排行榜'
160 _VALID_URL = r'http://yinyue\.kuwo\.cn/billboard_(?P<id>[^.]+).htm'
162 'url': 'http://yinyue.kuwo.cn/billboard_香港中文龙虎榜.htm',
166 'description': 're:\d{4}第\d{2}期',
168 'playlist_mincount': 10,
171 def _real_extract(self, url):
172 chart_id = self._match_id(url)
173 webpage = self._download_webpage(
174 url, chart_id, note='Download chart info',
175 errnote='Unable to get chart info')
177 chart_name = self._html_search_regex(
178 r'<h1[^>]+class="unDis">([^<]+)</h1>', webpage, 'chart name')
180 chart_desc = self._html_search_regex(
181 r'<p[^>]+class="tabDef">(\d{4}第\d{2}期)</p>', webpage, 'chart desc')
184 self.url_result(song_url, 'Kuwo') for song_url in re.findall(
185 r'<a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+)/"', webpage)
187 return self.playlist_result(entries, chart_id, chart_name, chart_desc)
190 class KuwoSingerIE(InfoExtractor):
191 IE_NAME = 'kuwo:singer'
192 IE_DESC = '酷我音乐 - 歌手'
193 _VALID_URL = r'http://www\.kuwo\.cn/mingxing/(?P<id>[^/]+)'
195 'url': 'http://www.kuwo.cn/mingxing/bruno+mars/',
198 'title': 'Bruno Mars',
200 'playlist_count': 10,
202 'url': 'http://www.kuwo.cn/mingxing/Ali/music.htm',
207 'playlist_mincount': 95,
208 'skip': 'Regularly stalls travis build', # See https://travis-ci.org/rg3/youtube-dl/jobs/78878540
211 def _real_extract(self, url):
212 singer_id = self._match_id(url)
213 webpage = self._download_webpage(
214 url, singer_id, note='Download singer info',
215 errnote='Unable to get singer info')
217 singer_name = self._html_search_regex(
218 r'<div class="title clearfix">\s*<h1>([^<]+)<span', webpage, 'singer name'
222 first_page_only = False if re.search(r'/music(?:_\d+)?\.htm', url) else True
223 for page_num in itertools.count(1):
224 webpage = self._download_webpage(
225 'http://www.kuwo.cn/mingxing/%s/music_%d.htm' % (singer_id, page_num),
226 singer_id, note='Download song list page #%d' % page_num,
227 errnote='Unable to get song list page #%d' % page_num)
230 self.url_result(song_url, 'Kuwo') for song_url in re.findall(
231 r'<p[^>]+class="m_name"><a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+)/',
233 ][:10 if first_page_only else None])
235 if first_page_only or not re.search(r'<a[^>]+href="[^"]+">下一页</a>', webpage):
238 return self.playlist_result(entries, singer_id, singer_name)
241 class KuwoCategoryIE(InfoExtractor):
242 IE_NAME = 'kuwo:category'
243 IE_DESC = '酷我音乐 - 分类'
244 _VALID_URL = r'http://yinyue\.kuwo\.cn/yy/cinfo_(?P<id>\d+?).htm'
246 'url': 'http://yinyue.kuwo.cn/yy/cinfo_86375.htm',
250 'description': '这些都是属于八十年代的回忆!',
252 'playlist_count': 30,
255 def _real_extract(self, url):
256 category_id = self._match_id(url)
257 webpage = self._download_webpage(
258 url, category_id, note='Download category info',
259 errnote='Unable to get category info')
261 category_name = self._html_search_regex(
262 r'<h1[^>]+title="([^<>]+?)">[^<>]+?</h1>', webpage, 'category name')
264 category_desc = remove_start(
265 get_element_by_id('intro', webpage).strip(),
266 '%s简介:' % category_name)
268 jsonm = self._parse_json(self._html_search_regex(
269 r'var\s+jsonm\s*=\s*([^;]+);', webpage, 'category songs'), category_id)
272 self.url_result('http://www.kuwo.cn/yinyue/%s/' % song['musicrid'], 'Kuwo')
273 for song in jsonm['musiclist']
275 return self.playlist_result(entries, category_id, category_name, category_desc)
278 class KuwoMvIE(KuwoBaseIE):
280 IE_DESC = '酷我音乐 - MV'
281 _VALID_URL = r'http://www\.kuwo\.cn/mv/(?P<id>\d+?)/'
283 'url': 'http://www.kuwo.cn/mv/6480076/',
291 _FORMATS = KuwoBaseIE._FORMATS + [
292 {'format': 'mkv', 'ext': 'mkv', 'preference': 250},
293 {'format': 'mp4', 'ext': 'mp4', 'preference': 200},
296 def _real_extract(self, url):
297 song_id = self._match_id(url)
298 webpage = self._download_webpage(
299 url, song_id, note='Download mv detail info: %s' % song_id,
300 errnote='Unable to get mv detail info: %s' % song_id)
303 r'<h1[^>]+title="(?P<song>[^"]+)">[^<]+<span[^>]+title="(?P<singer>[^"]+)"',
306 song_name = mobj.group('song')
307 singer_name = mobj.group('singer')
309 raise ExtractorError('Unable to find song or singer names')
311 formats = self._get_formats(song_id)
316 'creator': singer_name,