修复第三方资源无法播放的问题
This commit is contained in:
parent
a0f8532612
commit
bb2fcfac9c
|
@ -51,9 +51,6 @@ https://github.com/Binaryify/NeteaseCloudMusicApi
|
||||||
- [x] 每日推荐 `cloudmusic://163/my/daily`
|
- [x] 每日推荐 `cloudmusic://163/my/daily`
|
||||||
- [x] 我喜欢的音乐 `cloudmusic://163/my/ilike`
|
- [x] 我喜欢的音乐 `cloudmusic://163/my/ilike`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 关联项目
|
## 关联项目
|
||||||
|
|
||||||
- https://github.com/shaonianzhentan/cloud_music_mpd
|
- https://github.com/shaonianzhentan/cloud_music_mpd
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"domain": "ha_cloud_music",
|
"domain": "ha_cloud_music",
|
||||||
"name": "\u4E91\u97F3\u4E50",
|
"name": "\u4E91\u97F3\u4E50",
|
||||||
"version": "2023.11.1",
|
"version": "2023.11.6",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://github.com/shaonianzhentan/ha_cloud_music",
|
"documentation": "https://github.com/shaonianzhentan/ha_cloud_music",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
|
|
|
@ -2,6 +2,12 @@ from bs4 import BeautifulSoup
|
||||||
import requests, re
|
import requests, re
|
||||||
from .models.music_info import MusicInfo, MusicSource
|
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):
|
def get_music(keyword):
|
||||||
# https://www.gequbao.com
|
# https://www.gequbao.com
|
||||||
api = 'https://www.fangpi.net'
|
api = 'https://www.fangpi.net'
|
||||||
|
@ -23,21 +29,17 @@ def get_music(keyword):
|
||||||
response = session.get(f'{api}{href}')
|
response = session.get(f'{api}{href}')
|
||||||
html = response.text
|
html = response.text
|
||||||
|
|
||||||
pattren = re.compile(r'https://[^\s]+.mp3')
|
soup = BeautifulSoup(html, 'lxml')
|
||||||
url_lst = pattren.findall(html)
|
cover = soup.select('head meta[property="og:image"]')
|
||||||
# print(url_lst)
|
#print(cover)
|
||||||
if len(url_lst) > 0:
|
pic = 'https://p2.music.126.net/tGHU62DTszbFQ37W9qPHcg==/2002210674180197.jpg'
|
||||||
soup = BeautifulSoup(html, 'lxml')
|
# 封面
|
||||||
cover = soup.select('head meta[property="og:image"]')
|
if len(cover) > 0:
|
||||||
#print(cover)
|
pic = cover[0].attrs['content']
|
||||||
pic = 'https://p2.music.126.net/tGHU62DTszbFQ37W9qPHcg==/2002210674180197.jpg'
|
|
||||||
# 封面
|
|
||||||
if len(cover) > 0:
|
|
||||||
pic = cover[0].attrs['content']
|
|
||||||
|
|
||||||
songId = href.replace('/', '')
|
songId = get_last_part(href)
|
||||||
album = ''
|
album = ''
|
||||||
audio_url = url_lst[0]
|
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)
|
return MusicInfo(songId, song, singer, album, 0, audio_url, pic, MusicSource.URL.value)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print(ex)
|
print(ex)
|
Loading…
Reference in New Issue