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
:
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' and not tolerate_ip_deny
:
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'),
47 # XXX _sort_formats fails if there are not formats, while it's not the
48 # desired behavior if 'IPDeny' is ignored
49 # This check can be removed if https://github.com/rg3/youtube-dl/pull/8051 is merged
50 if not tolerate_ip_deny
:
51 self
._sort
_formats
(formats
)
55 class KuwoIE(KuwoBaseIE
):
58 _VALID_URL
= r
'https?://www\.kuwo\.cn/yinyue/(?P<id>\d+?)'
60 'url': 'http://www.kuwo.cn/yinyue/635632/',
66 'upload_date': '20080122',
67 'description': 'md5:ed13f58e3c3bf3f7fd9fbc4e5a7aa75c'
69 'skip': 'this song has been offline because of copyright issues',
71 'url': 'http://www.kuwo.cn/yinyue/6446136/',
76 'description': 'md5:b2ab6295d014005bfc607525bfc1e38a',
78 'upload_date': '20150518',
84 'url': 'http://www.kuwo.cn/yinyue/3197154?catalog=yueku2016',
85 'only_matching': True,
88 def _real_extract(self
, url
):
89 song_id
= self
._match
_id
(url
)
90 webpage
= self
._download
_webpage
(
91 url
, song_id
, note
='Download song detail info',
92 errnote
='Unable to get song detail info')
93 if '对不起,该歌曲由于版权问题已被下线,将返回网站首页' in webpage
:
94 raise ExtractorError('this song has been offline because of copyright issues', expected
=True)
96 song_name
= self
._html
_search
_regex
(
97 r
'(?s)class="(?:[^"\s]+\s+)*title(?:\s+[^"\s]+)*".*?<h1[^>]+title="([^"]+)"', webpage
, 'song name')
98 singer_name
= self
._html
_search
_regex
(
99 r
'<div[^>]+class="s_img">\s*<a[^>]+title="([^>]+)"',
100 webpage
, 'singer name', fatal
=False)
101 lrc_content
= clean_html(get_element_by_id('lrcContent', webpage
))
102 if lrc_content
== '暂无': # indicates no lyrics
105 formats
= self
._get
_formats
(song_id
)
107 album_id
= self
._html
_search
_regex
(
108 r
'<p[^>]+class="album"[^<]+<a[^>]+href="http://www\.kuwo\.cn/album/(\d+)/"',
109 webpage
, 'album id', fatal
=False)
112 if album_id
is not None:
113 album_info_page
= self
._download
_webpage
(
114 'http://www.kuwo.cn/album/%s/' % album_id
, song_id
,
115 note
='Download album detail info',
116 errnote
='Unable to get album detail info')
118 publish_time
= self
._html
_search
_regex
(
119 r
'发行时间:(\d{4}-\d{2}-\d{2})', album_info_page
,
120 'publish time', fatal
=False)
122 publish_time
= publish_time
.replace('-', '')
127 'creator': singer_name
,
128 'upload_date': publish_time
,
129 'description': lrc_content
,
134 class KuwoAlbumIE(InfoExtractor
):
135 IE_NAME
= 'kuwo:album'
136 IE_DESC
= '酷我音乐 - 专辑'
137 _VALID_URL
= r
'https?://www\.kuwo\.cn/album/(?P<id>\d+?)/'
139 'url': 'http://www.kuwo.cn/album/502294/',
143 'description': 'md5:6a7235a84cc6400ec3b38a7bdaf1d60c',
148 def _real_extract(self
, url
):
149 album_id
= self
._match
_id
(url
)
151 webpage
= self
._download
_webpage
(
152 url
, album_id
, note
='Download album info',
153 errnote
='Unable to get album info')
155 album_name
= self
._html
_search
_regex
(
156 r
'<div[^>]+class="comm"[^<]+<h1[^>]+title="([^"]+)"', webpage
,
158 album_intro
= remove_start(
159 clean_html(get_element_by_id('intro', webpage
)),
160 '%s简介:' % album_name
)
163 self
.url_result(song_url
, 'Kuwo') for song_url
in re
.findall(
164 r
'<p[^>]+class="listen"><a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+/)"',
167 return self
.playlist_result(entries
, album_id
, album_name
, album_intro
)
170 class KuwoChartIE(InfoExtractor
):
171 IE_NAME
= 'kuwo:chart'
172 IE_DESC
= '酷我音乐 - 排行榜'
173 _VALID_URL
= r
'https?://yinyue\.kuwo\.cn/billboard_(?P<id>[^.]+).htm'
175 'url': 'http://yinyue.kuwo.cn/billboard_香港中文龙虎榜.htm',
179 'playlist_mincount': 10,
182 def _real_extract(self
, url
):
183 chart_id
= self
._match
_id
(url
)
184 webpage
= self
._download
_webpage
(
185 url
, chart_id
, note
='Download chart info',
186 errnote
='Unable to get chart info')
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
)
195 class KuwoSingerIE(InfoExtractor
):
196 IE_NAME
= 'kuwo:singer'
197 IE_DESC
= '酷我音乐 - 歌手'
198 _VALID_URL
= r
'https?://www\.kuwo\.cn/mingxing/(?P<id>[^/]+)'
200 'url': 'http://www.kuwo.cn/mingxing/bruno+mars/',
203 'title': 'Bruno Mars',
205 'playlist_mincount': 329,
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
218 def _real_extract(self
, url
):
219 singer_id
= self
._match
_id
(url
)
220 webpage
= self
._download
_webpage
(
221 url
, singer_id
, note
='Download singer info',
222 errnote
='Unable to get singer info')
224 singer_name
= self
._html
_search
_regex
(
225 r
'<h1>([^<]+)</h1>', webpage
, 'singer name')
227 artist_id
= self
._html
_search
_regex
(
228 r
'data-artistid="(\d+)"', webpage
, 'artist id')
230 page_count
= int(self
._html
_search
_regex
(
231 r
'data-page="(\d+)"', webpage
, 'page count'))
233 def page_func(page_num
):
234 webpage
= self
._download
_webpage
(
235 'http://www.kuwo.cn/artist/contentMusicsAjax',
236 singer_id
, note
='Download song list page #%d' % (page_num
+ 1),
237 errnote
='Unable to get song list page #%d' % (page_num
+ 1),
238 query
={'artistId': artist_id, 'pn': page_num, 'rn': self.PAGE_SIZE}
)
241 self
.url_result(song_url
, 'Kuwo') for song_url
in re
.findall(
242 r
'<div[^>]+class="name"><a[^>]+href="(http://www\.kuwo\.cn/yinyue/\d+)',
246 entries
= InAdvancePagedList(page_func
, page_count
, self
.PAGE_SIZE
)
248 return self
.playlist_result(entries
, singer_id
, singer_name
)
251 class KuwoCategoryIE(InfoExtractor
):
252 IE_NAME
= 'kuwo:category'
253 IE_DESC
= '酷我音乐 - 分类'
254 _VALID_URL
= r
'https?://yinyue\.kuwo\.cn/yy/cinfo_(?P<id>\d+?).htm'
256 'url': 'http://yinyue.kuwo.cn/yy/cinfo_86375.htm',
260 'description': '这些都是属于八十年代的回忆!',
262 'playlist_count': 30,
265 def _real_extract(self
, url
):
266 category_id
= self
._match
_id
(url
)
267 webpage
= self
._download
_webpage
(
268 url
, category_id
, note
='Download category info',
269 errnote
='Unable to get category info')
271 category_name
= self
._html
_search
_regex
(
272 r
'<h1[^>]+title="([^<>]+?)">[^<>]+?</h1>', webpage
, 'category name')
274 category_desc
= remove_start(
275 get_element_by_id('intro', webpage
).strip(),
276 '%s简介:' % category_name
)
278 jsonm
= self
._parse
_json
(self
._html
_search
_regex
(
279 r
'var\s+jsonm\s*=\s*([^;]+);', webpage
, 'category songs'), category_id
)
282 self
.url_result('http://www.kuwo.cn/yinyue/%s/' % song
['musicrid'], 'Kuwo')
283 for song
in jsonm
['musiclist']
285 return self
.playlist_result(entries
, category_id
, category_name
, category_desc
)
288 class KuwoMvIE(KuwoBaseIE
):
290 IE_DESC
= '酷我音乐 - MV'
291 _VALID_URL
= r
'https?://www\.kuwo\.cn/mv/(?P<id>\d+?)/'
293 'url': 'http://www.kuwo.cn/mv/6480076/',
297 'title': 'My HouseMV',
300 # In this video, music URLs (anti.s) are blocked outside China and
301 # USA, while the MV URL (mvurl) is available globally, so force the MV
302 # URL for consistent results in different countries
307 _FORMATS
= KuwoBaseIE
._FORMATS
+ [
308 {'format': 'mkv', 'ext': 'mkv', 'preference': 250}
,
309 {'format': 'mp4', 'ext': 'mp4', 'preference': 200}
,
312 def _real_extract(self
, url
):
313 song_id
= self
._match
_id
(url
)
314 webpage
= self
._download
_webpage
(
315 url
, song_id
, note
='Download mv detail info: %s' % song_id
,
316 errnote
='Unable to get mv detail info: %s' % song_id
)
319 r
'<h1[^>]+title="(?P<song>[^"]+)">[^<]+<span[^>]+title="(?P<singer>[^"]+)"',
322 song_name
= mobj
.group('song')
323 singer_name
= mobj
.group('singer')
325 raise ExtractorError('Unable to find song or singer names')
327 formats
= self
._get
_formats
(song_id
, tolerate_ip_deny
=True)
329 mv_url
= self
._download
_webpage
(
330 'http://www.kuwo.cn/yy/st/mvurl?rid=MUSIC_%s' % song_id
,
331 song_id
, note
='Download %s MV URL' % song_id
)
337 self
._sort
_formats
(formats
)
342 'creator': singer_name
,