Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
shaonianzhentan committed Oct 15, 2024
2 parents ba4644c + ae7af3a commit b1a9ae8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion custom_components/ha_cloud_music/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "ha_cloud_music",
"name": "\u4E91\u97F3\u4E50",
"version": "2024.7.2",
"version": "2024.10.15",
"config_flow": true,
"documentation": "https://github.com/shaonianzhentan/ha_cloud_music",
"requirements": [
Expand Down
4 changes: 2 additions & 2 deletions custom_components/ha_cloud_music/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ def interval(self, now):
return

self.before_state = {
'media_position': self._attr_media_position,
'media_duration': self._attr_media_duration,
'media_position': int(self._attr_media_position),
'media_duration': int(self._attr_media_duration),
'state': self.current_state
}
self.current_state = media_player.state
Expand Down
29 changes: 14 additions & 15 deletions custom_components/ha_cloud_music/music_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
import 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'
Expand All @@ -21,10 +13,10 @@ def get_music(keyword):
items = soup.select('.card-text .row')
if len(items) > 1:
row = items[1]
song = row.select('.col-5 a')[0].get_text().strip()
singer = row.select('.col-4')[0].get_text().strip()
song = row.select('.music-title')[0].get_text().strip()
singer = row.select('.text-jade')[0].get_text().strip()

a = row.select('.col-3 a')
a = row.select('.music-link')
href = a[0].attrs['href']

response = session.get(f'{api}{href}')
Expand All @@ -37,9 +29,16 @@ def get_music(keyword):
if len(cover) > 0:
pic = cover[0].attrs['content']

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)
# 音乐链接
pattern = r"window.play_id = '(.*?)';"
match = re.search(pattern, html)
if match:
songId = match.group(1)
response = session.post(f'{api}/api/play-url', data={'id': songId})
data = response.json()
if data.get('code') == 1:
audio_url = data['data']['url']
return MusicInfo(songId, song, singer, album, 0, audio_url, pic, MusicSource.URL.value)
except Exception as ex:
pass
print(ex)

0 comments on commit b1a9ae8

Please sign in to comment.