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 'format': file_format
['ext'],
31 'br': file_format
.get('br', ''),
32 'rid': 'MUSIC_%s' % song_id
,
33 'type': 'convert_url',
37 song_url
= self
._download
_webpage
(
38 'http://antiserver.kuwo.cn/anti.s',
39 song_id
, note
='Download %s url info' % file_format
['format'],
40 query
=query
, headers
=self
.geo_verification_headers(),
43 if song_url
== 'IPDeny' and not tolerate_ip_deny
:
44 raise ExtractorError('This song is blocked in this region', expected
=True)
46 if song_url
.startswith('http://') or song_url
.startswith('https://'):
49 'format_id': file_format
['format'],
50 'format': file_format
['format'],
51 'preference': file_format
['preference'],
52 'abr': file_format
.get('abr'),
58 class KuwoIE(KuwoBaseIE
):
61 _VALID_URL
= r
'https?://www\.kuwo\.cn/yinyue/(?P<id>\d+)'
63 'url': 'http://www.kuwo.cn/yinyue/635632/',
69 'upload_date': '20080122',
70 'description': 'md5:ed13f58e3c3bf3f7fd9fbc4e5a7aa75c'
72 'skip': 'this song has been offline because of copyright issues',
74 'url': 'http://www.kuwo.cn/yinyue/6446136/',
79 'description': 'md5:5d0e947b242c35dc0eb1d2fce9fbf02c',
81 'upload_date': '20150518',
87 'url': 'http://www.kuwo.cn/yinyue/3197154?catalog=yueku2016',
88 'only_matching': True,
91 def _real_extract(self
, url
):
92 song_id
= self
._match
_id
(url
)
93 webpage
= self
._download
_webpage
(
94 url
, song_id
, note
='Download song detail info',
95 errnote
='Unable to get song detail info')
96 if '对不起,该歌曲由于版权问题已被下线,将返回网站首页' in webpage
:
97 raise ExtractorError('this song has been offline because of copyright issues', expected
=True)
99 song_name
= self
._html
_search
_regex
(
100 r
'<p[^>]+id="lrcName">([^<]+)</p>', webpage
, 'song name')
101 singer_name
= remove_start(self
._html
_search
_regex
(
102 r
'<a[^>]+href="http://www\.kuwo\.cn/artist/content\?name=([^"]+)">',
103 webpage
, 'singer name', fatal
=False), '歌手')
104 lrc_content
= clean_html(get_element_by_id('lrcContent', webpage
))
105 if lrc_content
== '暂无': # indicates no lyrics
108 formats
= self
._get
_formats
(song_id
)
109 self
._sort
_formats
(formats
)
111 album_id
= self
._html
_search
_regex
(
112 r
'<a[^>]+href="http://www\.kuwo\.cn/album/(\d+)/"',
113 webpage
, 'album id', fatal
=False)
116 if album_id
is not None:
117 album_info_page
= self
._download
_webpage
(
118 'http://www.kuwo.cn/album/%s/' % album_id
, song_id
,
119 note
='Download album detail info',
120 errnote
='Unable to get album detail info')
122 publish_time
= self
._html
_search
_regex
(
123 r
'发行时间:(\d{4}-\d{2}-\d{2})', album_info_page
,
124 'publish time', fatal
=False)
126 publish_time
= publish_time
.replace('-', '')
131 'creator': singer_name
,
132 'upload_date': publish_time
,
133 'description': lrc_content
,
138 class KuwoAlbumIE(InfoExtractor
):
139 IE_NAME
= 'kuwo:album'
140 IE_DESC
= '酷我音乐 - 专辑'
141 _VALID_URL
= r
'https?://www\.kuwo\.cn/album/(?P<id>\d+?)/'
143 'url': 'http://www.kuwo.cn/album/502294/',
146 'title': 'Made\xa0Series\xa0《M》',
147 'description': 'md5:d463f0d8a0ff3c3ea3d6ed7452a9483f',
152 def _real_extract(self
, url
):
153 album_id
= self
._match
_id
(url
)
155 webpage
= self
._download
_webpage
(
156 url
, album_id
, note
='Download album info',
157 errnote
='Unable to get album info')
159 album_name
= self
._html
_search
_regex
(
160 r
'<div[^>]+class="comm"[^<]+<h1[^>]+title="([^"]+)"', webpage
,
162 album_intro
= remove_start(
163 clean_html(get_element_by_id('intro', webpage
)),
164 '%s简介:' % album_name
)
167 self
.url_result(song_url
, 'Kuwo') for song_url
in re
.findall(
168 r
'<p[^>]+class="listen"><a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+/)"',
171 return self
.playlist_result(entries
, album_id
, album_name
, album_intro
)
174 class KuwoChartIE(InfoExtractor
):
175 IE_NAME
= 'kuwo:chart'
176 IE_DESC
= '酷我音乐 - 排行榜'
177 _VALID_URL
= r
'https?://yinyue\.kuwo\.cn/billboard_(?P<id>[^.]+).htm'
179 'url': 'http://yinyue.kuwo.cn/billboard_香港中文龙虎榜.htm',
183 'playlist_mincount': 10,
186 def _real_extract(self
, url
):
187 chart_id
= self
._match
_id
(url
)
188 webpage
= self
._download
_webpage
(
189 url
, chart_id
, note
='Download chart info',
190 errnote
='Unable to get chart info')
193 self
.url_result(song_url
, 'Kuwo') for song_url
in re
.findall(
194 r
'<a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+)', webpage
)
196 return self
.playlist_result(entries
, chart_id
)
199 class KuwoSingerIE(InfoExtractor
):
200 IE_NAME
= 'kuwo:singer'
201 IE_DESC
= '酷我音乐 - 歌手'
202 _VALID_URL
= r
'https?://www\.kuwo\.cn/mingxing/(?P<id>[^/]+)'
204 'url': 'http://www.kuwo.cn/mingxing/bruno+mars/',
207 'title': 'Bruno\xa0Mars',
209 'playlist_mincount': 329,
211 'url': 'http://www.kuwo.cn/mingxing/Ali/music.htm',
216 'playlist_mincount': 95,
217 'skip': 'Regularly stalls travis build', # See https://travis-ci.org/rg3/youtube-dl/jobs/78878540
222 def _real_extract(self
, url
):
223 singer_id
= self
._match
_id
(url
)
224 webpage
= self
._download
_webpage
(
225 url
, singer_id
, note
='Download singer info',
226 errnote
='Unable to get singer info')
228 singer_name
= self
._html
_search
_regex
(
229 r
'<h1>([^<]+)</h1>', webpage
, 'singer name')
231 artist_id
= self
._html
_search
_regex
(
232 r
'data-artistid="(\d+)"', webpage
, 'artist id')
234 page_count
= int(self
._html
_search
_regex
(
235 r
'data-page="(\d+)"', webpage
, 'page count'))
237 def page_func(page_num
):
238 webpage
= self
._download
_webpage
(
239 'http://www.kuwo.cn/artist/contentMusicsAjax',
240 singer_id
, note
='Download song list page #%d' % (page_num
+ 1),
241 errnote
='Unable to get song list page #%d' % (page_num
+ 1),
242 query
={'artistId': artist_id, 'pn': page_num, 'rn': self.PAGE_SIZE}
)
245 self
.url_result(song_url
, 'Kuwo') for song_url
in re
.findall(
246 r
'<div[^>]+class="name"><a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+)',
250 entries
= InAdvancePagedList(page_func
, page_count
, self
.PAGE_SIZE
)
252 return self
.playlist_result(entries
, singer_id
, singer_name
)
255 class KuwoCategoryIE(InfoExtractor
):
256 IE_NAME
= 'kuwo:category'
257 IE_DESC
= '酷我音乐 - 分类'
258 _VALID_URL
= r
'https?://yinyue\.kuwo\.cn/yy/cinfo_(?P<id>\d+?).htm'
260 'url': 'http://yinyue.kuwo.cn/yy/cinfo_86375.htm',
264 'description': '这些都是属于八十年代的回忆!',
266 'playlist_mincount': 24,
269 def _real_extract(self
, url
):
270 category_id
= self
._match
_id
(url
)
271 webpage
= self
._download
_webpage
(
272 url
, category_id
, note
='Download category info',
273 errnote
='Unable to get category info')
275 category_name
= self
._html
_search
_regex
(
276 r
'<h1[^>]+title="([^<>]+?)">[^<>]+?</h1>', webpage
, 'category name')
278 category_desc
= remove_start(
279 get_element_by_id('intro', webpage
).strip(),
280 '%s简介:' % category_name
)
281 if category_desc
== '暂无':
284 jsonm
= self
._parse
_json
(self
._html
_search
_regex
(
285 r
'var\s+jsonm\s*=\s*([^;]+);', webpage
, 'category songs'), category_id
)
288 self
.url_result('http://www.kuwo.cn/yinyue/%s/' % song
['musicrid'], 'Kuwo')
289 for song
in jsonm
['musiclist']
291 return self
.playlist_result(entries
, category_id
, category_name
, category_desc
)
294 class KuwoMvIE(KuwoBaseIE
):
296 IE_DESC
= '酷我音乐 - MV'
297 _VALID_URL
= r
'https?://www\.kuwo\.cn/mv/(?P<id>\d+?)/'
299 'url': 'http://www.kuwo.cn/mv/6480076/',
303 'title': 'My HouseMV',
304 'creator': 'PM02:00',
306 # In this video, music URLs (anti.s) are blocked outside China and
307 # USA, while the MV URL (mvurl) is available globally, so force the MV
308 # URL for consistent results in different countries
313 _FORMATS
= KuwoBaseIE
._FORMATS
+ [
314 {'format': 'mkv', 'ext': 'mkv', 'preference': 250}
,
315 {'format': 'mp4', 'ext': 'mp4', 'preference': 200}
,
318 def _real_extract(self
, url
):
319 song_id
= self
._match
_id
(url
)
320 webpage
= self
._download
_webpage
(
321 url
, song_id
, note
='Download mv detail info: %s' % song_id
,
322 errnote
='Unable to get mv detail info: %s' % song_id
)
325 r
'<h1[^>]+title="(?P<song>[^"]+)">[^<]+<span[^>]+title="(?P<singer>[^"]+)"',
328 song_name
= mobj
.group('song')
329 singer_name
= mobj
.group('singer')
331 raise ExtractorError('Unable to find song or singer names')
333 formats
= self
._get
_formats
(song_id
, tolerate_ip_deny
=True)
335 mv_url
= self
._download
_webpage
(
336 'http://www.kuwo.cn/yy/st/mvurl?rid=MUSIC_%s' % song_id
,
337 song_id
, note
='Download %s MV URL' % song_id
)
343 self
._sort
_formats
(formats
)
348 'creator': singer_name
,