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:
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'],
35 if song_url == 'IPDeny' and not tolerate_ip_deny:
36 raise ExtractorError('This song is blocked in this region', expected=True)
38 if song_url.startswith('http://') or song_url.startswith('https://'):
41 'format_id': file_format['format'],
42 'format': file_format['format'],
43 'preference': file_format['preference'],
44 'abr': file_format.get('abr'),
50 class KuwoIE(KuwoBaseIE):
53 _VALID_URL = r'https?://www\.kuwo\.cn/yinyue/(?P<id>\d+)'
55 'url': 'http://www.kuwo.cn/yinyue/635632/',
61 'upload_date': '20080122',
62 'description': 'md5:ed13f58e3c3bf3f7fd9fbc4e5a7aa75c'
64 'skip': 'this song has been offline because of copyright issues',
66 'url': 'http://www.kuwo.cn/yinyue/6446136/',
71 'description': 'md5:b2ab6295d014005bfc607525bfc1e38a',
73 'upload_date': '20150518',
79 'url': 'http://www.kuwo.cn/yinyue/3197154?catalog=yueku2016',
80 'only_matching': True,
83 def _real_extract(self, url):
84 song_id = self._match_id(url)
85 webpage = self._download_webpage(
86 url, song_id, note='Download song detail info',
87 errnote='Unable to get song detail info')
88 if '对不起,该歌曲由于版权问题已被下线,将返回网站首页' in webpage:
89 raise ExtractorError('this song has been offline because of copyright issues', expected=True)
91 song_name = self._html_search_regex(
92 r'(?s)class="(?:[^"\s]+\s+)*title(?:\s+[^"\s]+)*".*?<h1[^>]+title="([^"]+)"', webpage, 'song name')
93 singer_name = self._html_search_regex(
94 r'<div[^>]+class="s_img">\s*<a[^>]+title="([^>]+)"',
95 webpage, 'singer name', fatal=False)
96 lrc_content = clean_html(get_element_by_id('lrcContent', webpage))
97 if lrc_content == '暂无': # indicates no lyrics
100 formats = self._get_formats(song_id)
101 self._sort_formats(formats)
103 album_id = self._html_search_regex(
104 r'<p[^>]+class="album"[^<]+<a[^>]+href="http://www\.kuwo\.cn/album/(\d+)/"',
105 webpage, 'album id', fatal=False)
108 if album_id is not None:
109 album_info_page = self._download_webpage(
110 'http://www.kuwo.cn/album/%s/' % album_id, song_id,
111 note='Download album detail info',
112 errnote='Unable to get album detail info')
114 publish_time = self._html_search_regex(
115 r'发行时间:(\d{4}-\d{2}-\d{2})', album_info_page,
116 'publish time', fatal=False)
118 publish_time = publish_time.replace('-', '')
123 'creator': singer_name,
124 'upload_date': publish_time,
125 'description': lrc_content,
130 class KuwoAlbumIE(InfoExtractor):
131 IE_NAME = 'kuwo:album'
132 IE_DESC = '酷我音乐 - 专辑'
133 _VALID_URL = r'https?://www\.kuwo\.cn/album/(?P<id>\d+?)/'
135 'url': 'http://www.kuwo.cn/album/502294/',
139 'description': 'md5:6a7235a84cc6400ec3b38a7bdaf1d60c',
144 def _real_extract(self, url):
145 album_id = self._match_id(url)
147 webpage = self._download_webpage(
148 url, album_id, note='Download album info',
149 errnote='Unable to get album info')
151 album_name = self._html_search_regex(
152 r'<div[^>]+class="comm"[^<]+<h1[^>]+title="([^"]+)"', webpage,
154 album_intro = remove_start(
155 clean_html(get_element_by_id('intro', webpage)),
156 '%s简介:' % album_name)
159 self.url_result(song_url, 'Kuwo') for song_url in re.findall(
160 r'<p[^>]+class="listen"><a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+/)"',
163 return self.playlist_result(entries, album_id, album_name, album_intro)
166 class KuwoChartIE(InfoExtractor):
167 IE_NAME = 'kuwo:chart'
168 IE_DESC = '酷我音乐 - 排行榜'
169 _VALID_URL = r'https?://yinyue\.kuwo\.cn/billboard_(?P<id>[^.]+).htm'
171 'url': 'http://yinyue.kuwo.cn/billboard_香港中文龙虎榜.htm',
175 'playlist_mincount': 10,
178 def _real_extract(self, url):
179 chart_id = self._match_id(url)
180 webpage = self._download_webpage(
181 url, chart_id, note='Download chart info',
182 errnote='Unable to get chart info')
185 self.url_result(song_url, 'Kuwo') for song_url in re.findall(
186 r'<a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+)', webpage)
188 return self.playlist_result(entries, chart_id)
191 class KuwoSingerIE(InfoExtractor):
192 IE_NAME = 'kuwo:singer'
193 IE_DESC = '酷我音乐 - 歌手'
194 _VALID_URL = r'https?://www\.kuwo\.cn/mingxing/(?P<id>[^/]+)'
196 'url': 'http://www.kuwo.cn/mingxing/bruno+mars/',
199 'title': 'Bruno Mars',
201 'playlist_mincount': 329,
203 'url': 'http://www.kuwo.cn/mingxing/Ali/music.htm',
208 'playlist_mincount': 95,
209 'skip': 'Regularly stalls travis build', # See https://travis-ci.org/rg3/youtube-dl/jobs/78878540
214 def _real_extract(self, url):
215 singer_id = self._match_id(url)
216 webpage = self._download_webpage(
217 url, singer_id, note='Download singer info',
218 errnote='Unable to get singer info')
220 singer_name = self._html_search_regex(
221 r'<h1>([^<]+)</h1>', webpage, 'singer name')
223 artist_id = self._html_search_regex(
224 r'data-artistid="(\d+)"', webpage, 'artist id')
226 page_count = int(self._html_search_regex(
227 r'data-page="(\d+)"', webpage, 'page count'))
229 def page_func(page_num):
230 webpage = self._download_webpage(
231 'http://www.kuwo.cn/artist/contentMusicsAjax',
232 singer_id, note='Download song list page #%d' % (page_num + 1),
233 errnote='Unable to get song list page #%d' % (page_num + 1),
234 query={'artistId': artist_id, 'pn': page_num, 'rn': self.PAGE_SIZE})
237 self.url_result(song_url, 'Kuwo') for song_url in re.findall(
238 r'<div[^>]+class="name"><a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+)',
242 entries = InAdvancePagedList(page_func, page_count, self.PAGE_SIZE)
244 return self.playlist_result(entries, singer_id, singer_name)
247 class KuwoCategoryIE(InfoExtractor):
248 IE_NAME = 'kuwo:category'
249 IE_DESC = '酷我音乐 - 分类'
250 _VALID_URL = r'https?://yinyue\.kuwo\.cn/yy/cinfo_(?P<id>\d+?).htm'
252 'url': 'http://yinyue.kuwo.cn/yy/cinfo_86375.htm',
256 'description': '这些都是属于八十年代的回忆!',
258 'playlist_count': 30,
261 def _real_extract(self, url):
262 category_id = self._match_id(url)
263 webpage = self._download_webpage(
264 url, category_id, note='Download category info',
265 errnote='Unable to get category info')
267 category_name = self._html_search_regex(
268 r'<h1[^>]+title="([^<>]+?)">[^<>]+?</h1>', webpage, 'category name')
270 category_desc = remove_start(
271 get_element_by_id('intro', webpage).strip(),
272 '%s简介:' % category_name)
274 jsonm = self._parse_json(self._html_search_regex(
275 r'var\s+jsonm\s*=\s*([^;]+);', webpage, 'category songs'), category_id)
278 self.url_result('http://www.kuwo.cn/yinyue/%s/' % song['musicrid'], 'Kuwo')
279 for song in jsonm['musiclist']
281 return self.playlist_result(entries, category_id, category_name, category_desc)
284 class KuwoMvIE(KuwoBaseIE):
286 IE_DESC = '酷我音乐 - MV'
287 _VALID_URL = r'https?://www\.kuwo\.cn/mv/(?P<id>\d+?)/'
289 'url': 'http://www.kuwo.cn/mv/6480076/',
293 'title': 'My HouseMV',
296 # In this video, music URLs (anti.s) are blocked outside China and
297 # USA, while the MV URL (mvurl) is available globally, so force the MV
298 # URL for consistent results in different countries
303 _FORMATS = KuwoBaseIE._FORMATS + [
304 {'format': 'mkv', 'ext': 'mkv', 'preference': 250},
305 {'format': 'mp4', 'ext': 'mp4', 'preference': 200},
308 def _real_extract(self, url):
309 song_id = self._match_id(url)
310 webpage = self._download_webpage(
311 url, song_id, note='Download mv detail info: %s' % song_id,
312 errnote='Unable to get mv detail info: %s' % song_id)
315 r'<h1[^>]+title="(?P<song>[^"]+)">[^<]+<span[^>]+title="(?P<singer>[^"]+)"',
318 song_name = mobj.group('song')
319 singer_name = mobj.group('singer')
321 raise ExtractorError('Unable to find song or singer names')
323 formats = self._get_formats(song_id, tolerate_ip_deny=True)
325 mv_url = self._download_webpage(
326 'http://www.kuwo.cn/yy/st/mvurl?rid=MUSIC_%s' % song_id,
327 song_id, note='Download %s MV URL' % song_id)
333 self._sort_formats(formats)
338 'creator': singer_name,