[qqmusic] Fix tests and cleanup

This commit is contained in:
Yen Chi Hsuan 2017-08-17 16:39:57 +08:00
parent d22b67f356
commit 25a6e769a1

View file

@ -7,11 +7,10 @@
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
sanitized_Request,
strip_jsonp,
unescapeHTML,
clean_html, clean_html,
ExtractorError, ExtractorError,
strip_jsonp,
unescapeHTML,
) )
@ -21,14 +20,14 @@ class QQMusicIE(InfoExtractor):
_VALID_URL = r'https?://y\.qq\.com/n/yqq/song/(?P<id>[0-9A-Za-z]+)\.html' _VALID_URL = r'https?://y\.qq\.com/n/yqq/song/(?P<id>[0-9A-Za-z]+)\.html'
_TESTS = [{ _TESTS = [{
'url': 'https://y.qq.com/n/yqq/song/004295Et37taLD.html', 'url': 'https://y.qq.com/n/yqq/song/004295Et37taLD.html',
'md5': '9ce1c1c8445f561506d2e3cfb0255705', 'md5': '5f1e6cea39e182857da7ffc5ef5e6bb8',
'info_dict': { 'info_dict': {
'id': '004295Et37taLD', 'id': '004295Et37taLD',
'ext': 'mp3', 'ext': 'mp3',
'title': '可惜没如果', 'title': '可惜没如果',
'release_date': '20141227', 'release_date': '20141227',
'creator': '林俊杰', 'creator': '林俊杰',
'description': 'md5:d327722d0361576fde558f1ac68a7065', 'description': 'md5:d85afb3051952ecc50a1ee8a286d1eac',
'thumbnail': r're:^https?://.*\.jpg$', 'thumbnail': r're:^https?://.*\.jpg$',
} }
}, { }, {
@ -53,7 +52,7 @@ class QQMusicIE(InfoExtractor):
'title': 'Shadows Over Transylvania', 'title': 'Shadows Over Transylvania',
'release_date': '19970225', 'release_date': '19970225',
'creator': 'Dark Funeral', 'creator': 'Dark Funeral',
'description': 'md5:ed14d5bd7ecec19609108052c25b2c11', 'description': 'md5:c9b20210587cbcd6836a1c597bab4525',
'thumbnail': r're:^https?://.*\.jpg$', 'thumbnail': r're:^https?://.*\.jpg$',
}, },
'params': { 'params': {
@ -105,7 +104,7 @@ def _real_extract(self, url):
[r'albummid:\'([0-9a-zA-Z]+)\'', r'"albummid":"([0-9a-zA-Z]+)"'], [r'albummid:\'([0-9a-zA-Z]+)\'', r'"albummid":"([0-9a-zA-Z]+)"'],
detail_info_page, 'album mid', default=None) detail_info_page, 'album mid', default=None)
if albummid: if albummid:
thumbnail_url = "http://i.gtimg.cn/music/photo/mid_album_500/%s/%s/%s.jpg" \ thumbnail_url = 'http://i.gtimg.cn/music/photo/mid_album_500/%s/%s/%s.jpg' \
% (albummid[-2:-1], albummid[-1], albummid) % (albummid[-2:-1], albummid[-1], albummid)
guid = self.m_r_get_ruin() guid = self.m_r_get_ruin()
@ -158,8 +157,19 @@ def qq_static_url(category, mid):
def get_singer_all_songs(self, singmid, num): def get_singer_all_songs(self, singmid, num):
return self._download_webpage( return self._download_webpage(
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' % r'https://c.y.qq.com/v8/fcg-bin/fcg_v8_singer_track_cp.fcg', singmid,
(singmid, num), singmid) query={
'format': 'json',
'inCharset': 'utf8',
'outCharset': 'utf-8',
'platform': 'yqq',
'needNewCode': 0,
'singermid': singmid,
'order': 'listen',
'begin': 0,
'num': num,
'songstatus': 1,
})
def get_entries_from_page(self, singmid): def get_entries_from_page(self, singmid):
entries = [] entries = []
@ -176,7 +186,8 @@ def get_entries_from_page(self, singmid):
for item in json_obj_all_songs['data']['list']: for item in json_obj_all_songs['data']['list']:
if item['musicData'].get('songmid') is not None: if item['musicData'].get('songmid') is not None:
songmid = item['musicData']['songmid'] songmid = item['musicData']['songmid']
entries.append(self.url_result(r'https://y.qq.com/n/yqq/song/%s.html' % songmid, 'QQMusic', songmid)) entries.append(self.url_result(
r'https://y.qq.com/n/yqq/song/%s.html' % songmid, 'QQMusic', songmid))
return entries return entries
@ -192,7 +203,7 @@ class QQMusicSingerIE(QQPlaylistBaseIE):
'title': '林俊杰', 'title': '林俊杰',
'description': 'md5:870ec08f7d8547c29c93010899103751', 'description': 'md5:870ec08f7d8547c29c93010899103751',
}, },
'playlist_count': 12, 'playlist_mincount': 12,
} }
def _real_extract(self, url): def _real_extract(self, url):
@ -200,16 +211,16 @@ def _real_extract(self, url):
entries = self.get_entries_from_page(mid) entries = self.get_entries_from_page(mid)
singer_page = self._download_webpage(url, mid, 'Download singer page') singer_page = self._download_webpage(url, mid, 'Download singer page')
singer_name = self._html_search_regex(r"singername : '(.*?)'", singer_page, 'singer name', default=None) singer_name = self._html_search_regex(
r"singername\s*:\s*'(.*?)'", singer_page, 'singer name', default=None)
singer_desc = None singer_desc = None
if mid: if mid:
req = sanitized_Request(
'http://s.plcloud.music.qq.com/fcgi-bin/fcg_get_singer_desc.fcg?utf8=1&outCharset=utf-8&format=xml&singermid=%s' % mid)
req.add_header(
'Referer', 'https://y.qq.com/n/yqq/singer/')
singer_desc_page = self._download_xml( singer_desc_page = self._download_xml(
req, mid, 'Donwload singer description XML') 'http://s.plcloud.music.qq.com/fcgi-bin/fcg_get_singer_desc.fcg', mid,
'Donwload singer description XML',
query={'utf8': 1, 'outCharset': 'utf-8', 'format': 'xml', 'singermid': mid},
headers={'Referer': 'https://y.qq.com/n/yqq/singer/'})
singer_desc = singer_desc_page.find('./data/info/desc').text singer_desc = singer_desc_page.find('./data/info/desc').text
@ -267,26 +278,25 @@ class QQMusicToplistIE(QQPlaylistBaseIE):
_TESTS = [{ _TESTS = [{
'url': 'https://y.qq.com/n/yqq/toplist/123.html', 'url': 'https://y.qq.com/n/yqq/toplist/123.html',
'info_dict': { 'info_dict': {
'id': 'global_123', 'id': '123',
'title': '美国iTunes榜', 'title': '美国iTunes榜',
'description': 'md5:89db2335fdbb10678dee2d43fe9aba08',
}, },
'playlist_count': 10, 'playlist_count': 100,
}, { }, {
'url': 'https://y.qq.com/n/yqq/toplist/3.html', 'url': 'https://y.qq.com/n/yqq/toplist/3.html',
'info_dict': { 'info_dict': {
'id': 'top_3', 'id': '3',
'title': '巅峰榜·欧美', 'title': '巅峰榜·欧美',
'description': 'QQ音乐巅峰榜·欧美根据用户收听行为自动生成集结当下最流行的欧美新歌:更新时间每周四22点|统' 'description': 'md5:5a600d42c01696b26b71f8c4d43407da',
'计周期:一周(上周四至本周三)|统计对象:三个月内发行的欧美歌曲|统计数量100首|统计算法:根据'
'歌曲在一周内的有效播放次数由高到低取前100名同一歌手最多允许5首歌曲同时上榜|有效播放次数:'
'登录用户完整播放一首歌曲记为一次有效播放同一用户收听同一首歌曲每天记录为1次有效播放'
}, },
'playlist_count': 100, 'playlist_count': 100,
}, { }, {
'url': 'https://y.qq.com/n/yqq/toplist/106.html', 'url': 'https://y.qq.com/n/yqq/toplist/106.html',
'info_dict': { 'info_dict': {
'id': 'global_106', 'id': '106',
'title': '韩国Mnet榜', 'title': '韩国Mnet榜',
'description': 'md5:cb84b325215e1d21708c615cac82a6e7',
}, },
'playlist_count': 50, 'playlist_count': 50,
}] }]
@ -298,16 +308,14 @@ def _real_extract(self, url):
num_id = list_id num_id = list_id
toplist_json = self._download_json( toplist_json = self._download_json(
'http://i.y.qq.com/v8/fcg-bin/fcg_v8_toplist_cp.fcg?type=%s&topid=%s&format=json' 'http://i.y.qq.com/v8/fcg-bin/fcg_v8_toplist_cp.fcg', list_id,
% (list_type, num_id), note='Download toplist page',
list_id, 'Download toplist page') query={'type': 'toplist', 'topid': list_id, 'format': 'json'})
entries = [ entries = [self.url_result(
self.url_result(
'https://y.qq.com/n/yqq/song/' + song['data']['songmid'] + '.html', 'QQMusic', 'https://y.qq.com/n/yqq/song/' + song['data']['songmid'] + '.html', 'QQMusic',
song['data']['songmid'] song['data']['songmid'])
) for song in toplist_json['songlist'] for song in toplist_json['songlist']]
]
topinfo = toplist_json.get('topinfo', {}) topinfo = toplist_json.get('topinfo', {})
list_name = topinfo.get('ListName') list_name = topinfo.get('ListName')
@ -343,8 +351,9 @@ def _real_extract(self, url):
list_id = self._match_id(url) list_id = self._match_id(url)
list_json = self._download_json( list_json = self._download_json(
'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' 'http://i.y.qq.com/qzone-music/fcg-bin/fcg_ucc_getcdinfo_byids_cp.fcg',
% list_id, list_id, 'Download list page', list_id, 'Download list page',
query={'type': 1, 'json': 1, 'utf8': 1, 'onlysong': 0, 'disstid': list_id},
transform_source=strip_jsonp) transform_source=strip_jsonp)
if not len(list_json.get('cdlist', [])): if not len(list_json.get('cdlist', [])):
if list_json.get('code'): if list_json.get('code'):
@ -354,11 +363,9 @@ def _real_extract(self, url):
raise ExtractorError('Unable to get playlist info') raise ExtractorError('Unable to get playlist info')
cdlist = list_json['cdlist'][0] cdlist = list_json['cdlist'][0]
entries = [ entries = [self.url_result(
self.url_result( 'https://y.qq.com/n/yqq/song/' + song['songmid'] + '.html', 'QQMusic', song['songmid'])
'https://y.qq.com/n/yqq/song/' + song['songmid'] + '.html', 'QQMusic', song['songmid'] for song in cdlist['songlist']]
) for song in cdlist['songlist']
]
list_name = cdlist.get('dissname') list_name = cdlist.get('dissname')
list_description = clean_html(unescapeHTML(cdlist.get('desc'))) list_description = clean_html(unescapeHTML(cdlist.get('desc')))