修复第三方资源无法播放的问题
This commit is contained in:
parent
3a5188005b
commit
15b028d97a
|
@ -98,13 +98,13 @@ class CloudMusic():
|
|||
|
||||
# 获取云盘音乐链接
|
||||
async def cloud_song_url(self, id):
|
||||
res = await self.netease_cloud_music(f'/user/cloud')
|
||||
_LOGGER.debug(res)
|
||||
filter_list = list(filter(lambda x:x['simpleSong']['id'] == id, res['data']))
|
||||
if len(filter_list) > 0:
|
||||
songId = filter_list[0]['songId']
|
||||
url, fee = await self.song_url(songId)
|
||||
return url
|
||||
if self.userinfo.get('uid') is not None:
|
||||
res = await self.netease_cloud_music(f'/user/cloud')
|
||||
filter_list = list(filter(lambda x:x['simpleSong']['id'] == id, res['data']))
|
||||
if len(filter_list) > 0:
|
||||
songId = filter_list[0]['songId']
|
||||
url, fee = await self.song_url(songId)
|
||||
return url
|
||||
|
||||
# 获取歌单列表
|
||||
async def async_get_playlist(self, playlist_id):
|
||||
|
@ -423,8 +423,10 @@ class CloudMusic():
|
|||
}, res['result']['playlists']))
|
||||
return _list
|
||||
|
||||
async def async_music_source(self, keyword):
|
||||
|
||||
async def async_music_source(self, song, singer=''):
|
||||
keyword = f'{singer} {song}'.strip()
|
||||
_LOGGER.debug(keyword)
|
||||
|
||||
result = await self.hass.async_add_executor_job(get_music, keyword)
|
||||
if result is not None:
|
||||
return result
|
||||
|
|
|
@ -48,7 +48,7 @@ class HttpView(HomeAssistantView):
|
|||
if url is not None:
|
||||
# 收费音乐
|
||||
if fee == 1:
|
||||
result = await cloud_music.async_music_source(f'{song} - {singer}')
|
||||
result = await cloud_music.async_music_source(song, singer)
|
||||
if result is not None:
|
||||
url = result.url
|
||||
|
||||
|
@ -59,7 +59,7 @@ class HttpView(HomeAssistantView):
|
|||
if url is not None:
|
||||
play_url = url
|
||||
else:
|
||||
result = await cloud_music.async_music_source(f'{song} - {singer}')
|
||||
result = await cloud_music.async_music_source(song, singer)
|
||||
if result is not None:
|
||||
play_url = result.url
|
||||
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
{
|
||||
"domain": "ha_cloud_music",
|
||||
"name": "\u4E91\u97F3\u4E50",
|
||||
"version": "2023.3.29",
|
||||
"version": "2023.3.30",
|
||||
"config_flow": true,
|
||||
"documentation": "https://github.com/shaonianzhentan/ha_cloud_music",
|
||||
"requirements": [],
|
||||
"requirements": [
|
||||
"beautifulsoup4>=4.11.1",
|
||||
"lxml>=4.9.1"
|
||||
],
|
||||
"codeowners": [
|
||||
"@shaonianzhentan"
|
||||
],
|
||||
|
|
|
@ -15,12 +15,12 @@ def get_music(keywords):
|
|||
song = a[0].string
|
||||
singer = a[1].string
|
||||
|
||||
# print(href)
|
||||
#print(href)
|
||||
response = session.get(f'{api}{href}')
|
||||
|
||||
pattren = re.compile(r'https://[^\s]+.mp3')
|
||||
url_lst = pattren.findall(response.text)
|
||||
# print(url_lst)
|
||||
#print(url_lst)
|
||||
if len(url_lst) > 0:
|
||||
soup = BeautifulSoup(response.text.encode(response.encoding), 'lxml')
|
||||
cover = soup.select('#cover')
|
||||
|
|
Loading…
Reference in New Issue