2 from __future__
import unicode_literals
8 from .common
import InfoExtractor
14 from ..compat
import compat_urllib_request
17 class QQMusicIE(InfoExtractor
):
19 _VALID_URL
= r
'http://y.qq.com/#type=song&mid=(?P<id>[0-9A-Za-z]+)'
21 'url': 'http://y.qq.com/#type=song&mid=004295Et37taLD',
22 'md5': '9ce1c1c8445f561506d2e3cfb0255705',
24 'id': '004295Et37taLD',
27 'upload_date': '20141227',
29 'description': 'md5:d327722d0361576fde558f1ac68a7065',
30 'thumbnail': 're:^https?://.*\.jpg$',
33 'note': 'There is no mp3-320 version of this song.',
34 'url': 'http://y.qq.com/#type=song&mid=004MsGEo3DdNxV',
35 'md5': 'fa3926f0c585cda0af8fa4f796482e3e',
37 'id': '004MsGEo3DdNxV',
40 'upload_date': '20050626',
42 'description': 'md5:46857d5ed62bc4ba84607a805dccf437',
43 'thumbnail': 're:^https?://.*\.jpg$',
48 'mp3-320': {'prefix': 'M800', 'ext': 'mp3', 'preference': 40, 'abr': 320}
,
49 'mp3-128': {'prefix': 'M500', 'ext': 'mp3', 'preference': 30, 'abr': 128}
,
50 'm4a': {'prefix': 'C200', 'ext': 'm4a', 'preference': 10}
53 # Reference: m_r_GetRUin() in top_player.js
54 # http://imgcache.gtimg.cn/music/portal_v3/y/top_player.js
57 curMs
= int(time
.time() * 1000) % 1000
58 return int(round(random
.random() * 2147483647) * curMs
% 1E10
)
60 def _real_extract(self
, url
):
61 mid
= self
._match
_id
(url
)
63 detail_info_page
= self
._download
_webpage
(
64 'http://s.plcloud.music.qq.com/fcgi-bin/fcg_yqq_song_detail_info.fcg?songmid=%s&play=0' % mid
,
65 mid
, note
='Download song detail info',
66 errnote
='Unable to get song detail info', encoding
='gbk')
68 song_name
= self
._html
_search
_regex
(
69 r
"songname:\s*'([^']+)'", detail_info_page
, 'song name')
71 publish_time
= self
._html
_search
_regex
(
72 r
'发行时间:(\d{4}-\d{2}-\d{2})', detail_info_page
,
73 'publish time', default
=None)
75 publish_time
= publish_time
.replace('-', '')
77 singer
= self
._html
_search
_regex
(
78 r
"singer:\s*'([^']+)", detail_info_page
, 'singer', default
=None)
80 lrc_content
= self
._html
_search
_regex
(
81 r
'<div class="content" id="lrc_content"[^<>]*>([^<>]+)</div>',
82 detail_info_page
, 'LRC lyrics', default
=None)
84 lrc_content
= lrc_content
.replace('\\n', '\n')
87 albummid
= self
._search
_regex
(
88 [r
'albummid:\'([0-9a
-zA
-Z
]+)\'', r'"albummid":"([0-9a-zA-Z]+)"'],
89 detail_info_page, 'album mid
', default=None)
91 thumbnail_url = "http://i.gtimg.cn/music/photo/mid_album_500/%s/%s/%s.jpg" \
92 % (albummid[-2:-1], albummid[-1], albummid)
94 guid = self.m_r_get_ruin()
96 vkey = self._download_json(
97 'http
://base
.music
.qq
.com
/fcgi
-bin
/fcg_musicexpress
.fcg?json
=3&guid
=%s' % guid,
98 mid, note='Retrieve vkey
', errnote='Unable to get vkey
',
99 transform_source=strip_jsonp)['key
']
102 for format_id, details in self._FORMATS.items():
104 'url
': 'http
://cc
.stream
.qqmusic
.qq
.com
/%s%s.%s?vkey
=%s&guid
=%s&fromtag
=0'
105 % (details['prefix
'], mid, details['ext
'], vkey, guid),
107 'format_id
': format_id,
108 'preference
': details['preference
'],
109 'abr
': details.get('abr
'),
111 self._check_formats(formats, mid)
112 self._sort_formats(formats)
118 'upload_date
': publish_time,
120 'description
': lrc_content,
121 'thumbnail
': thumbnail_url,
125 class QQPlaylistBaseIE(InfoExtractor):
127 def qq_static_url(category, mid):
128 return 'http
://y
.qq
.com
/y
/static
/%s/%s/%s/%s.html
' % (category, mid[-2], mid[-1], mid)
131 def get_entries_from_page(cls, page):
134 for item in re.findall(r'class="data"[^
<>]*>([^
<>]+)</', page):
135 song_mid = unescapeHTML(item).split('|
')[-5]
136 entries.append(cls.url_result(
137 'http
://y
.qq
.com
/#type=song&mid=' + song_mid, 'QQMusic',
143 class QQMusicSingerIE(QQPlaylistBaseIE
):
144 IE_NAME
= 'qqmusic:singer'
145 _VALID_URL
= r
'http://y.qq.com/#type=singer&mid=(?P<id>[0-9A-Za-z]+)'
147 'url': 'http://y.qq.com/#type=singer&mid=001BLpXF2DyJe2',
149 'id': '001BLpXF2DyJe2',
151 'description': 'md5:2a222d89ba4455a3af19940c0481bb78',
153 'playlist_count': 12,
156 def _real_extract(self
, url
):
157 mid
= self
._match
_id
(url
)
159 singer_page
= self
._download
_webpage
(
160 self
.qq_static_url('singer', mid
), mid
, 'Download singer page')
162 entries
= self
.get_entries_from_page(singer_page
)
164 singer_name
= self
._html
_search
_regex
(
165 r
"singername\s*:\s*'([^']+)'", singer_page
, 'singer name',
168 singer_id
= self
._html
_search
_regex
(
169 r
"singerid\s*:\s*'([0-9]+)'", singer_page
, 'singer id',
175 req
= compat_urllib_request
.Request(
176 'http://s.plcloud.music.qq.com/fcgi-bin/fcg_get_singer_desc.fcg?utf8=1&outCharset=utf-8&format=xml&singerid=%s' % singer_id
)
178 'Referer', 'http://s.plcloud.music.qq.com/xhr_proxy_utf8.html')
179 singer_desc_page
= self
._download
_xml
(
180 req
, mid
, 'Donwload singer description XML')
182 singer_desc
= singer_desc_page
.find('./data/info/desc').text
184 return self
.playlist_result(entries
, mid
, singer_name
, singer_desc
)
187 class QQMusicAlbumIE(QQPlaylistBaseIE
):
188 IE_NAME
= 'qqmusic:album'
189 _VALID_URL
= r
'http://y.qq.com/#type=album&mid=(?P<id>[0-9A-Za-z]+)'
192 'url': 'http://y.qq.com/#type=album&mid=000gXCTb2AhRR1',
194 'id': '000gXCTb2AhRR1',
195 'title': '我们都是这样长大的',
196 'description': 'md5:179c5dce203a5931970d306aa9607ea6',
200 'url': 'http://y.qq.com/#type=album&mid=002Y5a3b3AlCu3',
202 'id': '002Y5a3b3AlCu3',
204 'description': 'md5:a48823755615508a95080e81b51ba729',
209 def _real_extract(self
, url
):
210 mid
= self
._match
_id
(url
)
212 album
= self
._download
_json
(
213 'http://i.y.qq.com/v8/fcg-bin/fcg_v8_album_info_cp.fcg?albummid=%s&format=json' % mid
,
214 mid
, 'Download album page')['data']
218 'http://y.qq.com/#type=song&mid=' + song
['songmid'], 'QQMusic', song
['songmid']
219 ) for song
in album
['list']
221 album_name
= album
.get('name')
222 album_detail
= album
.get('desc')
223 if album_detail
is not None:
224 album_detail
= album_detail
.strip()
226 return self
.playlist_result(entries
, mid
, album_name
, album_detail
)
229 class QQMusicToplistIE(QQPlaylistBaseIE
):
230 IE_NAME
= 'qqmusic:toplist'
231 _VALID_URL
= r
'http://y\.qq\.com/#type=toplist&p=(?P<id>(top|global)_[0-9]+)'
234 'url': 'http://y.qq.com/#type=toplist&p=global_123',
237 'title': '美国iTunes榜',
239 'playlist_count': 10,
241 'url': 'http://y.qq.com/#type=toplist&p=top_3',
244 'title': 'QQ音乐巅峰榜·欧美',
245 'description': 'QQ音乐巅峰榜·欧美根据用户收听行为自动生成,集结当下最流行的欧美新歌!:更新时间:每周四22点|统'
246 '计周期:一周(上周四至本周三)|统计对象:三个月内发行的欧美歌曲|统计数量:100首|统计算法:根据'
247 '歌曲在一周内的有效播放次数,由高到低取前100名(同一歌手最多允许5首歌曲同时上榜)|有效播放次数:'
248 '登录用户完整播放一首歌曲,记为一次有效播放;同一用户收听同一首歌曲,每天记录为1次有效播放'
250 'playlist_count': 100,
252 'url': 'http://y.qq.com/#type=toplist&p=global_106',
257 'playlist_count': 50,
260 def _real_extract(self
, url
):
261 list_id
= self
._match
_id
(url
)
263 list_type
, num_id
= list_id
.split("_")
265 toplist_json
= self
._download
_json
(
266 'http://i.y.qq.com/v8/fcg-bin/fcg_v8_toplist_cp.fcg?type=%s&topid=%s&format=json'
267 % (list_type
, num_id
),
268 list_id
, 'Download toplist page')
272 'http://y.qq.com/#type=song&mid=' + song
['data']['songmid'], 'QQMusic', song
['data']['songmid']
273 ) for song
in toplist_json
['songlist']
276 topinfo
= toplist_json
.get('topinfo', {})
277 list_name
= topinfo
.get('ListName')
278 list_description
= topinfo
.get('info')
279 return self
.playlist_result(entries
, list_id
, list_name
, list_description
)
282 class QQMusicPlaylistIE(QQPlaylistBaseIE
):
283 IE_NAME
= 'qqmusic:playlist'
284 _VALID_URL
= r
'http://y\.qq\.com/#type=taoge&id=(?P<id>[0-9]+)'
287 'url': 'http://y.qq.com/#type=taoge&id=3462654915',
290 'title': '韩国5月新歌精选下旬',
291 'description': 'md5:d2c9d758a96b9888cf4fe82f603121d4',
293 'playlist_count': 40,
296 def _real_extract(self
, url
):
297 list_id
= self
._match
_id
(url
)
299 list_json
= self
._download
_json
(
300 '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'
301 % list_id
, list_id
, 'Download list page',
302 transform_source
=strip_jsonp
)['cdlist'][0]
306 'http://y.qq.com/#type=song&mid=' + song
['songmid'], 'QQMusic', song
['songmid']
307 ) for song
in list_json
['songlist']
310 list_name
= list_json
.get('dissname')
311 list_description
= clean_html(unescapeHTML(list_json
.get('desc')))
312 return self
.playlist_result(entries
, list_id
, list_name
, list_description
)