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
)
108 album_id
= self
._html
_search
_regex
(
109 r
'<a[^>]+href="http://www\.kuwo\.cn/album/(\d+)/"',
110 webpage
, 'album id', fatal
=False)
113 if album_id
is not None:
114 album_info_page
= self
._download
_webpage
(
115 'http://www.kuwo.cn/album/%s/' % album_id
, song_id
,
116 note
='Download album detail info',
117 errnote
='Unable to get album detail info')
119 publish_time
= self
._html
_search
_regex
(
120 r
'发行时间:(\d{4}-\d{2}-\d{2})', album_info_page
,
121 'publish time', fatal
=False)
123 publish_time
= publish_time
.replace('-', '')
128 'creator': singer_name
,
129 'upload_date': publish_time
,
130 'description': lrc_content
,
135 class KuwoAlbumIE(InfoExtractor
):
136 IE_NAME
= 'kuwo:album'
137 IE_DESC
= '酷我音乐 - 专辑'
138 _VALID_URL
= r
'https?://(?:www\.)?kuwo\.cn/album/(?P<id>\d+?)/'
140 'url': 'http://www.kuwo.cn/album/502294/',
143 'title': 'Made\xa0Series\xa0《M》',
144 'description': 'md5:d463f0d8a0ff3c3ea3d6ed7452a9483f',
149 def _real_extract(self
, url
):
150 album_id
= self
._match
_id
(url
)
152 webpage
= self
._download
_webpage
(
153 url
, album_id
, note
='Download album info',
154 errnote
='Unable to get album info')
156 album_name
= self
._html
_search
_regex
(
157 r
'<div[^>]+class="comm"[^<]+<h1[^>]+title="([^"]+)"', webpage
,
159 album_intro
= remove_start(
160 clean_html(get_element_by_id('intro', webpage
)),
161 '%s简介:' % album_name
)
164 self
.url_result(song_url
, 'Kuwo') for song_url
in re
.findall(
165 r
'<p[^>]+class="listen"><a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+/)"',
168 return self
.playlist_result(entries
, album_id
, album_name
, album_intro
)
171 class KuwoChartIE(InfoExtractor
):
172 IE_NAME
= 'kuwo:chart'
173 IE_DESC
= '酷我音乐 - 排行榜'
174 _VALID_URL
= r
'https?://yinyue\.kuwo\.cn/billboard_(?P<id>[^.]+).htm'
176 'url': 'http://yinyue.kuwo.cn/billboard_香港中文龙虎榜.htm',
180 'playlist_mincount': 7,
183 def _real_extract(self
, url
):
184 chart_id
= self
._match
_id
(url
)
185 webpage
= self
._download
_webpage
(
186 url
, chart_id
, note
='Download chart info',
187 errnote
='Unable to get chart info')
190 self
.url_result(song_url
, 'Kuwo') for song_url
in re
.findall(
191 r
'<a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+)', webpage
)
193 return self
.playlist_result(entries
, chart_id
)
196 class KuwoSingerIE(InfoExtractor
):
197 IE_NAME
= 'kuwo:singer'
198 IE_DESC
= '酷我音乐 - 歌手'
199 _VALID_URL
= r
'https?://(?:www\.)?kuwo\.cn/mingxing/(?P<id>[^/]+)'
201 'url': 'http://www.kuwo.cn/mingxing/bruno+mars/',
204 'title': 'Bruno\xa0Mars',
206 'playlist_mincount': 329,
208 'url': 'http://www.kuwo.cn/mingxing/Ali/music.htm',
213 'playlist_mincount': 95,
214 'skip': 'Regularly stalls travis build', # See https://travis-ci.org/ytdl-org/youtube-dl/jobs/78878540
219 def _real_extract(self
, url
):
220 singer_id
= self
._match
_id
(url
)
221 webpage
= self
._download
_webpage
(
222 url
, singer_id
, note
='Download singer info',
223 errnote
='Unable to get singer info')
225 singer_name
= self
._html
_search
_regex
(
226 r
'<h1>([^<]+)</h1>', webpage
, 'singer name')
228 artist_id
= self
._html
_search
_regex
(
229 r
'data-artistid="(\d+)"', webpage
, 'artist id')
231 page_count
= int(self
._html
_search
_regex
(
232 r
'data-page="(\d+)"', webpage
, 'page count'))
234 def page_func(page_num
):
235 webpage
= self
._download
_webpage
(
236 'http://www.kuwo.cn/artist/contentMusicsAjax',
237 singer_id
, note
='Download song list page #%d' % (page_num
+ 1),
238 errnote
='Unable to get song list page #%d' % (page_num
+ 1),
239 query
={'artistId': artist_id, 'pn': page_num, 'rn': self.PAGE_SIZE}
)
242 self
.url_result(compat_urlparse
.urljoin(url
, song_url
), 'Kuwo')
243 for song_url
in re
.findall(
244 r
'<div[^>]+class="name"><a[^>]+href="(/yinyue/\d+)',
248 entries
= InAdvancePagedList(page_func
, page_count
, self
.PAGE_SIZE
)
250 return self
.playlist_result(entries
, singer_id
, singer_name
)
253 class KuwoCategoryIE(InfoExtractor
):
254 IE_NAME
= 'kuwo:category'
255 IE_DESC
= '酷我音乐 - 分类'
256 _VALID_URL
= r
'https?://yinyue\.kuwo\.cn/yy/cinfo_(?P<id>\d+?).htm'
258 'url': 'http://yinyue.kuwo.cn/yy/cinfo_86375.htm',
262 'description': '这些都是属于八十年代的回忆!',
264 'playlist_mincount': 24,
267 def _real_extract(self
, url
):
268 category_id
= self
._match
_id
(url
)
269 webpage
= self
._download
_webpage
(
270 url
, category_id
, note
='Download category info',
271 errnote
='Unable to get category info')
273 category_name
= self
._html
_search
_regex
(
274 r
'<h1[^>]+title="([^<>]+?)">[^<>]+?</h1>', webpage
, 'category name')
276 category_desc
= remove_start(
277 get_element_by_id('intro', webpage
).strip(),
278 '%s简介:' % category_name
)
279 if category_desc
== '暂无':
282 jsonm
= self
._parse
_json
(self
._html
_search
_regex
(
283 r
'var\s+jsonm\s*=\s*([^;]+);', webpage
, 'category songs'), category_id
)
286 self
.url_result('http://www.kuwo.cn/yinyue/%s/' % song
['musicrid'], 'Kuwo')
287 for song
in jsonm
['musiclist']
289 return self
.playlist_result(entries
, category_id
, category_name
, category_desc
)
292 class KuwoMvIE(KuwoBaseIE
):
294 IE_DESC
= '酷我音乐 - MV'
295 _VALID_URL
= r
'https?://(?:www\.)?kuwo\.cn/mv/(?P<id>\d+?)/'
297 'url': 'http://www.kuwo.cn/mv/6480076/',
301 'title': 'My HouseMV',
304 # In this video, music URLs (anti.s) are blocked outside China and
305 # USA, while the MV URL (mvurl) is available globally, so force the MV
306 # URL for consistent results in different countries
311 _FORMATS
= KuwoBaseIE
._FORMATS
+ [
312 {'format': 'mkv', 'ext': 'mkv', 'preference': 250}
,
313 {'format': 'mp4', 'ext': 'mp4', 'preference': 200}
,
316 def _real_extract(self
, url
):
317 song_id
= self
._match
_id
(url
)
318 webpage
= self
._download
_webpage
(
319 url
, song_id
, note
='Download mv detail info: %s' % song_id
,
320 errnote
='Unable to get mv detail info: %s' % song_id
)
323 r
'<h1[^>]+title="(?P<song>[^"]+)">[^<]+<span[^>]+title="(?P<singer>[^"]+)"',
326 song_name
= mobj
.group('song')
327 singer_name
= mobj
.group('singer')
329 raise ExtractorError('Unable to find song or singer names')
331 formats
= self
._get
_formats
(song_id
, tolerate_ip_deny
=True)
333 mv_url
= self
._download
_webpage
(
334 'http://www.kuwo.cn/yy/st/mvurl?rid=MUSIC_%s' % song_id
,
335 song_id
, note
='Download %s MV URL' % song_id
)
344 'creator': singer_name
,