Skip to content

Commit

Permalink
fix: 分享歌曲/歌单任务执行失败
Browse files Browse the repository at this point in the history
  • Loading branch information
chen310 committed Jan 26, 2022
1 parent 9c5cb6c commit a224f81
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
3 changes: 1 addition & 2 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ def request(self, method, path, params={}, base_url=BASE_URL, default={"code": -
data = default

for key, value in custom_cookies.items():
cookie = self.make_cookie(key, value)
self.session.cookies.set_cookie(cookie)
self.session.cookies.set(key, value)

params = encrypted_request(params)
try:
Expand Down
26 changes: 11 additions & 15 deletions user.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,18 @@ def login_check(self, username, pwd='', countrycode='', ip=''):
music.header["X-Real-IP"] = ip
if self.runtime == 'tencent-scf':
var_name = 'COOKIE_' + username
if var_name in os.environ:
music_u = ''
csrf = ''

if var_name in os.environ:
sp = os.environ.get(var_name).split(";")
cookies = {}
for c in sp:
if 'MUSIC_U' in c:
music_u = c.split(':')[1]
elif '__csrf' in c:
csrf = c.split(':')[1]
if len(music_u) > 0 and len(csrf) > 0:
t = c.split(':')
if len(t) == 2:
cookies[t[0]] = t[1]
if len(cookies) > 0:
music.session = requests.Session()
requests.utils.add_dict_to_cookiejar(music.session.cookies, {
'MUSIC_U': music_u, '__csrf': csrf, '__remember_me': 'true', 'os': 'pc'})
cookies['__remember_me'] = 'true'
requests.utils.add_dict_to_cookiejar(
music.session.cookies, cookies)
resp = music.user_level()
if resp['code'] == 200:
print('已通过 cookie 登录')
Expand All @@ -106,14 +104,12 @@ def login_check(self, username, pwd='', countrycode='', ip=''):
if self.runtime == 'tencent-scf':
for cookie in music.session.cookies:
if cookie.name == 'MUSIC_U':
music_cookie += 'MUSIC_U:' + \
str(cookie.value) + ';'
music_cookie += 'MUSIC_U:' + cookie.value + ';'
elif cookie.name == '__csrf':
music_cookie += '__csrf:' + str(cookie.value) + ';'
music_cookie += '__csrf:' + cookie.value + ';'

self.saved_environs['COOKIE_' + username] = music_cookie


music.uid = login_resp['profile']['userId']
music.nickname = login_resp['profile']['nickname']
music.userType = login_resp['profile']['userType']
Expand Down

0 comments on commit a224f81

Please sign in to comment.