3 from .common
import InfoExtractor
4 from ..compat
import compat_urlparse
14 class KuwoBaseIE(InfoExtractor
):
16 {'format': 'ape', 'ext': 'ape', 'preference': 100}
,
17 {'format': 'mp3-320', 'ext': 'mp3', 'br': '320kmp3', 'abr': 320, 'preference': 80}
,
18 {'format': 'mp3-192', 'ext': 'mp3', 'br': '192kmp3', 'abr': 192, 'preference': 70}
,
19 {'format': 'mp3-128', 'ext': 'mp3', 'br': '128kmp3', 'abr': 128, 'preference': 60}
,
20 {'format': 'wma', 'ext': 'wma', 'preference': 20}
,
21 {'format': 'aac', 'ext': 'aac', 'abr': 48, 'preference': 10}
24 def _get_formats(self
, song_id
, tolerate_ip_deny
=False):
26 for file_format
in self
._FORMATS
:
28 'format': file_format
['ext'],
29 'br': file_format
.get('br', ''),
30 'rid': 'MUSIC_%s' % song_id
,
31 'type': 'convert_url',
35 song_url
= self
._download
_webpage
(
36 'http://antiserver.kuwo.cn/anti.s',
37 song_id
, note
='Download %s url info' % file_format
['format'],
38 query
=query
, headers
=self
.geo_verification_headers(),
41 if song_url
== 'IPDeny' and not tolerate_ip_deny
:
42 raise ExtractorError('This song is blocked in this region', expected
=True)
44 if song_url
.startswith('http://') or song_url
.startswith('https://'):
47 'format_id': file_format
['format'],
48 'format': file_format
['format'],
49 'quality': file_format
['preference'],
50 'abr': file_format
.get('abr'),
56 class KuwoIE(KuwoBaseIE
):
59 _VALID_URL
= r
'https?://(?:www\.)?kuwo\.cn/yinyue/(?P<id>\d+)'
61 'url': 'http://www.kuwo.cn/yinyue/635632/',
67 'upload_date': '20080122',
68 'description': 'md5:ed13f58e3c3bf3f7fd9fbc4e5a7aa75c'
70 'skip': 'this song has been offline because of copyright issues',
72 'url': 'http://www.kuwo.cn/yinyue/6446136/',
77 'description': 'md5:5d0e947b242c35dc0eb1d2fce9fbf02c',
79 'upload_date': '20150518',
85 'url': 'http://www.kuwo.cn/yinyue/3197154?catalog=yueku2016',
86 'only_matching': True,
89 def _real_extract(self
, url
):
90 song_id
= self
._match
_id
(url
)
91 webpage
, urlh
= self
._download
_webpage
_handle
(
92 url
, song_id
, note
='Download song detail info',
93 errnote
='Unable to get song detail info')
94 if song_id
not in urlh
.geturl() or '对不起,该歌曲由于版权问题已被下线,将返回网站首页' in webpage
:
95 raise ExtractorError('this song has been offline because of copyright issues', expected
=True)
97 song_name
= self
._html
_search
_regex
(
98 r
'<p[^>]+id="lrcName">([^<]+)</p>', webpage
, 'song name')
99 singer_name
= remove_start(self
._html
_search
_regex
(
100 r
'<a[^>]+href="http://www\.kuwo\.cn/artist/content\?name=([^"]+)">',
101 webpage
, 'singer name', fatal
=False), '歌手')
102 lrc_content
= clean_html(get_element_by_id('lrcContent', webpage
))
103 if lrc_content
== '暂无': # indicates no lyrics
106 formats
= self
._get
_formats
(song_id
)
107 self
._sort
_formats
(formats
)
109 album_id
= self
._html
_search
_regex
(
110 r
'<a[^>]+href="http://www\.kuwo\.cn/album/(\d+)/"',
111 webpage
, 'album id', fatal
=False)
114 if album_id
is not None:
115 album_info_page
= self
._download
_webpage
(
116 'http://www.kuwo.cn/album/%s/' % album_id
, song_id
,
117 note
='Download album detail info',
118 errnote
='Unable to get album detail info')
120 publish_time
= self
._html
_search
_regex
(
121 r
'发行时间:(\d{4}-\d{2}-\d{2})', album_info_page
,
122 'publish time', fatal
=False)
124 publish_time
= publish_time
.replace('-', '')
129 'creator': singer_name
,
130 'upload_date': publish_time
,
131 'description': lrc_content
,
136 class KuwoAlbumIE(InfoExtractor
):
137 IE_NAME
= 'kuwo:album'
138 IE_DESC
= '酷我音乐 - 专辑'
139 _VALID_URL
= r
'https?://(?:www\.)?kuwo\.cn/album/(?P<id>\d+?)/'
141 'url': 'http://www.kuwo.cn/album/502294/',
144 'title': 'Made\xa0Series\xa0《M》',
145 'description': 'md5:d463f0d8a0ff3c3ea3d6ed7452a9483f',
150 def _real_extract(self
, url
):
151 album_id
= self
._match
_id
(url
)
153 webpage
= self
._download
_webpage
(
154 url
, album_id
, note
='Download album info',
155 errnote
='Unable to get album info')
157 album_name
= self
._html
_search
_regex
(
158 r
'<div[^>]+class="comm"[^<]+<h1[^>]+title="([^"]+)"', webpage
,
160 album_intro
= remove_start(
161 clean_html(get_element_by_id('intro', webpage
)),
162 '%s简介:' % album_name
)
165 self
.url_result(song_url
, 'Kuwo') for song_url
in re
.findall(
166 r
'<p[^>]+class="listen"><a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+/)"',
169 return self
.playlist_result(entries
, album_id
, album_name
, album_intro
)
172 class KuwoChartIE(InfoExtractor
):
173 IE_NAME
= 'kuwo:chart'
174 IE_DESC
= '酷我音乐 - 排行榜'
175 _VALID_URL
= r
'https?://yinyue\.kuwo\.cn/billboard_(?P<id>[^.]+).htm'
177 'url': 'http://yinyue.kuwo.cn/billboard_香港中文龙虎榜.htm',
181 'playlist_mincount': 7,
184 def _real_extract(self
, url
):
185 chart_id
= self
._match
_id
(url
)
186 webpage
= self
._download
_webpage
(
187 url
, chart_id
, note
='Download chart info',
188 errnote
='Unable to get chart info')
191 self
.url_result(song_url
, 'Kuwo') for song_url
in re
.findall(
192 r
'<a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+)', webpage
)
194 return self
.playlist_result(entries
, chart_id
)
197 class KuwoSingerIE(InfoExtractor
):
198 IE_NAME
= 'kuwo:singer'
199 IE_DESC
= '酷我音乐 - 歌手'
200 _VALID_URL
= r
'https?://(?:www\.)?kuwo\.cn/mingxing/(?P<id>[^/]+)'
202 'url': 'http://www.kuwo.cn/mingxing/bruno+mars/',
205 'title': 'Bruno\xa0Mars',
207 'playlist_mincount': 329,
209 'url': 'http://www.kuwo.cn/mingxing/Ali/music.htm',
214 'playlist_mincount': 95,
215 'skip': 'Regularly stalls travis build', # See https://travis-ci.org/ytdl-org/youtube-dl/jobs/78878540
220 def _real_extract(self
, url
):
221 singer_id
= self
._match
_id
(url
)
222 webpage
= self
._download
_webpage
(
223 url
, singer_id
, note
='Download singer info',
224 errnote
='Unable to get singer info')
226 singer_name
= self
._html
_search
_regex
(
227 r
'<h1>([^<]+)</h1>', webpage
, 'singer name')
229 artist_id
= self
._html
_search
_regex
(
230 r
'data-artistid="(\d+)"', webpage
, 'artist id')
232 page_count
= int(self
._html
_search
_regex
(
233 r
'data-page="(\d+)"', webpage
, 'page count'))
235 def page_func(page_num
):
236 webpage
= self
._download
_webpage
(
237 'http://www.kuwo.cn/artist/contentMusicsAjax',
238 singer_id
, note
='Download song list page #%d' % (page_num
+ 1),
239 errnote
='Unable to get song list page #%d' % (page_num
+ 1),
240 query
={'artistId': artist_id, 'pn': page_num, 'rn': self.PAGE_SIZE}
)
243 self
.url_result(compat_urlparse
.urljoin(url
, song_url
), 'Kuwo')
244 for song_url
in re
.findall(
245 r
'<div[^>]+class="name"><a[^>]+href="(/yinyue/\d+)',
249 entries
= InAdvancePagedList(page_func
, page_count
, self
.PAGE_SIZE
)
251 return self
.playlist_result(entries
, singer_id
, singer_name
)
254 class KuwoCategoryIE(InfoExtractor
):
255 IE_NAME
= 'kuwo:category'
256 IE_DESC
= '酷我音乐 - 分类'
257 _VALID_URL
= r
'https?://yinyue\.kuwo\.cn/yy/cinfo_(?P<id>\d+?).htm'
259 'url': 'http://yinyue.kuwo.cn/yy/cinfo_86375.htm',
263 'description': '这些都是属于八十年代的回忆!',
265 'playlist_mincount': 24,
268 def _real_extract(self
, url
):
269 category_id
= self
._match
_id
(url
)
270 webpage
= self
._download
_webpage
(
271 url
, category_id
, note
='Download category info',
272 errnote
='Unable to get category info')
274 category_name
= self
._html
_search
_regex
(
275 r
'<h1[^>]+title="([^<>]+?)">[^<>]+?</h1>', webpage
, 'category name')
277 category_desc
= remove_start(
278 get_element_by_id('intro', webpage
).strip(),
279 '%s简介:' % category_name
)
280 if category_desc
== '暂无':
283 jsonm
= self
._parse
_json
(self
._html
_search
_regex
(
284 r
'var\s+jsonm\s*=\s*([^;]+);', webpage
, 'category songs'), category_id
)
287 self
.url_result('http://www.kuwo.cn/yinyue/%s/' % song
['musicrid'], 'Kuwo')
288 for song
in jsonm
['musiclist']
290 return self
.playlist_result(entries
, category_id
, category_name
, category_desc
)
293 class KuwoMvIE(KuwoBaseIE
):
295 IE_DESC
= '酷我音乐 - MV'
296 _VALID_URL
= r
'https?://(?:www\.)?kuwo\.cn/mv/(?P<id>\d+?)/'
298 'url': 'http://www.kuwo.cn/mv/6480076/',
302 'title': 'My HouseMV',
305 # In this video, music URLs (anti.s) are blocked outside China and
306 # USA, while the MV URL (mvurl) is available globally, so force the MV
307 # URL for consistent results in different countries
312 _FORMATS
= KuwoBaseIE
._FORMATS
+ [
313 {'format': 'mkv', 'ext': 'mkv', 'preference': 250}
,
314 {'format': 'mp4', 'ext': 'mp4', 'preference': 200}
,
317 def _real_extract(self
, url
):
318 song_id
= self
._match
_id
(url
)
319 webpage
= self
._download
_webpage
(
320 url
, song_id
, note
='Download mv detail info: %s' % song_id
,
321 errnote
='Unable to get mv detail info: %s' % song_id
)
324 r
'<h1[^>]+title="(?P<song>[^"]+)">[^<]+<span[^>]+title="(?P<singer>[^"]+)"',
327 song_name
= mobj
.group('song')
328 singer_name
= mobj
.group('singer')
330 raise ExtractorError('Unable to find song or singer names')
332 formats
= self
._get
_formats
(song_id
, tolerate_ip_deny
=True)
334 mv_url
= self
._download
_webpage
(
335 'http://www.kuwo.cn/yy/st/mvurl?rid=MUSIC_%s' % song_id
,
336 song_id
, note
='Download %s MV URL' % song_id
)
342 self
._sort
_formats
(formats
)
347 'creator': singer_name
,