修复部分小爱音箱会截断URL参数的问题
This commit is contained in:
parent
68c5c61447
commit
f375408320
|
@ -1,4 +1,4 @@
|
|||
import uuid, time, logging, os, hashlib, aiohttp, requests
|
||||
import uuid, time, logging, os, hashlib, aiohttp, base64
|
||||
from urllib.parse import quote
|
||||
from homeassistant.helpers.network import get_url
|
||||
from .http_api import http_get, http_cookie
|
||||
|
@ -121,7 +121,10 @@ class CloudMusic():
|
|||
base_url = get_url(self.hass, prefer_external=True)
|
||||
if singer is None:
|
||||
singer = ''
|
||||
return f'{base_url}/cloud_music/url?id={id}&song={quote(song)}&singer={quote(singer)}&source={source}'
|
||||
|
||||
encoded_data = base64.b64encode(f'id={id}&song={quote(song)}&singer={quote(singer)}&source={source}'.encode('utf-8'))
|
||||
url_encoded_data = quote(encoded_data.decode('utf-8'), safe='-_')
|
||||
return f'{base_url}/cloud_music/url?data={url_encoded_data}'
|
||||
|
||||
# 网易云音乐接口
|
||||
async def netease_cloud_music(self, url):
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import os
|
||||
import json
|
||||
import base64
|
||||
import requests
|
||||
from urllib.parse import parse_qsl, quote
|
||||
from homeassistant.components.http import HomeAssistantView
|
||||
|
@ -9,7 +8,6 @@ from .manifest import manifest
|
|||
|
||||
DOMAIN = manifest.domain
|
||||
|
||||
|
||||
class HttpView(HomeAssistantView):
|
||||
|
||||
url = "/cloud_music/url"
|
||||
|
@ -20,21 +18,27 @@ class HttpView(HomeAssistantView):
|
|||
play_url = None
|
||||
|
||||
async def get(self, request):
|
||||
|
||||
hass = request.app["hass"]
|
||||
cloud_music = hass.data['cloud_music']
|
||||
|
||||
query = request.query
|
||||
query = {}
|
||||
data = request.query.get('data')
|
||||
if data is not None:
|
||||
decoded_data = base64.b64decode(data).decode('utf-8')
|
||||
qsl = parse_qsl(decoded_data)
|
||||
for q in qsl:
|
||||
query[q[0]] = q[1]
|
||||
|
||||
print(query)
|
||||
|
||||
id = query.get('id')
|
||||
source = query.get('source')
|
||||
song = query.get('song')
|
||||
singer = query.get('singer')
|
||||
|
||||
not_found_tips = quote(f'当前没有找到编号是{id},歌名为{song},作者是{singer}的播放链接')
|
||||
play_url = f'https://fanyi.baidu.com/gettts?lan=zh&text={not_found_tips}&spd=5&source=web'
|
||||
|
||||
if id is None or source is None:
|
||||
return web.HTTPFound(play_url)
|
||||
play_url = f'http://fanyi.baidu.com/gettts?lan=zh&text={not_found_tips}&spd=5&source=web'
|
||||
|
||||
# 缓存KEY
|
||||
play_key = f'{id}{song}{singer}{source}'
|
||||
|
@ -70,14 +74,9 @@ class HttpView(HomeAssistantView):
|
|||
|
||||
print(play_url)
|
||||
self.play_key = play_key
|
||||
self.play_url = play_url
|
||||
self.play_url = play_url
|
||||
# 重定向到可播放链接
|
||||
response = web.HTTPFound(play_url, headers={
|
||||
'Content-Length': 0,
|
||||
'Cache-Control': 'no-cache, no-store, keep-alive=timeout=4'
|
||||
})
|
||||
response.remove_header('Content-Type')
|
||||
return response
|
||||
return web.HTTPFound(play_url)
|
||||
|
||||
# VIP音乐资源
|
||||
def getVipMusic(self, id):
|
||||
|
|
Loading…
Reference in New Issue