调整二维码登录逻辑
This commit is contained in:
parent
aaea2cb771
commit
83ab410727
|
@ -202,7 +202,8 @@ async def async_browse_media(media_player, media_content_type, media_content_id)
|
|||
},{
|
||||
'title': '二维码登录',
|
||||
'path': CloudMusicRouter.my_login + '?action=menu',
|
||||
'type': MEDIA_TYPE_CHANNEL
|
||||
'type': MEDIA_TYPE_CHANNEL,
|
||||
'thumbnail': 'https://p1.music.126.net/kMuXXbwHbduHpLYDmHXrlA==/109951168152833223.jpg'
|
||||
}
|
||||
])
|
||||
|
||||
|
@ -293,23 +294,25 @@ async def async_browse_media(media_player, media_content_type, media_content_id)
|
|||
qr['url'] = res['data']['qrurl']
|
||||
qr['time'] = now
|
||||
|
||||
library_info = BrowseMedia(
|
||||
return BrowseMedia(
|
||||
media_class=MEDIA_CLASS_DIRECTORY,
|
||||
media_content_id=media_content_id,
|
||||
media_content_type=MEDIA_CLASS_TRACK,
|
||||
title=title,
|
||||
title='APP扫码授权后,点击二维码登录',
|
||||
can_play=False,
|
||||
can_expand=True,
|
||||
children=[
|
||||
{
|
||||
'title': 'APP扫码授权后,点击这里登录',
|
||||
'path': CloudMusicRouter.my_login + '?action=login&id=' + qr['key'],
|
||||
'type': MEDIA_TYPE_MUSIC,
|
||||
'thumbnail': f'https://cdn.dotmaui.com/qrc/?t={qr["url"]}'
|
||||
}
|
||||
BrowseMedia(
|
||||
title='点击检查登录',
|
||||
media_class=MEDIA_CLASS_DIRECTORY,
|
||||
media_content_type=MEDIA_TYPE_MUSIC,
|
||||
media_content_id=CloudMusicRouter.my_login + '?action=login&id=' + qr['key'],
|
||||
can_play=False,
|
||||
can_expand=True,
|
||||
thumbnail=f'https://cdn.dotmaui.com/qrc/?t={qr["url"]}'
|
||||
)
|
||||
],
|
||||
)
|
||||
return library_info
|
||||
elif action == 'login':
|
||||
# 用户登录
|
||||
res = await cloud_music.netease_cloud_music(f'/login/qr/check?key={id}&t={int(time.time())}')
|
||||
|
@ -320,7 +323,7 @@ async def async_browse_media(media_player, media_content_type, media_content_id)
|
|||
else:
|
||||
title = f'{message},点击返回重试'
|
||||
|
||||
library_info = BrowseMedia(
|
||||
return BrowseMedia(
|
||||
media_class=MEDIA_CLASS_DIRECTORY,
|
||||
media_content_id=media_content_id,
|
||||
media_content_type=MEDIA_TYPE_PLAYLIST,
|
||||
|
@ -329,7 +332,6 @@ async def async_browse_media(media_player, media_content_type, media_content_id)
|
|||
can_expand=False,
|
||||
children=[],
|
||||
)
|
||||
return library_info
|
||||
if media_content_id.startswith(CloudMusicRouter.my_daily):
|
||||
# 每日推荐
|
||||
library_info = BrowseMedia(
|
||||
|
|
|
@ -78,8 +78,21 @@ class CloudMusic():
|
|||
|
||||
# 二维码登录
|
||||
async def qrcode_login(self, cookie_str):
|
||||
'''
|
||||
s = SimpleCookie(cookie_str)
|
||||
cookie = {v.key:v.value for k,v in s.items()}
|
||||
'''
|
||||
arr = cookie_str.split(';')
|
||||
cookie = {}
|
||||
for item in arr:
|
||||
x = item.strip()
|
||||
if x == '' or x.startswith('Max-Age=') or x.startswith('Expires=') \
|
||||
or x.startswith('Path=') or x.startswith('HTTPOnly'):
|
||||
continue
|
||||
kv = x.split('=')
|
||||
if kv[1] != '':
|
||||
cookie[kv[0]] = kv[1]
|
||||
|
||||
# 设置cookie
|
||||
self.userinfo['cookie'] = cookie
|
||||
res = await self.netease_cloud_music('/user/account')
|
||||
|
@ -97,11 +110,11 @@ class CloudMusic():
|
|||
self.notification('用户凭据失效,请重新登录。如果多次失败,请联系插件作者')
|
||||
|
||||
def notification(self, message, notification_id='ha_cloud_music'):
|
||||
self.hass.services.call('persistent_notification', 'create', {
|
||||
self.hass.async_create_task(self.hass.services.async_call('persistent_notification', 'create', {
|
||||
'title': '云音乐',
|
||||
'message': message,
|
||||
'notification_id': notification_id
|
||||
})
|
||||
}))
|
||||
|
||||
# 获取播放链接
|
||||
def get_play_url(self, id, song, singer, source):
|
||||
|
@ -113,8 +126,16 @@ class CloudMusic():
|
|||
# 网易云音乐接口
|
||||
async def netease_cloud_music(self, url):
|
||||
res = await http_get(self.api_url + url, self.userinfo.get('cookie', {}))
|
||||
if res.get('code') != 200:
|
||||
self.notification(res.get('msg'))
|
||||
code = res.get('code')
|
||||
print(code, url)
|
||||
if code != 200 and code != 801:
|
||||
print(res)
|
||||
msg = res.get('msg')
|
||||
if msg is not None:
|
||||
self.notification(msg)
|
||||
elif code == 302:
|
||||
if self.userinfo.get('uid') is not None:
|
||||
self.notification(f'请求数据失败,账号出现异常\n\ncode: {code} \nurl: {url} \n\n这种情况一般是接口问题,和插件没有关系')
|
||||
return res
|
||||
|
||||
# 获取音乐链接
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"domain": "ha_cloud_music",
|
||||
"name": "\u4E91\u97F3\u4E50",
|
||||
"version": "2023.5.15",
|
||||
"version": "2023.5.17",
|
||||
"config_flow": true,
|
||||
"documentation": "https://github.com/shaonianzhentan/ha_cloud_music",
|
||||
"requirements": [
|
||||
|
|
Loading…
Reference in New Issue