修复第三方资源无法播放的问题

This commit is contained in:
shaonianzhentan 2023-11-06 11:13:54 +08:00
parent a0f8532612
commit bb2fcfac9c
3 changed files with 18 additions and 19 deletions

View File

@ -51,9 +51,6 @@ https://github.com/Binaryify/NeteaseCloudMusicApi
- [x] 每日推荐 `cloudmusic://163/my/daily`
- [x] 我喜欢的音乐 `cloudmusic://163/my/ilike`
## 关联项目
- https://github.com/shaonianzhentan/cloud_music_mpd

View File

@ -1,7 +1,7 @@
{
"domain": "ha_cloud_music",
"name": "\u4E91\u97F3\u4E50",
"version": "2023.11.1",
"version": "2023.11.6",
"config_flow": true,
"documentation": "https://github.com/shaonianzhentan/ha_cloud_music",
"requirements": [

View File

@ -2,6 +2,12 @@ from bs4 import BeautifulSoup
import requests, re
from .models.music_info import MusicInfo, MusicSource
def get_last_part(path):
last_slash_index = path.rfind('/')
if last_slash_index != -1:
return path[last_slash_index + 1:]
return path
def get_music(keyword):
# https://www.gequbao.com
api = 'https://www.fangpi.net'
@ -23,21 +29,17 @@ def get_music(keyword):
response = session.get(f'{api}{href}')
html = response.text
pattren = re.compile(r'https://[^\s]+.mp3')
url_lst = pattren.findall(html)
# print(url_lst)
if len(url_lst) > 0:
soup = BeautifulSoup(html, 'lxml')
cover = soup.select('head meta[property="og:image"]')
#print(cover)
pic = 'https://p2.music.126.net/tGHU62DTszbFQ37W9qPHcg==/2002210674180197.jpg'
# 封面
if len(cover) > 0:
pic = cover[0].attrs['content']
soup = BeautifulSoup(html, 'lxml')
cover = soup.select('head meta[property="og:image"]')
#print(cover)
pic = 'https://p2.music.126.net/tGHU62DTszbFQ37W9qPHcg==/2002210674180197.jpg'
# 封面
if len(cover) > 0:
pic = cover[0].attrs['content']
songId = href.replace('/', '')
album = ''
audio_url = url_lst[0]
return MusicInfo(songId, song, singer, album, 0, audio_url, pic, MusicSource.URL.value)
songId = get_last_part(href)
album = ''
audio_url = f'https://www.fangpi.net/api/play_url?id={songId}'
return MusicInfo(songId, song, singer, album, 0, audio_url, pic, MusicSource.URL.value)
except Exception as ex:
print(ex)