From 3a0a78731b5223b232beaabc3cdc771b9cebb078 Mon Sep 17 00:00:00 2001 From: ping Date: Sat, 16 Jan 2016 12:17:07 +0800 Subject: [PATCH 1/3] Fixes #8239 --- youtube_dl/extractor/neteasemusic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube_dl/extractor/neteasemusic.py b/youtube_dl/extractor/neteasemusic.py index 15eca825a..848ebdea0 100644 --- a/youtube_dl/extractor/neteasemusic.py +++ b/youtube_dl/extractor/neteasemusic.py @@ -40,7 +40,7 @@ class NetEaseMusicBaseIE(InfoExtractor): if not details: continue formats.append({ - 'url': 'http://m5.music.126.net/%s/%s.%s' % + 'url': 'http://203.130.59.9/m1.music.126.net/%s/%s.%s' % (cls._encrypt(details['dfsId']), details['dfsId'], details['extension']), 'ext': details.get('extension'), From e0ef13ddebfab39d8c59c8cd9c11882cfc604070 Mon Sep 17 00:00:00 2001 From: ping Date: Sun, 17 Jan 2016 07:48:46 +0800 Subject: [PATCH 2/3] [neteasemusic] Fallback to alt hosts if m5.music.126.net doesn't work --- youtube_dl/extractor/neteasemusic.py | 35 +++++++++++++++++----------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/youtube_dl/extractor/neteasemusic.py b/youtube_dl/extractor/neteasemusic.py index 848ebdea0..435cd8e2e 100644 --- a/youtube_dl/extractor/neteasemusic.py +++ b/youtube_dl/extractor/neteasemusic.py @@ -32,23 +32,32 @@ class NetEaseMusicBaseIE(InfoExtractor): result = b64encode(m.digest()).decode('ascii') return result.replace('/', '_').replace('+', '-') - @classmethod - def extract_formats(cls, info): + def extract_formats(self, info): formats = [] - for song_format in cls._FORMATS: + for song_format in self._FORMATS: details = info.get(song_format) if not details: continue - formats.append({ - 'url': 'http://203.130.59.9/m1.music.126.net/%s/%s.%s' % - (cls._encrypt(details['dfsId']), details['dfsId'], - details['extension']), - 'ext': details.get('extension'), - 'abr': details.get('bitrate', 0) / 1000, - 'format_id': song_format, - 'filesize': details.get('size'), - 'asr': details.get('sr') - }) + song_file_path = '/%s/%s.%s' % ( + self._encrypt(details['dfsId']), details['dfsId'], details['extension']) + + # 203.130.59.9, 124.40.233.182, 115.231.74.139, etc is a reverse proxy-like feature + # from NetEase's CDN provider that can be used if m5.music.126.net does not + # work, especially for users outside of Mainland China + # via: https://github.com/JixunMoe/unblock-163/issues/3#issuecomment-163115880 + for host in ('http://m5.music.126.net', 'http://115.231.74.139/m1.music.126.net', + 'http://124.40.233.182/m1.music.126.net', 'http://203.130.59.9/m1.music.126.net'): + song_url = host + song_file_path + if self._is_valid_url(song_url, info['id'], 'song'): + formats.append({ + 'url': song_url, + 'ext': details.get('extension'), + 'abr': details.get('bitrate', 0) / 1000, + 'format_id': song_format, + 'filesize': details.get('size'), + 'asr': details.get('sr') + }) + break return formats @classmethod From fe6856b0595b85c8070d7ccc154cd8ac2ff85e2c Mon Sep 17 00:00:00 2001 From: Yen Chi Hsuan Date: Wed, 20 Jan 2016 04:21:51 +0800 Subject: [PATCH 3/3] [neteasemusic] Use float_or_none --- youtube_dl/extractor/neteasemusic.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/youtube_dl/extractor/neteasemusic.py b/youtube_dl/extractor/neteasemusic.py index 435cd8e2e..7830616f8 100644 --- a/youtube_dl/extractor/neteasemusic.py +++ b/youtube_dl/extractor/neteasemusic.py @@ -12,7 +12,10 @@ from ..compat import ( compat_str, compat_itertools_count, ) -from ..utils import sanitized_Request +from ..utils import ( + sanitized_Request, + float_or_none, +) class NetEaseMusicBaseIE(InfoExtractor): @@ -52,7 +55,7 @@ class NetEaseMusicBaseIE(InfoExtractor): formats.append({ 'url': song_url, 'ext': details.get('extension'), - 'abr': details.get('bitrate', 0) / 1000, + 'abr': float_or_none(details.get('bitrate'), scale=1000), 'format_id': song_format, 'filesize': details.get('size'), 'asr': details.get('sr')