Skip to content

Commit

Permalink
Version 1.6.9.0.1
Browse files Browse the repository at this point in the history
cli : when logging in anonymously (i.e. not providing any credentials), utilize unique deviceId to authenticate
cli : added explanations for failed downloads (#41)
helper.SubstituteWithFullwidth : added `"` as one of the forbidden chars
  • Loading branch information
mos9527 committed Jun 14, 2023
1 parent 7d49f17 commit fd82906
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyncm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# 注意事项
- (PR#11) 海外用户可能经历 460 "Cheating" 问题,可通过添加以下 Header 解决: `X-Real-IP = 118.88.88.88`
"""
__version__ = "1.6.9.0"
__version__ = "1.6.9.0.1"

from threading import current_thread
from typing import Text, Union
Expand Down
25 changes: 23 additions & 2 deletions pyncm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,22 @@ def execute(task: BaseKeyValueClass):
# Downloding source audio
dAudio = track.GetTrackAudioV1(task.audio.id, level=task.audio.level)
dAudio = dAudio.get("data", [{"url": ""}])[0] # Dummy fallback value
assert dAudio["url"], "%s 无法下载,资源不存在" % task.song.Title
if not dAudio['url']:
# Attempt to give some sort of explaination
# 来自 https://neteasecloudmusicapi-docs.4everland.app/#/?id=%e8%8e%b7%e5%8f%96%e6%ad%8c%e6%9b%b2%e8%af%a6%e6%83%85
''' fee : enum
0: 免费或无版权
1: VIP 歌曲
4: 购买专辑
8: 非会员可免费播放低音质,会员可播放高音质及下载
fee 为 1 或 8 的歌曲均可单独购买 2 元单曲
'''
fee = dAudio['fee']
assert fee != 0,"可能无版权"
assert fee != 1,"VIP歌曲,账户可能无权访问"
assert fee != 4,"歌曲所在专辑需购买"
assert fee != 8,"歌曲可能需要单独购买或以低音质加载"
assert False, "未知原因 (fee=%d)" % fee
logger.info(
"开始下载 #%d / %d - %s - %s - %skbps - %s"
% (
Expand Down Expand Up @@ -597,8 +612,14 @@ def write(__s):
open(args.save, "w").write(DumpSessionAsString(GetCurrentSession()))
return 0
if not GetCurrentSession().logged_in:
# deviceID doesn't seem to have a format,so to speak
# Meaning anything will work.
# What we're trying to do here is to generate a UUID for
# the current machine so pyncm users won't be sharing the same one (i.e. id=pyncm!)
import uuid,base64
GetCurrentSession().deviceId = base64.b64encode(uuid.getnode().to_bytes(48,"little")).decode()
login.LoginViaAnonymousAccount()
logger.info("以匿名身份登陆成功,UID: %s" % GetCurrentSession().uid)
logger.info("以匿名身份登陆成功,deviceId=%s, UID: %s" % (GetCurrentSession().deviceId,GetCurrentSession().uid))
executor = TaskPoolExecutorThread(max_workers=args.max_workers)
executor.daemon = True
executor.start()
Expand Down
7 changes: 3 additions & 4 deletions pyncm/apis/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,8 @@ def LoginViaAnonymousAccount(deviceId=None):
Returns:
dict
'''
if deviceId:
GetCurrentSession().deviceId = deviceId
deviceId = GetCurrentSession().deviceId
if not deviceId:
deviceId = GetCurrentSession().deviceId
login_status = WeapiCryptoRequest(
lambda: ("/api/register/anonimous" , {
"username" : b64encode(
Expand All @@ -282,7 +281,7 @@ def LoginViaAnonymousAccount(deviceId=None):
).decode()
}
)
)()
)()
assert login_status['code'] == 200,"匿名登陆失败"
WriteLoginInfo({
**login_status,
Expand Down
2 changes: 1 addition & 1 deletion pyncm/utils/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
truncate_length = 64
logger = logging.getLogger("pyncm.helper")

def SubstituteWithFullwidth(string,sub=set('\x00\\/:<>|?*')):
def SubstituteWithFullwidth(string,sub=set('\x00\\/:<>|?*"')):
return "".join([c if not c in sub else chr(ord(c) + 0xFEE0) for c in string])

def Default(default=None):
Expand Down

0 comments on commit fd82906

Please sign in to comment.