2 from __future__
import unicode_literals
8 from .common
import InfoExtractor
18 class QQMusicIE(InfoExtractor
):
21 _VALID_URL
= r
'https?://y\.qq\.com/n/yqq/song/(?P<id>[0-9A-Za-z]+)\.html'
23 'url': 'https://y.qq.com/n/yqq/song/004295Et37taLD.html',
24 'md5': '9ce1c1c8445f561506d2e3cfb0255705',
26 'id': '004295Et37taLD',
29 'release_date': '20141227',
31 'description': 'md5:d327722d0361576fde558f1ac68a7065',
32 'thumbnail': r
're:^https?://.*\.jpg$',
35 'note': 'There is no mp3-320 version of this song.',
36 'url': 'https://y.qq.com/n/yqq/song/004MsGEo3DdNxV.html',
37 'md5': 'fa3926f0c585cda0af8fa4f796482e3e',
39 'id': '004MsGEo3DdNxV',
42 'release_date': '20050626',
44 'description': 'md5:46857d5ed62bc4ba84607a805dccf437',
45 'thumbnail': r
're:^https?://.*\.jpg$',
48 'note': 'lyrics not in .lrc format',
49 'url': 'https://y.qq.com/n/yqq/song/001JyApY11tIp6.html',
51 'id': '001JyApY11tIp6',
53 'title': 'Shadows Over Transylvania',
54 'release_date': '19970225',
55 'creator': 'Dark Funeral',
56 'description': 'md5:ed14d5bd7ecec19609108052c25b2c11',
57 'thumbnail': r
're:^https?://.*\.jpg$',
60 'skip_download': True,
65 'mp3-320': {'prefix': 'M800', 'ext': 'mp3', 'preference': 40, 'abr': 320}
,
66 'mp3-128': {'prefix': 'M500', 'ext': 'mp3', 'preference': 30, 'abr': 128}
,
67 'm4a': {'prefix': 'C200', 'ext': 'm4a', 'preference': 10}
70 # Reference: m_r_GetRUin() in top_player.js
71 # http://imgcache.gtimg.cn/music/portal_v3/y/top_player.js
74 curMs
= int(time
.time() * 1000) % 1000
75 return int(round(random
.random() * 2147483647) * curMs
% 1E10
)
77 def _real_extract(self
, url
):
78 mid
= self
._match
_id
(url
)
80 detail_info_page
= self
._download
_webpage
(
81 'http://s.plcloud.music.qq.com/fcgi-bin/fcg_yqq_song_detail_info.fcg?songmid=%s&play=0' % mid
,
82 mid
, note
='Download song detail info',
83 errnote
='Unable to get song detail info', encoding
='gbk')
85 song_name
= self
._html
_search
_regex
(
86 r
"songname:\s*'([^']+)'", detail_info_page
, 'song name')
88 publish_time
= self
._html
_search
_regex
(
89 r
'发行时间:(\d{4}-\d{2}-\d{2})', detail_info_page
,
90 'publish time', default
=None)
92 publish_time
= publish_time
.replace('-', '')
94 singer
= self
._html
_search
_regex
(
95 r
"singer:\s*'([^']+)", detail_info_page
, 'singer', default
=None)
97 lrc_content
= self
._html
_search
_regex
(
98 r
'<div class="content" id="lrc_content"[^<>]*>([^<>]+)</div>',
99 detail_info_page
, 'LRC lyrics', default
=None)
101 lrc_content
= lrc_content
.replace('\\n', '\n')
104 albummid
= self
._search
_regex
(
105 [r
'albummid:\'([0-9a
-zA
-Z
]+)\'', r'"albummid":"([0-9a-zA-Z]+)"'],
106 detail_info_page, 'album mid
', default=None)
108 thumbnail_url = "http://i.gtimg.cn/music/photo/mid_album_500/%s/%s/%s.jpg" \
109 % (albummid[-2:-1], albummid[-1], albummid)
111 guid = self.m_r_get_ruin()
113 vkey = self._download_json(
114 'http
://base
.music
.qq
.com
/fcgi
-bin
/fcg_musicexpress
.fcg?json
=3&guid
=%s' % guid,
115 mid, note='Retrieve vkey
', errnote='Unable to get vkey
',
116 transform_source=strip_jsonp)['key
']
119 for format_id, details in self._FORMATS.items():
121 'url
': 'http
://cc
.stream
.qqmusic
.qq
.com
/%s%s.%s?vkey
=%s&guid
=%s&fromtag
=0'
122 % (details['prefix
'], mid, details['ext
'], vkey, guid),
124 'format_id
': format_id,
125 'preference
': details['preference
'],
126 'abr
': details.get('abr
'),
128 self._check_formats(formats, mid)
129 self._sort_formats(formats)
131 actual_lrc_lyrics = ''.join(
132 line + '\n' for line in re.findall(
133 r'(?m
)^
(\
[[0-9]{2}
:[0-9]{2}
(?
:\
.[0-9]{2,}
)?\
][^
\n]*|\
[[^\
]]*\
])', lrc_content))
139 'release_date
': publish_time,
141 'description
': lrc_content,
142 'thumbnail
': thumbnail_url
144 if actual_lrc_lyrics:
145 info_dict['subtitles
'] = {
148 'data
': actual_lrc_lyrics,
154 class QQPlaylistBaseIE(InfoExtractor):
156 def qq_static_url(category, mid):
157 return 'http
://y
.qq
.com
/y
/static
/%s/%s/%s/%s.html
' % (category, mid[-2], mid[-1], mid)
159 def get_singer_all_songs(self, singmid, num):
160 return self._download_webpage(
161 r'https
://c
.y
.qq
.com
/v8
/fcg
-bin
/fcg_v8_singer_track_cp
.fcg?format
=json
&inCharset
=utf8
&outCharset
=utf
-8&platform
=yqq
&needNewCode
=0&singermid
=%s&order
=listen
&begin
=0&num
=%s&songstatus
=1' %
162 (singmid, num), singmid)
164 def get_entries_from_page(self, singmid):
168 json_text = self.get_singer_all_songs(singmid, default_num)
169 json_obj_all_songs = self._parse_json(json_text, singmid)
171 if json_obj_all_songs['code
'] == 0:
172 total = json_obj_all_songs['data
']['total
']
173 json_text = self.get_singer_all_songs(singmid, total)
174 json_obj_all_songs = self._parse_json(json_text, singmid)
176 for item in json_obj_all_songs['data
']['list']:
177 if item['musicData
'].get('songmid
') is not None:
178 songmid = item['musicData
']['songmid
']
179 entries.append(self.url_result(r'https
://y
.qq
.com
/n
/yqq
/song
/%s.html
' % songmid, 'QQMusic
', songmid))
184 class QQMusicSingerIE(QQPlaylistBaseIE):
185 IE_NAME = 'qqmusic
:singer
'
186 IE_DESC = 'QQ音乐
- 歌手
'
187 _VALID_URL = r'https?
://y\
.qq\
.com
/n
/yqq
/singer
/(?P
<id>[0-9A
-Za
-z
]+)\
.html
'
189 'url
': 'https
://y
.qq
.com
/n
/yqq
/singer
/001BLpXF2DyJe2
.html
',
191 'id': '001BLpXF2DyJe2
',
193 'description
': 'md5
:870ec08f7d8547c29c93010899103751
',
195 'playlist_count
': 12,
198 def _real_extract(self, url):
199 mid = self._match_id(url)
201 entries = self.get_entries_from_page(mid)
202 singer_page = self._download_webpage(url, mid, 'Download singer page
')
203 singer_name = self._html_search_regex(r"singername : '(.*?
)'", singer_page, 'singer name
', default=None)
207 req = sanitized_Request(
208 'http
://s
.plcloud
.music
.qq
.com
/fcgi
-bin
/fcg_get_singer_desc
.fcg?utf8
=1&outCharset
=utf
-8&format
=xml
&singermid
=%s' % mid)
210 'Referer
', 'https
://y
.qq
.com
/n
/yqq
/singer
/')
211 singer_desc_page = self._download_xml(
212 req, mid, 'Donwload singer description XML
')
214 singer_desc = singer_desc_page.find('./data
/info
/desc
').text
216 return self.playlist_result(entries, mid, singer_name, singer_desc)
219 class QQMusicAlbumIE(QQPlaylistBaseIE):
220 IE_NAME = 'qqmusic
:album
'
221 IE_DESC = 'QQ音乐
- 专辑
'
222 _VALID_URL = r'https?
://y\
.qq\
.com
/n
/yqq
/album
/(?P
<id>[0-9A
-Za
-z
]+)\
.html
'
225 'url
': 'https
://y
.qq
.com
/n
/yqq
/album
/000gXCTb2AhRR1
.html
',
227 'id': '000gXCTb2AhRR1
',
228 'title
': '我们都是这样长大的
',
229 'description
': 'md5
:179c5dce203a5931970d306aa9607ea6
',
233 'url
': 'https
://y
.qq
.com
/n
/yqq
/album
/002Y5a3b3AlCu3
.html
',
235 'id': '002Y5a3b3AlCu3
',
237 'description
': 'md5
:a48823755615508a95080e81b51ba729
',
242 def _real_extract(self, url):
243 mid = self._match_id(url)
245 album = self._download_json(
246 'http
://i
.y
.qq
.com
/v8
/fcg
-bin
/fcg_v8_album_info_cp
.fcg?albummid
=%s&format
=json
' % mid,
247 mid, 'Download album page
')['data
']
251 'https
://y
.qq
.com
/n
/yqq
/song
/' + song['songmid
'] + '.html
', 'QQMusic
', song['songmid
']
252 ) for song in album['list']
254 album_name = album.get('name
')
255 album_detail = album.get('desc
')
256 if album_detail is not None:
257 album_detail = album_detail.strip()
259 return self.playlist_result(entries, mid, album_name, album_detail)
262 class QQMusicToplistIE(QQPlaylistBaseIE):
263 IE_NAME = 'qqmusic
:toplist
'
264 IE_DESC = 'QQ音乐
- 排行榜
'
265 _VALID_URL = r'https?
://y\
.qq\
.com
/n
/yqq
/toplist
/(?P
<id>[0-9]+)\
.html
'
268 'url
': 'https
://y
.qq
.com
/n
/yqq
/toplist
/123.html
',
271 'title
': '美国iTunes榜
',
273 'playlist_count
': 10,
275 'url
': 'https
://y
.qq
.com
/n
/yqq
/toplist
/3.html
',
279 'description
': 'QQ音乐巅峰榜·欧美根据用户收听行为自动生成,集结当下最流行的欧美新歌!
:更新时间:每周四
22点|统
'
280 '计周期:一周(上周四至本周三)|统计对象:三个月内发行的欧美歌曲|统计数量:
100首|统计算法:根据
'
281 '歌曲在一周内的有效播放次数,由高到低取前
100名(同一歌手最多允许
5首歌曲同时上榜)|有效播放次数:
'
282 '登录用户完整播放一首歌曲,记为一次有效播放;同一用户收听同一首歌曲,每天记录为
1次有效播放
'
284 'playlist_count
': 100,
286 'url
': 'https
://y
.qq
.com
/n
/yqq
/toplist
/106.html
',
291 'playlist_count
': 50,
294 def _real_extract(self, url):
295 list_id = self._match_id(url)
297 list_type = 'toplist
'
300 toplist_json = self._download_json(
301 'http
://i
.y
.qq
.com
/v8
/fcg
-bin
/fcg_v8_toplist_cp
.fcg?
type=%s&topid
=%s&format
=json
'
302 % (list_type, num_id),
303 list_id, 'Download toplist page
')
307 'https
://y
.qq
.com
/n
/yqq
/song
/' + song['data
']['songmid
'] + '.html
', 'QQMusic
',
308 song['data
']['songmid
']
309 ) for song in toplist_json['songlist
']
312 topinfo = toplist_json.get('topinfo
', {})
313 list_name = topinfo.get('ListName
')
314 list_description = topinfo.get('info
')
315 return self.playlist_result(entries, list_id, list_name, list_description)
318 class QQMusicPlaylistIE(QQPlaylistBaseIE):
319 IE_NAME = 'qqmusic
:playlist
'
320 IE_DESC = 'QQ音乐
- 歌单
'
321 _VALID_URL = r'https?
://y\
.qq\
.com
/n
/yqq
/playlist
/(?P
<id>[0-9]+)\
.html
'
324 'url
': 'http
://y
.qq
.com
/n
/yqq
/playlist
/3462654915.html
',
327 'title
': '韩国
5月新歌精选下旬
',
328 'description
': 'md5
:d2c9d758a96b9888cf4fe82f603121d4
',
330 'playlist_count
': 40,
331 'skip
': 'playlist gone
',
333 'url
': 'https
://y
.qq
.com
/n
/yqq
/playlist
/1374105607.html
',
336 'title
': '易入人心的华语民谣
',
337 'description
': '民谣的歌曲易于传唱、、歌词朗朗伤口、旋律简单温馨。属于那种才入耳孔。却上心头的感觉。没有太多的复杂情绪。简单而直接地表达乐者的情绪,就是这样的简单才易入人心。
',
339 'playlist_count
': 20,
342 def _real_extract(self, url):
343 list_id = self._match_id(url)
345 list_json = self._download_json(
346 'http
://i
.y
.qq
.com
/qzone
-music
/fcg
-bin
/fcg_ucc_getcdinfo_byids_cp
.fcg?
type=1&json
=1&utf8
=1&onlysong
=0&disstid
=%s'
347 % list_id, list_id, 'Download
list page
',
348 transform_source=strip_jsonp)
349 if not len(list_json.get('cdlist
', [])):
350 if list_json.get('code
'):
351 raise ExtractorError(
352 'QQ Music said
: error
%d in fetching playlist info
' % list_json['code
'],
354 raise ExtractorError('Unable to get playlist info
')
356 cdlist = list_json['cdlist
'][0]
359 'https
://y
.qq
.com
/n
/yqq
/song
/' + song['songmid
'] + '.html
', 'QQMusic
', song['songmid
']
360 ) for song in cdlist['songlist
']
363 list_name = cdlist.get('dissname
')
364 list_description = clean_html(unescapeHTML(cdlist.get('desc
')))
365 return self.playlist_result(entries, list_id, list_name, list_description)