新增XIAOMUSIC_USE_MUSIC_API=true时使用player_play_music接口,兼容部分不能播放的设备型号 see #30
This commit is contained in:
parent
4a234e8829
commit
17279aaae0
@ -86,6 +86,9 @@ class Config:
|
|||||||
)
|
)
|
||||||
key_word_dict = DEFAULT_KEY_WORD_DICT.copy()
|
key_word_dict = DEFAULT_KEY_WORD_DICT.copy()
|
||||||
key_match_order = DEFAULT_KEY_MATCH_ORDER.copy()
|
key_match_order = DEFAULT_KEY_MATCH_ORDER.copy()
|
||||||
|
use_music_api: bool = (
|
||||||
|
os.getenv("XIAOMUSIC_USE_MUSIC_API", "false").lower() == "true"
|
||||||
|
)
|
||||||
|
|
||||||
def append_keyword(self, keys, action):
|
def append_keyword(self, keys, action):
|
||||||
for key in keys.split(","):
|
for key in keys.split(","):
|
||||||
|
@ -3,7 +3,9 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import difflib
|
import difflib
|
||||||
import os
|
import os
|
||||||
|
import random
|
||||||
import re
|
import re
|
||||||
|
import string
|
||||||
import tempfile
|
import tempfile
|
||||||
from collections.abc import AsyncIterator
|
from collections.abc import AsyncIterator
|
||||||
from http.cookies import SimpleCookie
|
from http.cookies import SimpleCookie
|
||||||
@ -213,3 +215,7 @@ def get_local_music_duration(filename):
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
return duration
|
return duration
|
||||||
|
|
||||||
|
|
||||||
|
def get_random(length):
|
||||||
|
return "".join(random.sample(string.ascii_letters + string.digits, length))
|
||||||
|
@ -29,6 +29,7 @@ from xiaomusic.utils import (
|
|||||||
custom_sort_key,
|
custom_sort_key,
|
||||||
fuzzyfinder,
|
fuzzyfinder,
|
||||||
get_local_music_duration,
|
get_local_music_duration,
|
||||||
|
get_random,
|
||||||
get_web_music_duration,
|
get_web_music_duration,
|
||||||
parse_cookie_string,
|
parse_cookie_string,
|
||||||
walk_to_depth,
|
walk_to_depth,
|
||||||
@ -622,6 +623,25 @@ class XiaoMusic:
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
async def play_url(self, url):
|
||||||
|
if self.config.use_music_api:
|
||||||
|
audio_id = get_random(30)
|
||||||
|
music = {
|
||||||
|
"payload": {
|
||||||
|
"audio_items": [
|
||||||
|
{"item_id": {"audio_id": audio_id}, "stream": {"url": url}}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return await self.mina_service.ubus_request(
|
||||||
|
self.device_id,
|
||||||
|
"player_play_music",
|
||||||
|
"mediaplayer",
|
||||||
|
{"startaudioid": audio_id, "music": json.dumps(music)},
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
await self.mina_service.play_by_url(self.device_id, url)
|
||||||
|
|
||||||
# 播放本地歌曲
|
# 播放本地歌曲
|
||||||
async def playlocal(self, **kwargs):
|
async def playlocal(self, **kwargs):
|
||||||
name = kwargs.get("arg1", "")
|
name = kwargs.get("arg1", "")
|
||||||
@ -647,7 +667,7 @@ class XiaoMusic:
|
|||||||
url = self.get_music_url(name)
|
url = self.get_music_url(name)
|
||||||
self.log.info(f"播放 {url}")
|
self.log.info(f"播放 {url}")
|
||||||
await self.force_stop_xiaoai()
|
await self.force_stop_xiaoai()
|
||||||
await self.mina_service.play_by_url(self.device_id, url)
|
await self.play_url(url)
|
||||||
self.log.info("已经开始播放了")
|
self.log.info("已经开始播放了")
|
||||||
# 设置下一首歌曲的播放定时器
|
# 设置下一首歌曲的播放定时器
|
||||||
await self.set_next_music_timeout()
|
await self.set_next_music_timeout()
|
||||||
|
Loading…
Reference in New Issue
Block a user