From 55e5841f14131ab61359535fdcc44e1564d555b8 Mon Sep 17 00:00:00 2001 From: ping Date: Thu, 4 Jun 2015 17:41:29 +0800 Subject: [PATCH 1/4] [qqmusic] Extract additional formats (mp3-128, mp3-320) --- youtube_dl/extractor/qqmusic.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/youtube_dl/extractor/qqmusic.py b/youtube_dl/extractor/qqmusic.py index b540033e2..4b4ef4993 100644 --- a/youtube_dl/extractor/qqmusic.py +++ b/youtube_dl/extractor/qqmusic.py @@ -19,10 +19,10 @@ class QQMusicIE(InfoExtractor): _VALID_URL = r'http://y.qq.com/#type=song&mid=(?P[0-9A-Za-z]+)' _TESTS = [{ 'url': 'http://y.qq.com/#type=song&mid=004295Et37taLD', - 'md5': 'bed90b6db2a7a7a7e11bc585f471f63a', + 'md5': '9ce1c1c8445f561506d2e3cfb0255705', 'info_dict': { 'id': '004295Et37taLD', - 'ext': 'm4a', + 'ext': 'mp3', 'title': '可惜没如果', 'upload_date': '20141227', 'creator': '林俊杰', @@ -30,6 +30,12 @@ class QQMusicIE(InfoExtractor): } }] + _FORMATS = { + 'mp3-320': {'prefix': 'M800', 'ext': 'mp3', 'preference': 40}, + 'mp3-128': {'prefix': 'M500', 'ext': 'mp3', 'preference': 30}, + 'm4a': {'prefix': 'C200', 'ext': 'm4a', 'preference': 10} + } + # Reference: m_r_GetRUin() in top_player.js # http://imgcache.gtimg.cn/music/portal_v3/y/top_player.js @staticmethod @@ -69,11 +75,19 @@ class QQMusicIE(InfoExtractor): 'http://base.music.qq.com/fcgi-bin/fcg_musicexpress.fcg?json=3&guid=%s' % guid, mid, note='Retrieve vkey', errnote='Unable to get vkey', transform_source=strip_jsonp)['key'] - song_url = 'http://cc.stream.qqmusic.qq.com/C200%s.m4a?vkey=%s&guid=%s&fromtag=0' % (mid, vkey, guid) + + formats = [] + for k, sf in self._FORMATS.items(): + formats.append({ + 'url': 'http://cc.stream.qqmusic.qq.com/%s%s.%s?vkey=%s&guid=%s&fromtag=0' + % (sf['prefix'], mid, sf['ext'], vkey, guid), + 'format': k, 'format_id': k, 'preference': sf['preference'] + }) + self._sort_formats(formats) return { 'id': mid, - 'url': song_url, + 'formats': formats, 'title': song_name, 'upload_date': publish_time, 'creator': singer, From 8b8cde21406b53f5aeb6586dab03a9d78d62e631 Mon Sep 17 00:00:00 2001 From: ping Date: Fri, 5 Jun 2015 06:04:26 +0800 Subject: [PATCH 2/4] [qqmusic] Set abr for mp3 formats --- youtube_dl/extractor/qqmusic.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/youtube_dl/extractor/qqmusic.py b/youtube_dl/extractor/qqmusic.py index 4b4ef4993..dc300e189 100644 --- a/youtube_dl/extractor/qqmusic.py +++ b/youtube_dl/extractor/qqmusic.py @@ -31,8 +31,8 @@ class QQMusicIE(InfoExtractor): }] _FORMATS = { - 'mp3-320': {'prefix': 'M800', 'ext': 'mp3', 'preference': 40}, - 'mp3-128': {'prefix': 'M500', 'ext': 'mp3', 'preference': 30}, + 'mp3-320': {'prefix': 'M800', 'ext': 'mp3', 'preference': 40, 'abr': 320}, + 'mp3-128': {'prefix': 'M500', 'ext': 'mp3', 'preference': 30, 'abr': 128}, 'm4a': {'prefix': 'C200', 'ext': 'm4a', 'preference': 10} } @@ -77,11 +77,12 @@ class QQMusicIE(InfoExtractor): transform_source=strip_jsonp)['key'] formats = [] - for k, sf in self._FORMATS.items(): + for k, f in self._FORMATS.items(): formats.append({ 'url': 'http://cc.stream.qqmusic.qq.com/%s%s.%s?vkey=%s&guid=%s&fromtag=0' - % (sf['prefix'], mid, sf['ext'], vkey, guid), - 'format': k, 'format_id': k, 'preference': sf['preference'] + % (f['prefix'], mid, f['ext'], vkey, guid), + 'format': k, 'format_id': k, 'preference': f['preference'], + 'abr': f.get('abr') }) self._sort_formats(formats) From f00a650705a5e5b4f2b540ea8133a1752e63dd81 Mon Sep 17 00:00:00 2001 From: Yen Chi Hsuan Date: Fri, 5 Jun 2015 23:16:34 +0800 Subject: [PATCH 3/4] [qqmusic] Rearrange codes --- youtube_dl/extractor/qqmusic.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/youtube_dl/extractor/qqmusic.py b/youtube_dl/extractor/qqmusic.py index e24ddaefe..c903bee58 100644 --- a/youtube_dl/extractor/qqmusic.py +++ b/youtube_dl/extractor/qqmusic.py @@ -80,7 +80,9 @@ class QQMusicIE(InfoExtractor): formats.append({ 'url': 'http://cc.stream.qqmusic.qq.com/%s%s.%s?vkey=%s&guid=%s&fromtag=0' % (f['prefix'], mid, f['ext'], vkey, guid), - 'format': k, 'format_id': k, 'preference': f['preference'], + 'format': k, + 'format_id': k, + 'preference': f['preference'], 'abr': f.get('abr') }) self._sort_formats(formats) From e8ac61e840b5c02e406b910f5f0eed3d8b331969 Mon Sep 17 00:00:00 2001 From: Yen Chi Hsuan Date: Fri, 5 Jun 2015 23:19:25 +0800 Subject: [PATCH 4/4] [qqmusic] Use meaningful variable names --- youtube_dl/extractor/qqmusic.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/youtube_dl/extractor/qqmusic.py b/youtube_dl/extractor/qqmusic.py index c903bee58..bafa81c21 100644 --- a/youtube_dl/extractor/qqmusic.py +++ b/youtube_dl/extractor/qqmusic.py @@ -76,14 +76,14 @@ class QQMusicIE(InfoExtractor): transform_source=strip_jsonp)['key'] formats = [] - for k, f in self._FORMATS.items(): + for format_id, details in self._FORMATS.items(): formats.append({ 'url': 'http://cc.stream.qqmusic.qq.com/%s%s.%s?vkey=%s&guid=%s&fromtag=0' - % (f['prefix'], mid, f['ext'], vkey, guid), - 'format': k, - 'format_id': k, - 'preference': f['preference'], - 'abr': f.get('abr') + % (details['prefix'], mid, details['ext'], vkey, guid), + 'format': format_id, + 'format_id': format_id, + 'preference': details['preference'], + 'abr': details.get('abr'), }) self._sort_formats(formats)