mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-13 14:37:43 +01:00
[neteasemusic] Changes after review
This commit is contained in:
parent
2da0cad6ae
commit
02b386f80a
@ -2,6 +2,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
|
from base64 import b64encode
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import itertools
|
import itertools
|
||||||
import re
|
import re
|
||||||
@ -20,14 +21,14 @@ class NetEaseMusicBaseIE(InfoExtractor):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _encrypt(cls, dfsid):
|
def _encrypt(cls, dfsid):
|
||||||
salt_bytes = bytearray(str(cls._NETEASE_SALT))
|
salt_bytes = bytearray(cls._NETEASE_SALT, 'utf-8')
|
||||||
string_bytes = bytearray(str(dfsid))
|
string_bytes = bytearray(str(dfsid))
|
||||||
salt_len = len(salt_bytes)
|
salt_len = len(salt_bytes)
|
||||||
for i in xrange(len(string_bytes)):
|
for i in range(len(string_bytes)):
|
||||||
string_bytes[i] = string_bytes[i] ^ salt_bytes[i % salt_len]
|
string_bytes[i] = string_bytes[i] ^ salt_bytes[i % salt_len]
|
||||||
m = md5()
|
m = md5()
|
||||||
m.update(string_bytes)
|
m.update(string_bytes)
|
||||||
result = m.digest().encode('base64')[:-1]
|
result = b64encode(m.digest())
|
||||||
return result.replace('/', '_').replace('+', '-')
|
return result.replace('/', '_').replace('+', '-')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -41,12 +42,11 @@ def extract_formats(cls, info):
|
|||||||
'url': 'http://m1.music.126.net/%s/%s.%s' %
|
'url': 'http://m1.music.126.net/%s/%s.%s' %
|
||||||
(cls._encrypt(details['dfsId']), details['dfsId'],
|
(cls._encrypt(details['dfsId']), details['dfsId'],
|
||||||
details['extension']),
|
details['extension']),
|
||||||
'ext': details['extension'],
|
'ext': details.get('extension'),
|
||||||
'abr': details['bitrate'] / 1000,
|
'abr': details.get('bitrate', 0) / 1000,
|
||||||
'preference': details['bitrate'],
|
|
||||||
'format_id': song_format,
|
'format_id': song_format,
|
||||||
'filesize': details['size'],
|
'filesize': details.get('size'),
|
||||||
'asr': details['sr']
|
'asr': details.get('sr')
|
||||||
})
|
})
|
||||||
return formats
|
return formats
|
||||||
|
|
||||||
@ -98,6 +98,19 @@ class NetEaseMusicIE(NetEaseMusicBaseIE):
|
|||||||
'upload_date': '20080211',
|
'upload_date': '20080211',
|
||||||
'timestamp': 1202745600,
|
'timestamp': 1202745600,
|
||||||
},
|
},
|
||||||
|
}, {
|
||||||
|
'note': 'Has translated name.',
|
||||||
|
'url': 'http://music.163.com/#/song?id=22735043',
|
||||||
|
'info_dict': {
|
||||||
|
'id': '22735043',
|
||||||
|
'ext': 'mp3',
|
||||||
|
'title': '소원을 말해봐 (Genie)',
|
||||||
|
'creator': '少女时代',
|
||||||
|
'description': 'md5:79d99cc560e4ca97e0c4d86800ee4184',
|
||||||
|
'upload_date': '20100127',
|
||||||
|
'timestamp': 1264608000,
|
||||||
|
'alt_title': '说出愿望吧(Genie)',
|
||||||
|
}
|
||||||
}]
|
}]
|
||||||
|
|
||||||
def _process_lyrics(self, lyrics_info):
|
def _process_lyrics(self, lyrics_info):
|
||||||
@ -109,10 +122,9 @@ def _process_lyrics(self, lyrics_info):
|
|||||||
|
|
||||||
lyrics_expr = r'(\[[0-9]{2}:[0-9]{2}\.[0-9]{2,}\])([^\n]+)'
|
lyrics_expr = r'(\[[0-9]{2}:[0-9]{2}\.[0-9]{2,}\])([^\n]+)'
|
||||||
original_ts_texts = re.findall(lyrics_expr, original)
|
original_ts_texts = re.findall(lyrics_expr, original)
|
||||||
translation_ts_dict = {
|
translation_ts_dict = dict(
|
||||||
time_stamp: text for time_stamp, text in re.findall(lyrics_expr, translated)
|
(time_stamp, text) for time_stamp, text in re.findall(lyrics_expr, translated)
|
||||||
}
|
)
|
||||||
|
|
||||||
lyrics = '\n'.join([
|
lyrics = '\n'.join([
|
||||||
'%s%s / %s' % (time_stamp, text, translation_ts_dict.get(time_stamp, ''))
|
'%s%s / %s' % (time_stamp, text, translation_ts_dict.get(time_stamp, ''))
|
||||||
for time_stamp, text in original_ts_texts
|
for time_stamp, text in original_ts_texts
|
||||||
@ -139,8 +151,8 @@ def _real_extract(self, url):
|
|||||||
lyrics = self._process_lyrics(lyrics_info)
|
lyrics = self._process_lyrics(lyrics_info)
|
||||||
|
|
||||||
alt_title = None
|
alt_title = None
|
||||||
if info.get('alias'):
|
if info.get('transNames'):
|
||||||
alt_title = '/'.join(info.get('alias'))
|
alt_title = '/'.join(info.get('transNames'))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': song_id,
|
'id': song_id,
|
||||||
@ -294,7 +306,7 @@ def _real_extract(self, url):
|
|||||||
mv_id, 'Downloading mv info')['data']
|
mv_id, 'Downloading mv info')['data']
|
||||||
|
|
||||||
formats = [
|
formats = [
|
||||||
{'url': mv_url, 'ext': 'mp4', 'format_id': '%sp' % brs, 'preference': int(brs)}
|
{'url': mv_url, 'ext': 'mp4', 'format_id': '%sp' % brs, 'height': int(brs)}
|
||||||
for brs, mv_url in info['brs'].items()
|
for brs, mv_url in info['brs'].items()
|
||||||
]
|
]
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
Loading…
Reference in New Issue
Block a user