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
):
60 _VALID_URL
= r
'https?://(?:www\.)?kuwo\.cn/yinyue/(?P<id>\d+)'
62 'url': 'http://www.kuwo.cn/yinyue/635632/',
68 'upload_date': '20080122',
69 'description': 'md5:ed13f58e3c3bf3f7fd9fbc4e5a7aa75c'
71 'skip': 'this song has been offline because of copyright issues',
73 'url': 'http://www.kuwo.cn/yinyue/6446136/',
78 'description': 'md5:5d0e947b242c35dc0eb1d2fce9fbf02c',
80 'upload_date': '20150518',
86 'url': 'http://www.kuwo.cn/yinyue/3197154?catalog=yueku2016',
87 'only_matching': True,
90 def _real_extract(self
, url
):
91 song_id
= self
._match
_id
(url
)
92 webpage
, urlh
= self
._download
_webpage
_handle
(
93 url
, song_id
, note
='Download song detail info',
94 errnote
='Unable to get song detail info')
95 if song_id
not in urlh
.url
or '对不起,该歌曲由于版权问题已被下线,将返回网站首页' in webpage
:
96 raise ExtractorError('this song has been offline because of copyright issues', expected
=True)
98 song_name
= self
._html
_search
_regex
(
99 r
'<p[^>]+id="lrcName">([^<]+)</p>', webpage
, 'song name')
100 singer_name
= remove_start(self
._html
_search
_regex
(
101 r
'<a[^>]+href="http://www\.kuwo\.cn/artist/content\?name=([^"]+)">',
102 webpage
, 'singer name', fatal
=False), '歌手')
103 lrc_content
= clean_html(get_element_by_id('lrcContent', webpage
))
104 if lrc_content
== '暂无': # indicates no lyrics
107 formats
= self
._get
_formats
(song_id
)
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
):
138 IE_NAME
= 'kuwo:album'
139 IE_DESC
= '酷我音乐 - 专辑'
140 _VALID_URL
= r
'https?://(?:www\.)?kuwo\.cn/album/(?P<id>\d+?)/'
142 'url': 'http://www.kuwo.cn/album/502294/',
145 'title': 'Made\xa0Series\xa0《M》',
146 'description': 'md5:d463f0d8a0ff3c3ea3d6ed7452a9483f',
151 def _real_extract(self
, url
):
152 album_id
= self
._match
_id
(url
)
154 webpage
= self
._download
_webpage
(
155 url
, album_id
, note
='Download album info',
156 errnote
='Unable to get album info')
158 album_name
= self
._html
_search
_regex
(
159 r
'<div[^>]+class="comm"[^<]+<h1[^>]+title="([^"]+)"', webpage
,
161 album_intro
= remove_start(
162 clean_html(get_element_by_id('intro', webpage
)),
163 '%s简介:' % album_name
)
166 self
.url_result(song_url
, 'Kuwo') for song_url
in re
.findall(
167 r
'<p[^>]+class="listen"><a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+/)"',
170 return self
.playlist_result(entries
, album_id
, album_name
, album_intro
)
173 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': 7,
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
):
201 IE_NAME
= 'kuwo:singer'
202 IE_DESC
= '酷我音乐 - 歌手'
203 _VALID_URL
= r
'https?://(?:www\.)?kuwo\.cn/mingxing/(?P<id>[^/]+)'
205 'url': 'http://www.kuwo.cn/mingxing/bruno+mars/',
208 'title': 'Bruno\xa0Mars',
210 'playlist_mincount': 329,
212 'url': 'http://www.kuwo.cn/mingxing/Ali/music.htm',
217 'playlist_mincount': 95,
218 'skip': 'Regularly stalls travis build', # See https://travis-ci.org/ytdl-org/youtube-dl/jobs/78878540
223 def _real_extract(self
, url
):
224 singer_id
= self
._match
_id
(url
)
225 webpage
= self
._download
_webpage
(
226 url
, singer_id
, note
='Download singer info',
227 errnote
='Unable to get singer info')
229 singer_name
= self
._html
_search
_regex
(
230 r
'<h1>([^<]+)</h1>', webpage
, 'singer name')
232 artist_id
= self
._html
_search
_regex
(
233 r
'data-artistid="(\d+)"', webpage
, 'artist id')
235 page_count
= int(self
._html
_search
_regex
(
236 r
'data-page="(\d+)"', webpage
, 'page count'))
238 def page_func(page_num
):
239 webpage
= self
._download
_webpage
(
240 'http://www.kuwo.cn/artist/contentMusicsAjax',
241 singer_id
, note
='Download song list page #%d' % (page_num
+ 1),
242 errnote
='Unable to get song list page #%d' % (page_num
+ 1),
243 query
={'artistId': artist_id
, 'pn': page_num
, 'rn': self
.PAGE_SIZE
})
246 self
.url_result(compat_urlparse
.urljoin(url
, song_url
), 'Kuwo')
247 for song_url
in re
.findall(
248 r
'<div[^>]+class="name"><a[^>]+href="(/yinyue/\d+)',
252 entries
= InAdvancePagedList(page_func
, page_count
, self
.PAGE_SIZE
)
254 return self
.playlist_result(entries
, singer_id
, singer_name
)
257 class KuwoCategoryIE(InfoExtractor
):
259 IE_NAME
= 'kuwo:category'
260 IE_DESC
= '酷我音乐 - 分类'
261 _VALID_URL
= r
'https?://yinyue\.kuwo\.cn/yy/cinfo_(?P<id>\d+?).htm'
263 'url': 'http://yinyue.kuwo.cn/yy/cinfo_86375.htm',
267 'description': '这些都是属于八十年代的回忆!',
269 'playlist_mincount': 24,
272 def _real_extract(self
, url
):
273 category_id
= self
._match
_id
(url
)
274 webpage
= self
._download
_webpage
(
275 url
, category_id
, note
='Download category info',
276 errnote
='Unable to get category info')
278 category_name
= self
._html
_search
_regex
(
279 r
'<h1[^>]+title="([^<>]+?)">[^<>]+?</h1>', webpage
, 'category name')
281 category_desc
= remove_start(
282 get_element_by_id('intro', webpage
).strip(),
283 '%s简介:' % category_name
)
284 if category_desc
== '暂无':
287 jsonm
= self
._parse
_json
(self
._html
_search
_regex
(
288 r
'var\s+jsonm\s*=\s*([^;]+);', webpage
, 'category songs'), category_id
)
291 self
.url_result('http://www.kuwo.cn/yinyue/%s/' % song
['musicrid'], 'Kuwo')
292 for song
in jsonm
['musiclist']
294 return self
.playlist_result(entries
, category_id
, category_name
, category_desc
)
297 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
)
350 'creator': singer_name
,