2 from __future__ import unicode_literals
6 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, tolerate_ip_deny=False):
28 for file_format in self._FORMATS:
30 cn_verification_proxy = self._downloader.params.get('cn_verification_proxy')
31 if cn_verification_proxy:
32 headers['Ytdl-request-proxy'] = cn_verification_proxy
35 'format': file_format['ext'],
36 'br': file_format.get('br', ''),
37 'rid': 'MUSIC_%s' % song_id,
38 'type': 'convert_url',
42 song_url = self._download_webpage(
43 'http://antiserver.kuwo.cn/anti.s',
44 song_id, note='Download %s url info' % file_format['format'],
45 query=query, headers=headers,
48 if song_url == 'IPDeny' and not tolerate_ip_deny:
49 raise ExtractorError('This song is blocked in this region', expected=True)
51 if song_url.startswith('http://') or song_url.startswith('https://'):
54 'format_id': file_format['format'],
55 'format': file_format['format'],
56 'preference': file_format['preference'],
57 'abr': file_format.get('abr'),
63 class KuwoIE(KuwoBaseIE):
66 _VALID_URL = r'https?://www\.kuwo\.cn/yinyue/(?P<id>\d+)'
68 'url': 'http://www.kuwo.cn/yinyue/635632/',
74 'upload_date': '20080122',
75 'description': 'md5:ed13f58e3c3bf3f7fd9fbc4e5a7aa75c'
77 'skip': 'this song has been offline because of copyright issues',
79 'url': 'http://www.kuwo.cn/yinyue/6446136/',
84 'description': 'md5:5d0e947b242c35dc0eb1d2fce9fbf02c',
86 'upload_date': '20150518',
92 'url': 'http://www.kuwo.cn/yinyue/3197154?catalog=yueku2016',
93 'only_matching': True,
96 def _real_extract(self, url):
97 song_id = self._match_id(url)
98 webpage = self._download_webpage(
99 url, song_id, note='Download song detail info',
100 errnote='Unable to get song detail info')
101 if '对不起,该歌曲由于版权问题已被下线,将返回网站首页' in webpage:
102 raise ExtractorError('this song has been offline because of copyright issues', expected=True)
104 song_name = self._html_search_regex(
105 r'<p[^>]+id="lrcName">([^<]+)</p>', webpage, 'song name')
106 singer_name = remove_start(self._html_search_regex(
107 r'<a[^>]+href="http://www\.kuwo\.cn/artist/content\?name=([^"]+)">',
108 webpage, 'singer name', fatal=False), '歌手')
109 lrc_content = clean_html(get_element_by_id('lrcContent', webpage))
110 if lrc_content == '暂无': # indicates no lyrics
113 formats = self._get_formats(song_id)
114 self._sort_formats(formats)
116 album_id = self._html_search_regex(
117 r'<a[^>]+href="http://www\.kuwo\.cn/album/(\d+)/"',
118 webpage, 'album id', fatal=False)
121 if album_id is not None:
122 album_info_page = self._download_webpage(
123 'http://www.kuwo.cn/album/%s/' % album_id, song_id,
124 note='Download album detail info',
125 errnote='Unable to get album detail info')
127 publish_time = self._html_search_regex(
128 r'发行时间:(\d{4}-\d{2}-\d{2})', album_info_page,
129 'publish time', fatal=False)
131 publish_time = publish_time.replace('-', '')
136 'creator': singer_name,
137 'upload_date': publish_time,
138 'description': lrc_content,
143 class KuwoAlbumIE(InfoExtractor):
144 IE_NAME = 'kuwo:album'
145 IE_DESC = '酷我音乐 - 专辑'
146 _VALID_URL = r'https?://www\.kuwo\.cn/album/(?P<id>\d+?)/'
148 'url': 'http://www.kuwo.cn/album/502294/',
152 'description': 'md5:6a7235a84cc6400ec3b38a7bdaf1d60c',
157 def _real_extract(self, url):
158 album_id = self._match_id(url)
160 webpage = self._download_webpage(
161 url, album_id, note='Download album info',
162 errnote='Unable to get album info')
164 album_name = self._html_search_regex(
165 r'<div[^>]+class="comm"[^<]+<h1[^>]+title="([^"]+)"', webpage,
167 album_intro = remove_start(
168 clean_html(get_element_by_id('intro', webpage)),
169 '%s简介:' % album_name)
172 self.url_result(song_url, 'Kuwo') for song_url in re.findall(
173 r'<p[^>]+class="listen"><a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+/)"',
176 return self.playlist_result(entries, album_id, album_name, album_intro)
179 class KuwoChartIE(InfoExtractor):
180 IE_NAME = 'kuwo:chart'
181 IE_DESC = '酷我音乐 - 排行榜'
182 _VALID_URL = r'https?://yinyue\.kuwo\.cn/billboard_(?P<id>[^.]+).htm'
184 'url': 'http://yinyue.kuwo.cn/billboard_香港中文龙虎榜.htm',
188 'playlist_mincount': 10,
191 def _real_extract(self, url):
192 chart_id = self._match_id(url)
193 webpage = self._download_webpage(
194 url, chart_id, note='Download chart info',
195 errnote='Unable to get chart info')
198 self.url_result(song_url, 'Kuwo') for song_url in re.findall(
199 r'<a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+)', webpage)
201 return self.playlist_result(entries, chart_id)
204 class KuwoSingerIE(InfoExtractor):
205 IE_NAME = 'kuwo:singer'
206 IE_DESC = '酷我音乐 - 歌手'
207 _VALID_URL = r'https?://www\.kuwo\.cn/mingxing/(?P<id>[^/]+)'
209 'url': 'http://www.kuwo.cn/mingxing/bruno+mars/',
212 'title': 'Bruno Mars',
214 'playlist_mincount': 329,
216 'url': 'http://www.kuwo.cn/mingxing/Ali/music.htm',
221 'playlist_mincount': 95,
222 'skip': 'Regularly stalls travis build', # See https://travis-ci.org/rg3/youtube-dl/jobs/78878540
227 def _real_extract(self, url):
228 singer_id = self._match_id(url)
229 webpage = self._download_webpage(
230 url, singer_id, note='Download singer info',
231 errnote='Unable to get singer info')
233 singer_name = self._html_search_regex(
234 r'<h1>([^<]+)</h1>', webpage, 'singer name')
236 artist_id = self._html_search_regex(
237 r'data-artistid="(\d+)"', webpage, 'artist id')
239 page_count = int(self._html_search_regex(
240 r'data-page="(\d+)"', webpage, 'page count'))
242 def page_func(page_num):
243 webpage = self._download_webpage(
244 'http://www.kuwo.cn/artist/contentMusicsAjax',
245 singer_id, note='Download song list page #%d' % (page_num + 1),
246 errnote='Unable to get song list page #%d' % (page_num + 1),
247 query={'artistId': artist_id, 'pn': page_num, 'rn': self.PAGE_SIZE})
250 self.url_result(song_url, 'Kuwo') for song_url in re.findall(
251 r'<div[^>]+class="name"><a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+)',
255 entries = InAdvancePagedList(page_func, page_count, self.PAGE_SIZE)
257 return self.playlist_result(entries, singer_id, singer_name)
260 class KuwoCategoryIE(InfoExtractor):
261 IE_NAME = 'kuwo:category'
262 IE_DESC = '酷我音乐 - 分类'
263 _VALID_URL = r'https?://yinyue\.kuwo\.cn/yy/cinfo_(?P<id>\d+?).htm'
265 'url': 'http://yinyue.kuwo.cn/yy/cinfo_86375.htm',
270 'playlist_mincount': 24,
273 def _real_extract(self, url):
274 category_id = self._match_id(url)
275 webpage = self._download_webpage(
276 url, category_id, note='Download category info',
277 errnote='Unable to get category info')
279 category_name = self._html_search_regex(
280 r'<h1[^>]+title="([^<>]+?)">[^<>]+?</h1>', webpage, 'category name')
282 category_desc = remove_start(
283 get_element_by_id('intro', webpage).strip(),
284 '%s简介:' % category_name)
285 if category_desc == '暂无':
288 jsonm = self._parse_json(self._html_search_regex(
289 r'var\s+jsonm\s*=\s*([^;]+);', webpage, 'category songs'), category_id)
292 self.url_result('http://www.kuwo.cn/yinyue/%s/' % song['musicrid'], 'Kuwo')
293 for song in jsonm['musiclist']
295 return self.playlist_result(entries, category_id, category_name, category_desc)
298 class KuwoMvIE(KuwoBaseIE):
300 IE_DESC = '酷我音乐 - MV'
301 _VALID_URL = r'https?://www\.kuwo\.cn/mv/(?P<id>\d+?)/'
303 'url': 'http://www.kuwo.cn/mv/6480076/',
307 'title': 'My HouseMV',
310 # In this video, music URLs (anti.s) are blocked outside China and
311 # USA, while the MV URL (mvurl) is available globally, so force the MV
312 # URL for consistent results in different countries
317 _FORMATS = KuwoBaseIE._FORMATS + [
318 {'format': 'mkv', 'ext': 'mkv', 'preference': 250},
319 {'format': 'mp4', 'ext': 'mp4', 'preference': 200},
322 def _real_extract(self, url):
323 song_id = self._match_id(url)
324 webpage = self._download_webpage(
325 url, song_id, note='Download mv detail info: %s' % song_id,
326 errnote='Unable to get mv detail info: %s' % song_id)
329 r'<h1[^>]+title="(?P<song>[^"]+)">[^<]+<span[^>]+title="(?P<singer>[^"]+)"',
332 song_name = mobj.group('song')
333 singer_name = mobj.group('singer')
335 raise ExtractorError('Unable to find song or singer names')
337 formats = self._get_formats(song_id, tolerate_ip_deny=True)
339 mv_url = self._download_webpage(
340 'http://www.kuwo.cn/yy/st/mvurl?rid=MUSIC_%s' % song_id,
341 song_id, note='Download %s MV URL' % song_id)
347 self._sort_formats(formats)
352 'creator': singer_name,