Compare commits

...

4 Commits

Author SHA1 Message Date
shaonianzhentan aa64ec239e Merge branch 'dev' 2024-01-17 10:08:07 +08:00
shaonianzhentan 20effe9503 update version 2024-01-17 10:04:46 +08:00
shaonianzhentan d5542c381f 兼容新版HA 2024-01-17 09:59:39 +08:00
shaonianzhentan e68cec504d 删除日志 2024-01-17 09:57:34 +08:00
7 changed files with 38 additions and 50 deletions

View File

@ -119,7 +119,6 @@ class CloudMusicRouter():
async def async_browse_media(media_player, media_content_type, media_content_id):
print(media_content_type, media_content_id)
hass = media_player.hass
cloud_music = hass.data['cloud_music']
@ -730,7 +729,6 @@ async def async_browse_media(media_player, media_content_type, media_content_id)
''' ================== 播放音乐 ================== '''
async def async_play_media(media_player, cloud_music, media_content_id):
print(media_content_id)
hass = media_player.hass
# 媒体库
if media_source.is_media_source_id(media_content_id):

View File

@ -73,8 +73,6 @@ class CloudMusic():
}
save_json(self.userinfo_filepath, self.userinfo)
return res_data
else:
print(res_data)
# 二维码登录
async def qrcode_login(self, cookie_str):
@ -130,9 +128,7 @@ class CloudMusic():
async def netease_cloud_music(self, url):
res = await http_get(self.api_url + url, self.userinfo.get('cookie', {}))
code = res.get('code')
print(code, url)
if code != 200 and code != 801:
print(res)
msg = res.get('msg')
if msg is not None:
self.notification(msg)

View File

@ -35,8 +35,7 @@ class SimpleConfigFlow(ConfigFlow, domain=DOMAIN):
if res['data']['code'] == 200:
user_input[CONF_URL] = url
return self.async_create_entry(title=DOMAIN, data=user_input)
except Exception as ex:
print(ex)
except Exception as ex:
errors = { 'base': 'api_failed' }
else:
user_input = {}

View File

@ -30,8 +30,6 @@ class HttpView(HomeAssistantView):
for q in qsl:
query[q[0]] = q[1]
print(query)
id = query.get('id')
source = query.get('source')
song = query.get('song')
@ -72,7 +70,6 @@ class HttpView(HomeAssistantView):
if result is not None:
play_url = result.url
print(play_url)
self.play_key = play_key
self.play_url = play_url
# 重定向到可播放链接
@ -87,7 +84,6 @@ class HttpView(HomeAssistantView):
'source': 'netease'
})
data = res.json()
# print(data)
return data.get('url')
except Exception as ex:
print(ex)
pass

View File

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

View File

@ -4,9 +4,8 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.event import async_track_time_interval
from homeassistant.components.media_player import MediaPlayerEntity, MediaPlayerDeviceClass
from homeassistant.components.media_player import MediaPlayerEntity, MediaPlayerDeviceClass, MediaPlayerEntityFeature
from homeassistant.components.media_player.const import (
SUPPORT_BROWSE_MEDIA,
SUPPORT_TURN_OFF,
SUPPORT_TURN_ON,
SUPPORT_VOLUME_STEP,
@ -51,7 +50,7 @@ _LOGGER = logging.getLogger(__name__)
SUPPORT_FEATURES = SUPPORT_VOLUME_STEP | SUPPORT_VOLUME_MUTE | SUPPORT_VOLUME_SET | \
SUPPORT_PLAY_MEDIA | SUPPORT_PLAY | SUPPORT_PAUSE | SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK | \
SUPPORT_BROWSE_MEDIA | SUPPORT_SEEK | SUPPORT_CLEAR_PLAYLIST | SUPPORT_SHUFFLE_SET | SUPPORT_REPEAT_SET
MediaPlayerEntityFeature.BROWSE_MEDIA | SUPPORT_SEEK | SUPPORT_CLEAR_PLAYLIST | SUPPORT_SHUFFLE_SET | SUPPORT_REPEAT_SET
# 定时器时间
TIME_BETWEEN_UPDATES = datetime.timedelta(seconds=2)

View File

@ -1,45 +1,45 @@
from bs4 import BeautifulSoup
import requests, re
import requests
import re
from .models.music_info import MusicInfo, MusicSource
def get_last_part(path):
last_slash_index = path.rfind('/')
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'
session = requests.Session()
try:
response = session.get(f'{api}/s/{keyword}')
soup = BeautifulSoup(response.text.encode(response.encoding), 'lxml')
items = soup.select('.card-text .row')
if len(items) > 1:
row = items[1]
# print(td)
song = row.select('.col-5 a')[0].get_text().strip()
singer = row.select('.col-4')[0].get_text().strip()
# https://www.gequbao.com
api = 'https://www.fangpi.net'
session = requests.Session()
try:
response = session.get(f'{api}/s/{keyword}')
soup = BeautifulSoup(response.text.encode(response.encoding), 'lxml')
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()
a = row.select('.col-3 a')
href = a[0].attrs['href']
# print(href)
response = session.get(f'{api}{href}')
html = response.text
a = row.select('.col-3 a')
href = a[0].attrs['href']
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']
response = session.get(f'{api}{href}')
html = response.text
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)
soup = BeautifulSoup(html, 'lxml')
cover = soup.select('head meta[property="og:image"]')
pic = 'https://p2.music.126.net/tGHU62DTszbFQ37W9qPHcg==/2002210674180197.jpg'
# 封面
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)
except Exception as ex:
pass