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'],
35 if song_url == 'IPDeny':
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'),
46 self._sort_formats(formats)
50 class KuwoIE(KuwoBaseIE):
53 _VALID_URL = r'http://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',
80 def _real_extract(self, url):
81 song_id = self._match_id(url)
82 webpage = self._download_webpage(
83 url, song_id, note='Download song detail info',
84 errnote='Unable to get song detail info')
85 if '对不起,该歌曲由于版权问题已被下线,将返回网站首页' in webpage:
86 raise ExtractorError('this song has been offline because of copyright issues', expected=True)
88 song_name = self._html_search_regex(
89 r'(?s)class="(?:[^"\s]+\s+)*title(?:\s+[^"\s]+)*".*?<h1[^>]+title="([^"]+)"', webpage, 'song name')
90 singer_name = self._html_search_regex(
91 r'<div[^>]+class="s_img">\s*<a[^>]+title="([^>]+)"',
92 webpage, 'singer name', fatal=False)
93 lrc_content = clean_html(get_element_by_id('lrcContent', webpage))
94 if lrc_content == '暂无': # indicates no lyrics
97 formats = self._get_formats(song_id)
99 album_id = self._html_search_regex(
100 r'<p[^>]+class="album"[^<]+<a[^>]+href="http://www\.kuwo\.cn/album/(\d+)/"',
101 webpage, 'album id', fatal=False)
104 if album_id is not None:
105 album_info_page = self._download_webpage(
106 'http://www.kuwo.cn/album/%s/' % album_id, song_id,
107 note='Download album detail info',
108 errnote='Unable to get album detail info')
110 publish_time = self._html_search_regex(
111 r'发行时间:(\d{4}-\d{2}-\d{2})', album_info_page,
112 'publish time', fatal=False)
114 publish_time = publish_time.replace('-', '')
119 'creator': singer_name,
120 'upload_date': publish_time,
121 'description': lrc_content,
126 class KuwoAlbumIE(InfoExtractor):
127 IE_NAME = 'kuwo:album'
128 IE_DESC = '酷我音乐 - 专辑'
129 _VALID_URL = r'http://www\.kuwo\.cn/album/(?P<id>\d+?)/'
131 'url': 'http://www.kuwo.cn/album/502294/',
135 'description': 'md5:6a7235a84cc6400ec3b38a7bdaf1d60c',
140 def _real_extract(self, url):
141 album_id = self._match_id(url)
143 webpage = self._download_webpage(
144 url, album_id, note='Download album info',
145 errnote='Unable to get album info')
147 album_name = self._html_search_regex(
148 r'<div[^>]+class="comm"[^<]+<h1[^>]+title="([^"]+)"', webpage,
150 album_intro = remove_start(
151 clean_html(get_element_by_id('intro', webpage)),
152 '%s简介:' % album_name)
155 self.url_result(song_url, 'Kuwo') for song_url in re.findall(
156 r'<p[^>]+class="listen"><a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+/)"',
159 return self.playlist_result(entries, album_id, album_name, album_intro)
162 class KuwoChartIE(InfoExtractor):
163 IE_NAME = 'kuwo:chart'
164 IE_DESC = '酷我音乐 - 排行榜'
165 _VALID_URL = r'http://yinyue\.kuwo\.cn/billboard_(?P<id>[^.]+).htm'
167 'url': 'http://yinyue.kuwo.cn/billboard_香港中文龙虎榜.htm',
171 'description': 're:\d{4}第\d{2}期',
173 'playlist_mincount': 10,
176 def _real_extract(self, url):
177 chart_id = self._match_id(url)
178 webpage = self._download_webpage(
179 url, chart_id, note='Download chart info',
180 errnote='Unable to get chart info')
182 chart_name = self._html_search_regex(
183 r'<h1[^>]+class="unDis">([^<]+)</h1>', webpage, 'chart name')
185 chart_desc = self._html_search_regex(
186 r'<p[^>]+class="tabDef">(\d{4}第\d{2}期)</p>', webpage, 'chart desc')
189 self.url_result(song_url, 'Kuwo') for song_url in re.findall(
190 r'<a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+)/"', webpage)
192 return self.playlist_result(entries, chart_id, chart_name, chart_desc)
195 class KuwoSingerIE(InfoExtractor):
196 IE_NAME = 'kuwo:singer'
197 IE_DESC = '酷我音乐 - 歌手'
198 _VALID_URL = r'http://www\.kuwo\.cn/mingxing/(?P<id>[^/]+)'
200 'url': 'http://www.kuwo.cn/mingxing/bruno+mars/',
203 'title': 'Bruno Mars',
205 'playlist_count': 10,
207 'url': 'http://www.kuwo.cn/mingxing/Ali/music.htm',
212 'playlist_mincount': 95,
213 'skip': 'Regularly stalls travis build', # See https://travis-ci.org/rg3/youtube-dl/jobs/78878540
216 def _real_extract(self, url):
217 singer_id = self._match_id(url)
218 webpage = self._download_webpage(
219 url, singer_id, note='Download singer info',
220 errnote='Unable to get singer info')
222 singer_name = self._html_search_regex(
223 r'<div class="title clearfix">\s*<h1>([^<]+)<span', webpage, 'singer name'
227 first_page_only = False if re.search(r'/music(?:_\d+)?\.htm', url) else True
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)
235 self.url_result(song_url, 'Kuwo') for song_url in re.findall(
236 r'<p[^>]+class="m_name"><a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+)/',
238 ][:10 if first_page_only else None])
240 if first_page_only or not re.search(r'<a[^>]+href="[^"]+">下一页</a>', webpage):
243 return self.playlist_result(entries, singer_id, singer_name)
246 class KuwoCategoryIE(InfoExtractor):
247 IE_NAME = 'kuwo:category'
248 IE_DESC = '酷我音乐 - 分类'
249 _VALID_URL = r'http://yinyue\.kuwo\.cn/yy/cinfo_(?P<id>\d+?).htm'
251 'url': 'http://yinyue.kuwo.cn/yy/cinfo_86375.htm',
255 'description': '这些都是属于八十年代的回忆!',
257 'playlist_count': 30,
260 def _real_extract(self, url):
261 category_id = self._match_id(url)
262 webpage = self._download_webpage(
263 url, category_id, note='Download category info',
264 errnote='Unable to get category info')
266 category_name = self._html_search_regex(
267 r'<h1[^>]+title="([^<>]+?)">[^<>]+?</h1>', webpage, 'category name')
269 category_desc = remove_start(
270 get_element_by_id('intro', webpage).strip(),
271 '%s简介:' % category_name)
273 jsonm = self._parse_json(self._html_search_regex(
274 r'var\s+jsonm\s*=\s*([^;]+);', webpage, 'category songs'), category_id)
277 self.url_result('http://www.kuwo.cn/yinyue/%s/' % song['musicrid'], 'Kuwo')
278 for song in jsonm['musiclist']
280 return self.playlist_result(entries, category_id, category_name, category_desc)
283 class KuwoMvIE(KuwoBaseIE):
285 IE_DESC = '酷我音乐 - MV'
286 _VALID_URL = r'http://www\.kuwo\.cn/mv/(?P<id>\d+?)/'
288 'url': 'http://www.kuwo.cn/mv/6480076/',
296 _FORMATS = KuwoBaseIE._FORMATS + [
297 {'format': 'mkv', 'ext': 'mkv', 'preference': 250},
298 {'format': 'mp4', 'ext': 'mp4', 'preference': 200},
301 def _real_extract(self, url):
302 song_id = self._match_id(url)
303 webpage = self._download_webpage(
304 url, song_id, note='Download mv detail info: %s' % song_id,
305 errnote='Unable to get mv detail info: %s' % song_id)
308 r'<h1[^>]+title="(?P<song>[^"]+)">[^<]+<span[^>]+title="(?P<singer>[^"]+)"',
311 song_name = mobj.group('song')
312 singer_name = mobj.group('singer')
314 raise ExtractorError('Unable to find song or singer names')
316 formats = self._get_formats(song_id)
321 'creator': singer_name,