二维码5分钟过期
This commit is contained in:
parent
6f9bd30625
commit
85e133dcbe
|
@ -1,6 +1,6 @@
|
||||||
"""Support for media browsing."""
|
"""Support for media browsing."""
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
import logging, os, random
|
import logging, os, random, time
|
||||||
from urllib.parse import urlparse, parse_qs, parse_qsl, quote
|
from urllib.parse import urlparse, parse_qs, parse_qsl, quote
|
||||||
from homeassistant.util.json import save_json
|
from homeassistant.util.json import save_json
|
||||||
from custom_components.ha_cloud_music.http_api import http_get
|
from custom_components.ha_cloud_music.http_api import http_get
|
||||||
|
@ -186,20 +186,26 @@ async def async_browse_media(media_player, media_content_type, media_content_id)
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
else:
|
else:
|
||||||
res = await cloud_music.netease_cloud_music('/login/qr/key')
|
qr = cloud_music.login_qrcode
|
||||||
if res['code'] == 200:
|
now = int(time.time())
|
||||||
codekey = res['data']['unikey']
|
# 超过5分钟重新获取验证码
|
||||||
res = await cloud_music.netease_cloud_music(f'/login/qr/create?key={codekey}')
|
if qr['time'] is None or now - qr['time'] > 300:
|
||||||
qrurl = res['data']['qrurl']
|
res = await cloud_music.netease_cloud_music('/login/qr/key')
|
||||||
print(qrurl)
|
if res['code'] == 200:
|
||||||
children.extend([
|
codekey = res['data']['unikey']
|
||||||
{
|
res = await cloud_music.netease_cloud_music(f'/login/qr/create?key={codekey}')
|
||||||
'title': 'APP扫码授权后,点击这里登录',
|
qr['key'] = codekey
|
||||||
'path': CloudMusicRouter.my_login + '?id=' + codekey,
|
qr['url'] = res['data']['qrurl']
|
||||||
'type': MEDIA_TYPE_MUSIC,
|
qr['time'] = now
|
||||||
'thumbnail': f'https://cdn.dotmaui.com/qrc/?t={qrurl}'
|
|
||||||
}
|
children.extend([
|
||||||
])
|
{
|
||||||
|
'title': 'APP扫码授权后,点击这里登录',
|
||||||
|
'path': CloudMusicRouter.my_login + '?id=' + qr['key'],
|
||||||
|
'type': MEDIA_TYPE_MUSIC,
|
||||||
|
'thumbnail': f'https://cdn.dotmaui.com/qrc/?t={qr["url"]}'
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
# 扩展资源
|
# 扩展资源
|
||||||
children.extend([
|
children.extend([
|
||||||
|
|
|
@ -35,6 +35,12 @@ class CloudMusic():
|
||||||
self.userinfo_filepath = self.get_storage_dir('cloud_music.userinfo')
|
self.userinfo_filepath = self.get_storage_dir('cloud_music.userinfo')
|
||||||
if os.path.exists(self.userinfo_filepath):
|
if os.path.exists(self.userinfo_filepath):
|
||||||
self.userinfo = load_json(self.userinfo_filepath)
|
self.userinfo = load_json(self.userinfo_filepath)
|
||||||
|
# 登录二维码
|
||||||
|
self.login_qrcode = {
|
||||||
|
'key': None,
|
||||||
|
'time': None,
|
||||||
|
'url': None
|
||||||
|
}
|
||||||
|
|
||||||
def get_storage_dir(self, file_name):
|
def get_storage_dir(self, file_name):
|
||||||
return os.path.abspath(f'{STORAGE_DIR}/{file_name}')
|
return os.path.abspath(f'{STORAGE_DIR}/{file_name}')
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"domain": "ha_cloud_music",
|
"domain": "ha_cloud_music",
|
||||||
"name": "\u4E91\u97F3\u4E50",
|
"name": "\u4E91\u97F3\u4E50",
|
||||||
"version": "2023.3.24",
|
"version": "2023.3.25",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://github.com/shaonianzhentan/ha_cloud_music",
|
"documentation": "https://github.com/shaonianzhentan/ha_cloud_music",
|
||||||
"requirements": [],
|
"requirements": [],
|
||||||
|
|
Loading…
Reference in New Issue