diff --git a/README.md b/README.md index b0aa053..7708f7b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/custom_components/ha_cloud_music/manifest.json b/custom_components/ha_cloud_music/manifest.json index 4ff6afa..f77cad4 100644 --- a/custom_components/ha_cloud_music/manifest.json +++ b/custom_components/ha_cloud_music/manifest.json @@ -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": [ diff --git a/custom_components/ha_cloud_music/music_parser.py b/custom_components/ha_cloud_music/music_parser.py index 940cd0f..6eede69 100644 --- a/custom_components/ha_cloud_music/music_parser.py +++ b/custom_components/ha_cloud_music/music_parser.py @@ -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) \ No newline at end of file