mirror of
https://github.com/hanxi/xiaomusic.git
synced 2025-12-07 15:02:55 +08:00
Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5619584481 | ||
|
|
3f0a1cb8f5 | ||
|
|
2f6105843b | ||
|
|
d71f99de53 | ||
|
|
d7385405d9 | ||
|
|
781e5ebb2f | ||
|
|
980772bf9c | ||
|
|
632e411c6e | ||
|
|
789d442029 | ||
|
|
0452d49930 | ||
|
|
19d781fa1f | ||
|
|
ad82d13a7e | ||
|
|
9c4d757dc0 | ||
|
|
e369d80875 | ||
|
|
9b0c8510a3 | ||
|
|
94fb158d7d | ||
|
|
11df6e9f0c | ||
|
|
4e8550a56c | ||
|
|
7f349410a0 | ||
|
|
6610c29fe4 | ||
|
|
3da1b8eac1 | ||
|
|
003068e62c | ||
|
|
1d12f0d508 | ||
|
|
1ee4667a79 | ||
|
|
521605e9c8 |
20
CHANGELOG.md
20
CHANGELOG.md
@@ -1,3 +1,23 @@
|
||||
## v0.3.31 (2024-09-10)
|
||||
|
||||
### Feat
|
||||
|
||||
- 新增播放上一首歌曲功能 #90
|
||||
- 新增所有歌曲列表
|
||||
- 触屏版显示歌曲名称 (#156)
|
||||
|
||||
### Fix
|
||||
|
||||
- 修复插件示例报错 #105
|
||||
- 修复当前播放歌曲没保存的问题 #90
|
||||
|
||||
## v0.3.30 (2024-09-07)
|
||||
|
||||
### Feat
|
||||
|
||||
- 修改设置按钮位置
|
||||
- 新增网页播放接口 #138
|
||||
|
||||
## v0.3.29 (2024-09-06)
|
||||
|
||||
### Feat
|
||||
|
||||
69
README.md
69
README.md
@@ -17,7 +17,16 @@
|
||||
|
||||
## 最简配置运行
|
||||
|
||||
已经支持在 web 页面配置其他参数,docker compose 配置如下:
|
||||
已经支持在 web 页面配置其他参数,docker 启动命令如下:
|
||||
|
||||
```bash
|
||||
docker run -p 8090:8090 \
|
||||
-v /xiaomusic/music:/app/music \
|
||||
-v /xiaomusic/conf:/app/conf \
|
||||
hanxi/xiaomusic
|
||||
```
|
||||
|
||||
对应的 docker compose 配置如下:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
@@ -28,22 +37,17 @@ services:
|
||||
ports:
|
||||
- 8090:8090
|
||||
volumes:
|
||||
- ./music:/app/music
|
||||
- ./conf:/app/conf
|
||||
```
|
||||
|
||||
对应的 docker 启动命令如下:
|
||||
|
||||
```yaml
|
||||
docker run -p 8090:8090 \
|
||||
-v ./music:/app/music \
|
||||
-v ./conf:/app/conf \
|
||||
hanxi/xiaomusic
|
||||
- /xiaomusic/music:/app/music
|
||||
- /xiaomusic/conf:/app/conf
|
||||
```
|
||||
|
||||
其中 conf 目录为配置文件存放目录,music 目录为音乐存放目录,建议分开配置为不同的目录。
|
||||
|
||||
启动成功后,在 web 页面可以配置其他参数,带有 `*` 号的配置是必须要配置的,其他的用不上时不用修改。初次配置时需要在页面上输入小米账号和密码保存后才能获取到设备列表。
|
||||
> 上面配置的 /xiaomusic/music 和 /xiaomusic/conf 是 docker 主机里的 /xiaomusic 目录下的,可以修改为其他目录。如果报错找不到 /xiaomusic/music 目录,可以先执行 `mkdir -p /xiaomusic/{music,conf}` 命令新建目录。
|
||||
|
||||
docker 和 docker compose 二选一即可,启动成功后,在 web 页面可以配置其他参数,带有 `*` 号的配置是必须要配置的,其他的用不上时不用修改。初次配置时需要在页面上输入小米账号和密码保存后才能获取到设备列表。
|
||||
|
||||
> 目前安装步骤已经是最简化了,如果还是嫌安装麻烦,可以微信或者 QQ 约我远程安装,我一般周末和晚上才有时间,收个辛苦费 :moneybag: 50 元一次,安装失败不收费。
|
||||
|
||||
### 修改默认8090端口映射
|
||||
|
||||
@@ -58,13 +62,13 @@ services:
|
||||
ports:
|
||||
- 5678:5678
|
||||
volumes:
|
||||
- ./music:/app/music
|
||||
- ./conf:/app/conf
|
||||
- /xiaomusic/music:/app/music
|
||||
- /xiaomusic/conf:/app/conf
|
||||
environment:
|
||||
XIAOMUSIC_PORT: 5678
|
||||
```
|
||||
|
||||
如果不是首次修改端口,还需要修改 setting.json 文件里的端口。
|
||||
如果不是首次修改端口,还需要修改 /xiaomusic/conf/setting.json 文件里的端口。
|
||||
|
||||
遇到问题可以去 web 设置页面底部点击【下载日志文件】按钮,然后搜索一下日志文件内容确保里面没有账号密码信息后(有就删除这些敏感信息),然后在提 issues 反馈问题时把下载的日志文件带上。
|
||||
|
||||
@@ -80,7 +84,7 @@ services:
|
||||
\ / | | / _` | / _ \ | |\/| | | | | | / __| | | / __|
|
||||
/ \ | | | (_| | | (_) | | | | | | |_| | \__ \ | | | (__
|
||||
/_/\_\ |_| \__,_| \___/ |_| |_| \__,_| |___/ |_| \___|
|
||||
XiaoMusic v0.3.28 by: github.com/hanxi
|
||||
XiaoMusic v0.3.29 by: github.com/hanxi
|
||||
|
||||
usage: xiaomusic [-h] [--port PORT] [--hardware HARDWARE] [--account ACCOUNT]
|
||||
[--password PASSWORD] [--cookie COOKIE] [--verbose]
|
||||
@@ -135,6 +139,10 @@ docker build -t xiaomusic .
|
||||
- 停止播放
|
||||
- 刷新列表
|
||||
- 播放列表+列表名 比如:播放列表其他
|
||||
- 加入收藏
|
||||
- 取消收藏
|
||||
- 播放列表收藏
|
||||
- 播放本地歌曲+歌名
|
||||
|
||||
> 隐藏玩法: 对小爱同学说播放歌曲小猪佩奇的故事,会播放小猪佩奇的故事。
|
||||
|
||||
@@ -153,13 +161,14 @@ docker build -t xiaomusic .
|
||||
| LX01 | [小爱音箱mini](https://home.mi.com/baike/index.html#/detail?model=xiaomi.wifispeaker.lx01) |
|
||||
| L05B | [小爱音箱Play](https://home.mi.com/baike/index.html#/detail?model=xiaomi.wifispeaker.l05b) |
|
||||
| L05C | [小米小爱音箱Play 增强版](https://home.mi.com/baike/index.html#/detail?model=xiaomi.wifispeaker.l05c) |
|
||||
| L09A | [小米音箱Art](https://home.mi.com/webapp/content/baike/product/index.html?model=xiaomi.wifispeaker.l09a) |
|
||||
| LX04 X10A X08A | 已经支持的触屏版 |
|
||||
|
||||
型号与产品名称对照可以在这里查询 <https://home.miot-spec.com/s/xiaomi.wifispeaker>
|
||||
|
||||
> 如果你的设备支持播放,请反馈给我添加到支持列表里,谢谢。
|
||||
> 目前应该所有设备类型都已经支持播放,有问题随时反馈。
|
||||
> 其他触屏版不能播放可以设置 XIAOMUSIC_USE_MUSIC_API 为 true 试试。
|
||||
> 其他触屏版不能播放可以设置【触屏版兼容模式】选项为 true 试试。见 <https://github.com/hanxi/xiaomusic/issues/30>
|
||||
|
||||
## 支持音乐格式
|
||||
|
||||
@@ -192,16 +201,7 @@ docker build -t xiaomusic .
|
||||
|
||||
采用新的设置页面之后,没有必须在启动前配置的环境变量了,除非是改默认的 8090 端口才需要配置环境变量。
|
||||
|
||||
后台的 XIAOMUSIC_PROXY 参数格式参考 yt-dlp 文档说明:
|
||||
```
|
||||
Use the specified HTTP/HTTPS/SOCKS proxy. To
|
||||
enable SOCKS proxy, specify a proper scheme,
|
||||
e.g. socks5://user:pass@127.0.0.1:1080/.
|
||||
Pass in an empty string (--proxy "") for
|
||||
direct connection
|
||||
```
|
||||
|
||||
见 <https://github.com/hanxi/xiaomusic/issues/2> 和 <https://github.com/hanxi/xiaomusic/issues/11>
|
||||
后台的
|
||||
|
||||
## 网络歌单功能
|
||||
|
||||
@@ -227,6 +227,12 @@ direct connection
|
||||
- XIAOMUSIC_FUZZY_MATCH_CUTOFF 设置模糊搜索匹配的最低相似度阈值(默认0.6,可以配0到1直接的小数),越小越模糊,越大越精准,对应后台的 【模糊匹配阈值】。具体见 <https://github.com/hanxi/xiaomusic/issues/52>
|
||||
- XIAOMUSIC_PUBLIC_PORT 用于设置外网端口,对应后台的 【外网访问端口】,当使用反向代理时可以设置为外网端口,XIAOMUSIC_HOSTNAME 设为外网IP或者域名即可。
|
||||
- XIAOMUSIC_DOWNLOAD_PATH 变量可以配置下载目录,默认为空,表示使用 music 目录为下载目录,对应后台的 【音乐下载目录】。设置这个目录必须是 music 的子目录,否则刷新列表后会找不到歌曲。具体见 <https://github.com/hanxi/xiaomusic/issues/98>
|
||||
- XIAOMUSIC_PROXY 用于配置国内使用 youtube 源下载歌曲时使用的代理,参数格式参考 yt-dlp 文档说明。 见 <https://github.com/hanxi/xiaomusic/issues/2> 和 <https://github.com/hanxi/xiaomusic/issues/11>
|
||||
|
||||
|
||||
### :warning: 安全提醒
|
||||
|
||||
- 如果配置了公网访问 xiaomusic ,请一定要开启密码登陆,并设置复杂的密码。且不要在公共场所的 WiFi 环境下使用,否则可能造成小米账号密码泄露。
|
||||
|
||||
## 高级篇
|
||||
|
||||
@@ -250,6 +256,7 @@ direct connection
|
||||
- [NAS部署教程](https://post.m.smzdm.com/p/avpe7n99/)
|
||||
- [群晖部署教程](https://post.m.smzdm.com/p/a7px7dol/)
|
||||
- [QNAS部署教程](https://post.smzdm.com/p/a5xz5x63/)
|
||||
- [视频教程](https://www.bilibili.com/video/BV1ZZpweHEtT/)
|
||||
- 所有帮忙调试和测试的朋友
|
||||
- 所有反馈问题和建议的朋友
|
||||
|
||||
@@ -259,6 +266,6 @@ direct connection
|
||||
|
||||
## 赞赏
|
||||
|
||||
- 爱发电 <https://afdian.com/a/imhanxi>
|
||||
- 点个 Star ⭐
|
||||
- 谢谢 ❤️
|
||||
- :moneybag: 爱发电 <https://afdian.com/a/imhanxi>
|
||||
- 点个 Star :star:
|
||||
- 谢谢 :heart:
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
async def code1(arg1):
|
||||
global log, xiaomusic
|
||||
log.info(f"code1:{arg1}")
|
||||
await xiaomusic.do_tts("你好,我是自定义的测试口令")
|
||||
did = xiaomusic._cur_did
|
||||
await xiaomusic.do_tts(did, "你好,我是自定义的测试口令")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "xiaomusic"
|
||||
version = "0.3.29"
|
||||
version = "0.3.31"
|
||||
description = "Play Music with xiaomi AI speaker"
|
||||
authors = [
|
||||
{name = "涵曦", email = "im.hanxi@gmail.com"},
|
||||
|
||||
@@ -1 +1 @@
|
||||
__version__ = "0.3.29"
|
||||
__version__ = "0.3.31"
|
||||
|
||||
@@ -16,6 +16,7 @@ def default_key_word_dict():
|
||||
"播放本地歌曲": "playlocal",
|
||||
"关机": "stop",
|
||||
"下一首": "play_next",
|
||||
"上一首": "play_prev",
|
||||
"单曲循环": "set_play_type_one",
|
||||
"全部循环": "set_play_type_all",
|
||||
"随机播放": "set_random_play",
|
||||
@@ -46,6 +47,7 @@ def default_key_match_order():
|
||||
"分钟后关机",
|
||||
"播放歌曲",
|
||||
"下一首",
|
||||
"上一首",
|
||||
"单曲循环",
|
||||
"全部循环",
|
||||
"随机播放",
|
||||
|
||||
@@ -205,6 +205,16 @@ async def musiclist(Verifcation=Depends(verification)):
|
||||
return xiaomusic.get_music_list()
|
||||
|
||||
|
||||
@app.get("/musicinfo")
|
||||
async def musicinfo(name: str, Verifcation=Depends(verification)):
|
||||
url = xiaomusic.get_music_url(name)
|
||||
return {
|
||||
"ret": "OK",
|
||||
"name": name,
|
||||
"url": url,
|
||||
}
|
||||
|
||||
|
||||
@app.get("/curplaylist")
|
||||
async def curplaylist(did: str = "", Verifcation=Depends(verification)):
|
||||
if not xiaomusic.did_exist(did):
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
$(function(){
|
||||
$container=$("#cmds");
|
||||
|
||||
append_op_button_name("加入收藏");
|
||||
append_op_button_name("取消收藏");
|
||||
|
||||
const PLAY_TYPE_ONE = 0; // 单曲循环
|
||||
const PLAY_TYPE_ALL = 1; // 全部循环
|
||||
const PLAY_TYPE_RND = 2; // 随机播放
|
||||
@@ -8,12 +11,11 @@ $(function(){
|
||||
append_op_button("play_type_one", "单曲循环", "单曲循环");
|
||||
append_op_button("play_type_rnd", "随机播放", "随机播放");
|
||||
|
||||
append_op_button_name("刷新列表");
|
||||
append_op_button_name("下一首");
|
||||
append_op_button_name("上一首");
|
||||
append_op_button_name("关机");
|
||||
append_op_button_name("下一首");
|
||||
|
||||
append_op_button_name("加入收藏");
|
||||
append_op_button_name("取消收藏");
|
||||
append_op_button_name("刷新列表");
|
||||
|
||||
$container.append($("<hr>"));
|
||||
|
||||
@@ -98,9 +100,9 @@ $(function(){
|
||||
|
||||
$('#music_list').change(function() {
|
||||
const selectedValue = $(this).val();
|
||||
localStorage.setItem('cur_playlist', selectedValue);
|
||||
$('#music_name').empty();
|
||||
const sorted_musics = data[selectedValue].sort(custom_sort_key);
|
||||
$.each(sorted_musics, function(index, item) {
|
||||
$.each(data[selectedValue], function(index, item) {
|
||||
$('#music_name').append($('<option></option>').val(item).text(item));
|
||||
});
|
||||
});
|
||||
@@ -108,10 +110,17 @@ $(function(){
|
||||
$('#music_list').trigger('change');
|
||||
|
||||
// 获取当前播放列表
|
||||
$.get(`curplaylist?did=${did}`, function(data, status) {
|
||||
if (data != "") {
|
||||
$('#music_list').val(data);
|
||||
$.get(`curplaylist?did=${did}`, function(playlist, status) {
|
||||
if (playlist != "") {
|
||||
$('#music_list').val(playlist);
|
||||
$('#music_list').trigger('change');
|
||||
} else {
|
||||
// 使用本地记录的
|
||||
playlist = localStorage.getItem('cur_playlist');
|
||||
if (data.includes(playlist)) {
|
||||
$('#music_list').val(playlist);
|
||||
$('#music_list').trigger('change');
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -130,6 +139,17 @@ $(function(){
|
||||
sendcmd(cmd);
|
||||
});
|
||||
|
||||
$("#web_play").on("click", () => {
|
||||
const music_name = $("#music_name").val();
|
||||
$.get(`/musicinfo?name=${music_name}`, function(data, status) {
|
||||
console.log(data);
|
||||
if (data.ret == "OK") {
|
||||
const music = new Audio(data.url);
|
||||
music.play();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#del_music").on("click", () => {
|
||||
var del_music_name = $("#music_name").val();
|
||||
if (confirm(`确定删除歌曲 ${del_music_name} 吗?`)) {
|
||||
@@ -254,23 +274,4 @@ $(function(){
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function custom_sort_key(a, b) {
|
||||
// 使用正则表达式提取数字前缀
|
||||
const numericPrefixA = a.match(/^(\d+)/) ? parseInt(a.match(/^(\d+)/)[1], 10) : null;
|
||||
const numericPrefixB = b.match(/^(\d+)/) ? parseInt(b.match(/^(\d+)/)[1], 10) : null;
|
||||
|
||||
// 如果两个键都有数字前缀,则按数字大小排序
|
||||
if (numericPrefixA !== null && numericPrefixB !== null) {
|
||||
return numericPrefixA - numericPrefixB;
|
||||
}
|
||||
|
||||
// 如果一个键有数字前缀而另一个没有,则有数字前缀的键排在前面
|
||||
if (numericPrefixA !== null) return -1;
|
||||
if (numericPrefixB !== null) return 1;
|
||||
|
||||
// 如果两个键都没有数字前缀,则按照常规字符串排序
|
||||
return a.localeCompare(b);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<title>Debug For XiaoMusic</title>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="/static/style.css?version=1725646067">
|
||||
<link rel="stylesheet" type="text/css" href="/static/style.css?version=1725986534">
|
||||
<script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script>
|
||||
<script src="/static/jquery-3.7.1.min.js?version=1725646067"></script>
|
||||
<script src="/static/jquery-3.7.1.min.js?version=1725986534"></script>
|
||||
|
||||
<script>
|
||||
var vConsole = new window.VConsole();
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<title>小爱音箱操控面板</title>
|
||||
<script src="/static/jquery-3.7.1.min.js?version=1725646067"></script>
|
||||
<script src="/static/app.js?version=1725646067"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/static/style.css?version=1725646067">
|
||||
<script src="/static/jquery-3.7.1.min.js?version=1725986534"></script>
|
||||
<script src="/static/app.js?version=1725986534"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/static/style.css?version=1725986534">
|
||||
|
||||
<!--
|
||||
<script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script>
|
||||
@@ -29,15 +29,14 @@ var vConsole = new window.VConsole();
|
||||
</div>
|
||||
|
||||
<div id="cmds">
|
||||
<a class="button" href="/static/setting.html">设置</a>
|
||||
</div>
|
||||
<hr>
|
||||
|
||||
<div style="margin: 20px;">
|
||||
<div style="display: flex; align-items: center;">
|
||||
<svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" fill="#8e43e7" style="height: 48px; width: 48px;"><path d="M550.826667 154.666667a47.786667 47.786667 0 0 0-19.84 4.48L298.666667 298.666667H186.453333A80 80 0 0 0 106.666667 378.453333v267.093334A80 80 0 0 0 186.453333 725.333333H298.666667l232.32 139.52a47.786667 47.786667 0 0 0 19.84 4.48A46.506667 46.506667 0 0 0 597.333333 822.826667V201.173333a46.506667 46.506667 0 0 0-46.506666-46.506666zM554.666667 822.826667c0 3.413333-3.84 3.84-3.84 3.84L320 688.853333l-9.6-6.186666H186.453333A37.12 37.12 0 0 1 149.333333 645.546667V378.453333A37.12 37.12 0 0 1 186.453333 341.333333h123.946667l10.24-6.186666 229.546667-137.6s3.84 0 3.84 3.84zM667.52 346.026667a21.333333 21.333333 0 0 0 0 30.293333 192 192 0 0 1 0 271.36 21.333333 21.333333 0 0 0 0 30.293333 21.333333 21.333333 0 0 0 30.293333 0 234.666667 234.666667 0 0 0 0-331.946666 21.333333 21.333333 0 0 0-30.293333 0z"></path><path d="M804.48 219.52a21.333333 21.333333 0 0 0-30.293333 30.293333 370.986667 370.986667 0 0 1 0 524.373334 21.333333 21.333333 0 0 0 0 30.293333 21.333333 21.333333 0 0 0 30.293333 0 414.08 414.08 0 0 0 0-584.96z"></path></svg>
|
||||
<input id="volume" type="range"></input>
|
||||
<a href="/static/setting.html">
|
||||
<svg fill="#8e43e7" height="48px" width="48px" version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-11.88 -11.88 77.76 77.76" xml:space="preserve" stroke="#8e43e7" transform="rotate(0)matrix(1, 0, 0, 1, 0, 0)" stroke-width="0.00054"><g id="SVGRepo_bgCarrier" stroke-width="0" transform="translate(0,0), scale(1)"><rect x="-11.88" y="-11.88" width="77.76" height="77.76" rx="18.6624" fill="#addcff" strokewidth="0"></rect></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round" stroke="#CCCCCC" stroke-width="1.512"></g><g id="SVGRepo_iconCarrier"> <g> <path d="M51.22,21h-5.052c-0.812,0-1.481-0.447-1.792-1.197s-0.153-1.54,0.42-2.114l3.572-3.571 c0.525-0.525,0.814-1.224,0.814-1.966c0-0.743-0.289-1.441-0.814-1.967l-4.553-4.553c-1.05-1.05-2.881-1.052-3.933,0l-3.571,3.571 c-0.574,0.573-1.366,0.733-2.114,0.421C33.447,9.313,33,8.644,33,7.832V2.78C33,1.247,31.753,0,30.22,0H23.78 C22.247,0,21,1.247,21,2.78v5.052c0,0.812-0.447,1.481-1.197,1.792c-0.748,0.313-1.54,0.152-2.114-0.421l-3.571-3.571 c-1.052-1.052-2.883-1.05-3.933,0l-4.553,4.553c-0.525,0.525-0.814,1.224-0.814,1.967c0,0.742,0.289,1.44,0.814,1.966l3.572,3.571 c0.573,0.574,0.73,1.364,0.42,2.114S8.644,21,7.832,21H2.78C1.247,21,0,22.247,0,23.78v6.439C0,31.753,1.247,33,2.78,33h5.052 c0.812,0,1.481,0.447,1.792,1.197s0.153,1.54-0.42,2.114l-3.572,3.571c-0.525,0.525-0.814,1.224-0.814,1.966 c0,0.743,0.289,1.441,0.814,1.967l4.553,4.553c1.051,1.051,2.881,1.053,3.933,0l3.571-3.572c0.574-0.573,1.363-0.731,2.114-0.42 c0.75,0.311,1.197,0.98,1.197,1.792v5.052c0,1.533,1.247,2.78,2.78,2.78h6.439c1.533,0,2.78-1.247,2.78-2.78v-5.052 c0-0.812,0.447-1.481,1.197-1.792c0.751-0.312,1.54-0.153,2.114,0.42l3.571,3.572c1.052,1.052,2.883,1.05,3.933,0l4.553-4.553 c0.525-0.525,0.814-1.224,0.814-1.967c0-0.742-0.289-1.44-0.814-1.966l-3.572-3.571c-0.573-0.574-0.73-1.364-0.42-2.114 S45.356,33,46.168,33h5.052c1.533,0,2.78-1.247,2.78-2.78V23.78C54,22.247,52.753,21,51.22,21z M52,30.22 C52,30.65,51.65,31,51.22,31h-5.052c-1.624,0-3.019,0.932-3.64,2.432c-0.622,1.5-0.295,3.146,0.854,4.294l3.572,3.571 c0.305,0.305,0.305,0.8,0,1.104l-4.553,4.553c-0.304,0.304-0.799,0.306-1.104,0l-3.571-3.572c-1.149-1.149-2.794-1.474-4.294-0.854 c-1.5,0.621-2.432,2.016-2.432,3.64v5.052C31,51.65,30.65,52,30.22,52H23.78C23.35,52,23,51.65,23,51.22v-5.052 c0-1.624-0.932-3.019-2.432-3.64c-0.503-0.209-1.021-0.311-1.533-0.311c-1.014,0-1.997,0.4-2.761,1.164l-3.571,3.572 c-0.306,0.306-0.801,0.304-1.104,0l-4.553-4.553c-0.305-0.305-0.305-0.8,0-1.104l3.572-3.571c1.148-1.148,1.476-2.794,0.854-4.294 C10.851,31.932,9.456,31,7.832,31H2.78C2.35,31,2,30.65,2,30.22V23.78C2,23.35,2.35,23,2.78,23h5.052 c1.624,0,3.019-0.932,3.64-2.432c0.622-1.5,0.295-3.146-0.854-4.294l-3.572-3.571c-0.305-0.305-0.305-0.8,0-1.104l4.553-4.553 c0.304-0.305,0.799-0.305,1.104,0l3.571,3.571c1.147,1.147,2.792,1.476,4.294,0.854C22.068,10.851,23,9.456,23,7.832V2.78 C23,2.35,23.35,2,23.78,2h6.439C30.65,2,31,2.35,31,2.78v5.052c0,1.624,0.932,3.019,2.432,3.64 c1.502,0.622,3.146,0.294,4.294-0.854l3.571-3.571c0.306-0.305,0.801-0.305,1.104,0l4.553,4.553c0.305,0.305,0.305,0.8,0,1.104 l-3.572,3.571c-1.148,1.148-1.476,2.794-0.854,4.294c0.621,1.5,2.016,2.432,3.64,2.432h5.052C51.65,23,52,23.35,52,23.78V30.22z"></path> <path d="M27,18c-4.963,0-9,4.037-9,9s4.037,9,9,9s9-4.037,9-9S31.963,18,27,18z M27,34c-3.859,0-7-3.141-7-7s3.141-7,7-7 s7,3.141,7,7S30.859,34,27,34z"></path> </g> </g></svg>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
@@ -60,6 +59,7 @@ var vConsole = new window.VConsole();
|
||||
<div>
|
||||
<button id="play_music_list">播放列表歌曲</button>
|
||||
<button id="del_music">删除选中歌曲</button>
|
||||
<button id="web_play">网页播放</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<title>M3U to JSON Converter</title>
|
||||
<link rel="stylesheet" type="text/css" href="/static/style.css?version=1725646067">
|
||||
<link rel="stylesheet" type="text/css" href="/static/style.css?version=1725986534">
|
||||
<!--
|
||||
<script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script>
|
||||
<script>
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<title>小爱音箱操控面板</title>
|
||||
<script src="/static/jquery-3.7.1.min.js?version=1725646067"></script>
|
||||
<script src="/static/setting.js?version=1725646067"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/static/style.css?version=1725646067">
|
||||
<script src="/static/jquery-3.7.1.min.js?version=1725986534"></script>
|
||||
<script src="/static/setting.js?version=1725986534"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/static/style.css?version=1725986534">
|
||||
|
||||
<!--
|
||||
<script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
import asyncio
|
||||
import copy
|
||||
import json
|
||||
import logging
|
||||
import math
|
||||
@@ -453,6 +454,9 @@ class XiaoMusic:
|
||||
self.log.exception(f"Execption {e}")
|
||||
|
||||
self.music_list["全部"] = list(self.all_music.keys())
|
||||
self.music_list["所有歌曲"] = [
|
||||
name for name in self.all_music.keys() if name not in self._all_radio
|
||||
]
|
||||
|
||||
self._append_custom_play_list()
|
||||
|
||||
@@ -718,6 +722,9 @@ class XiaoMusic:
|
||||
async def play_next(self, did="", **kwargs):
|
||||
return await self.devices[did].play_next()
|
||||
|
||||
async def play_prev(self, did="", **kwargs):
|
||||
return await self.devices[did].play_prev()
|
||||
|
||||
# 停止
|
||||
async def stop(self, did="", arg1="", **kwargs):
|
||||
return await self.devices[did].stop(arg1=arg1)
|
||||
@@ -794,7 +801,7 @@ class XiaoMusic:
|
||||
|
||||
# 正在播放中的音乐
|
||||
def playingmusic(self, did):
|
||||
cur_music = self.devices[did].cur_music
|
||||
cur_music = self.devices[did].get_cur_music()
|
||||
self.log.debug(f"playingmusic. cur_music:{cur_music}")
|
||||
return cur_music
|
||||
|
||||
@@ -836,6 +843,10 @@ class XiaoMusic:
|
||||
|
||||
# 把当前配置落地
|
||||
def save_cur_config(self):
|
||||
for did in self.config.devices.keys():
|
||||
deviceobj = self.devices.get(did)
|
||||
if deviceobj is not None:
|
||||
self.config.devices[did] = deviceobj.device
|
||||
data = asdict(self.config)
|
||||
self.do_saveconfig(data)
|
||||
self.log.info("save_cur_config ok")
|
||||
@@ -909,7 +920,6 @@ class XiaoMusicDevice:
|
||||
self.ffmpeg_location = self.config.ffmpeg_location
|
||||
|
||||
self._download_proc = None # 下载对象
|
||||
self.cur_music = self.device.cur_music
|
||||
self._next_timer = None
|
||||
self._timeout = 0
|
||||
self._playing = False
|
||||
@@ -918,12 +928,21 @@ class XiaoMusicDevice:
|
||||
self._last_cmd = None
|
||||
self.update_playlist()
|
||||
|
||||
def get_cur_music(self):
|
||||
return self.device.cur_music
|
||||
|
||||
# 初始化播放列表
|
||||
def update_playlist(self):
|
||||
self._cur_play_list = self.device.cur_playlist
|
||||
if self._cur_play_list not in self.xiaomusic.music_list:
|
||||
self._cur_play_list = "全部"
|
||||
self._play_list = self.xiaomusic.music_list.get(self._cur_play_list)
|
||||
if self.device.cur_playlist not in self.xiaomusic.music_list:
|
||||
self.device.cur_playlist = "全部"
|
||||
|
||||
list_name = self.device.cur_playlist
|
||||
self._play_list = copy.copy(self.xiaomusic.music_list[list_name])
|
||||
if self.device.play_type == PLAY_TYPE_RND:
|
||||
random.shuffle(self._play_list)
|
||||
self.log.info(f"随机打乱 {list_name} {self._play_list}")
|
||||
else:
|
||||
self.log.info(f"没打乱 {list_name} {self._play_list}")
|
||||
|
||||
# 播放歌曲
|
||||
async def play(self, name="", search_key=""):
|
||||
@@ -936,7 +955,7 @@ class XiaoMusicDevice:
|
||||
await self._play_next()
|
||||
return
|
||||
else:
|
||||
name = self.cur_music
|
||||
name = self.get_cur_music()
|
||||
self.log.info(f"play. search_key:{search_key} name:{name}")
|
||||
|
||||
# 本地歌曲不存在时下载
|
||||
@@ -958,7 +977,7 @@ class XiaoMusicDevice:
|
||||
|
||||
async def _play_next(self):
|
||||
self.log.info("开始播放下一首")
|
||||
name = self.cur_music
|
||||
name = self.get_cur_music()
|
||||
if (
|
||||
self.device.play_type == PLAY_TYPE_ALL
|
||||
or self.device.play_type == PLAY_TYPE_RND
|
||||
@@ -966,7 +985,27 @@ class XiaoMusicDevice:
|
||||
or (name not in self._play_list)
|
||||
):
|
||||
name = self.get_next_music()
|
||||
self.log.info(f"_play_next. name:{name}, cur_music:{self.cur_music}")
|
||||
self.log.info(f"_play_next. name:{name}, cur_music:{self.get_cur_music()}")
|
||||
if name == "":
|
||||
await self.do_tts("本地没有歌曲")
|
||||
return
|
||||
await self._play(name)
|
||||
|
||||
# 上一首
|
||||
async def play_prev(self):
|
||||
return await self._play_prev()
|
||||
|
||||
async def _play_prev(self):
|
||||
self.log.info("开始播放上一首")
|
||||
name = self.get_cur_music()
|
||||
if (
|
||||
self.device.play_type == PLAY_TYPE_ALL
|
||||
or self.device.play_type == PLAY_TYPE_RND
|
||||
or name == ""
|
||||
or (name not in self._play_list)
|
||||
):
|
||||
name = self.get_prev_music()
|
||||
self.log.info(f"_play_prev. name:{name}, cur_music:{self.get_cur_music()}")
|
||||
if name == "":
|
||||
await self.do_tts("本地没有歌曲")
|
||||
return
|
||||
@@ -980,7 +1019,7 @@ class XiaoMusicDevice:
|
||||
await self._play_next()
|
||||
return
|
||||
else:
|
||||
name = self.cur_music
|
||||
name = self.get_cur_music()
|
||||
|
||||
self.log.info(f"playlocal. name:{name}")
|
||||
|
||||
@@ -996,12 +1035,13 @@ class XiaoMusicDevice:
|
||||
self.cancel_group_next_timer()
|
||||
|
||||
self._playing = True
|
||||
self.cur_music = name
|
||||
self.log.info(f"cur_music {self.cur_music}")
|
||||
self.device.cur_music = name
|
||||
|
||||
self.log.info(f"cur_music {self.get_cur_music()}")
|
||||
sec, url = await self.xiaomusic.get_music_sec_url(name)
|
||||
await self.group_force_stop_xiaoai()
|
||||
self.log.info(f"播放 {url}")
|
||||
results = await self.group_player_play(url)
|
||||
results = await self.group_player_play(url, name)
|
||||
if all(ele is None for ele in results):
|
||||
self.log.info(f"播放 {name} 失败")
|
||||
await asyncio.sleep(1)
|
||||
@@ -1017,6 +1057,7 @@ class XiaoMusicDevice:
|
||||
return
|
||||
sec = sec + self.config.delay_sec
|
||||
await self.set_next_music_timeout(sec)
|
||||
self.xiaomusic.save_cur_config()
|
||||
|
||||
async def do_tts(self, value):
|
||||
self.log.info(f"try do_tts value:{value}")
|
||||
@@ -1030,7 +1071,7 @@ class XiaoMusicDevice:
|
||||
# 最大等8秒
|
||||
sec = min(8, int(len(value) / 3))
|
||||
await asyncio.sleep(sec)
|
||||
self.log.info(f"do_tts ok. cur_music:{self.cur_music}")
|
||||
self.log.info(f"do_tts ok. cur_music:{self.get_cur_music()}")
|
||||
await self.check_replay()
|
||||
|
||||
async def force_stop_xiaoai(self, device_id):
|
||||
@@ -1132,51 +1173,62 @@ class XiaoMusicDevice:
|
||||
self.log.info(f"add_download_music add_music {name}")
|
||||
self.log.debug(self._play_list)
|
||||
|
||||
# 获取下一首
|
||||
def get_next_music(self):
|
||||
def get_music(self, direction="next"):
|
||||
play_list_len = len(self._play_list)
|
||||
if play_list_len == 0:
|
||||
self.log.warning("当前播放列表没有歌曲")
|
||||
return ""
|
||||
index = 0
|
||||
try:
|
||||
index = self._play_list.index(self.cur_music)
|
||||
index = self._play_list.index(self.get_cur_music())
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
if play_list_len == 1:
|
||||
next_index = index # 当只有一首歌曲时保持当前索引不变
|
||||
new_index = index # 当只有一首歌曲时保持当前索引不变
|
||||
else:
|
||||
# 顺序往后找1个
|
||||
next_index = index + 1
|
||||
if next_index >= play_list_len:
|
||||
next_index = 0
|
||||
# 排除当前歌曲随机找1个
|
||||
if self.device.play_type == PLAY_TYPE_RND:
|
||||
indices = list(range(play_list_len))
|
||||
indices.remove(index)
|
||||
next_index = random.choice(indices)
|
||||
name = self._play_list[next_index]
|
||||
if direction == "next":
|
||||
new_index = index + 1
|
||||
if new_index >= play_list_len:
|
||||
new_index = 0
|
||||
elif direction == "prev":
|
||||
new_index = index - 1
|
||||
if new_index < 0:
|
||||
new_index = play_list_len - 1
|
||||
else:
|
||||
self.log.error("无效的方向参数")
|
||||
return ""
|
||||
|
||||
name = self._play_list[new_index]
|
||||
if not self.xiaomusic.is_music_exist(name):
|
||||
self._play_list.pop(next_index)
|
||||
self.log.info(f"pop not exist music:{name}")
|
||||
return self.get_next_music()
|
||||
self._play_list.pop(new_index)
|
||||
self.log.info(f"pop not exist music: {name}")
|
||||
return self.get_music(direction)
|
||||
return name
|
||||
|
||||
# 获取下一首
|
||||
def get_next_music(self):
|
||||
return self.get_music(direction="next")
|
||||
|
||||
# 获取上一首
|
||||
def get_prev_music(self):
|
||||
return self.get_music(direction="prev")
|
||||
|
||||
# 判断是否播放下一首歌曲
|
||||
def check_play_next(self):
|
||||
# 当前歌曲不在当前播放列表
|
||||
if self.cur_music not in self._play_list:
|
||||
self.log.info(f"当前歌曲 {self.cur_music} 不在当前播放列表")
|
||||
if self.get_cur_music() not in self._play_list:
|
||||
self.log.info(f"当前歌曲 {self.get_cur_music()} 不在当前播放列表")
|
||||
return True
|
||||
|
||||
# 当前没我在播放的歌曲
|
||||
if self.cur_music == "":
|
||||
if self.get_cur_music() == "":
|
||||
self.log.info("当前没我在播放的歌曲")
|
||||
return True
|
||||
else:
|
||||
# 当前播放的歌曲不存在了
|
||||
if not self.xiaomusic.is_music_exist(self.cur_music):
|
||||
self.log.info(f"当前播放的歌曲 {self.cur_music} 不存在了")
|
||||
if not self.xiaomusic.is_music_exist(self.get_cur_music()):
|
||||
self.log.info(f"当前播放的歌曲 {self.get_cur_music()} 不存在了")
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -1187,22 +1239,25 @@ class XiaoMusicDevice:
|
||||
self.log.exception(f"Execption {e}")
|
||||
|
||||
# 同一组设备播放
|
||||
async def group_player_play(self, url):
|
||||
async def group_player_play(self, url, name=""):
|
||||
device_id_list = self.xiaomusic.get_group_device_id_list(self.group_name)
|
||||
tasks = [self.play_one_url(device_id, url) for device_id in device_id_list]
|
||||
tasks = [
|
||||
self.play_one_url(device_id, url, name) for device_id in device_id_list
|
||||
]
|
||||
results = await asyncio.gather(*tasks)
|
||||
self.log.info(f"group_player_play {url} {device_id_list} {results}")
|
||||
return results
|
||||
|
||||
async def play_one_url(self, device_id, url):
|
||||
async def play_one_url(self, device_id, url, name):
|
||||
ret = None
|
||||
try:
|
||||
audio_id = await self._get_audio_id(name)
|
||||
if self.config.use_music_api:
|
||||
ret = await self.xiaomusic.mina_service.play_by_music_url(
|
||||
device_id, url
|
||||
device_id, url, audio_id=audio_id
|
||||
)
|
||||
self.log.info(
|
||||
f"play_one_url play_by_music_url device_id:{device_id} ret:{ret} url:{url}"
|
||||
f"play_one_url play_by_music_url device_id:{device_id} ret:{ret} url:{url} audio_id:{audio_id}"
|
||||
)
|
||||
else:
|
||||
ret = await self.xiaomusic.mina_service.play_by_url(device_id, url)
|
||||
@@ -1213,6 +1268,27 @@ class XiaoMusicDevice:
|
||||
self.log.exception(f"Execption {e}")
|
||||
return ret
|
||||
|
||||
async def _get_audio_id(self, name):
|
||||
audio_id = 1582971365183456177
|
||||
try:
|
||||
params = {
|
||||
"query": name,
|
||||
"queryType": 1,
|
||||
"offset": 0,
|
||||
"count": 6,
|
||||
"timestamp": int(time.time_ns() / 1000),
|
||||
}
|
||||
response = await self.xiaomusic.mina_service.mina_request(
|
||||
"/music/search", params
|
||||
)
|
||||
audio_id = response["data"]["songList"][5][
|
||||
"audioID"
|
||||
] # QQ音乐为搜索结果的第6首歌
|
||||
self.log.debug(f"_get_audio_id. name: {name} songId:{audio_id}")
|
||||
except Exception as e:
|
||||
self.log.error(f"_get_audio_id {e}")
|
||||
return str(audio_id)
|
||||
|
||||
# 设置下一首歌曲的播放定时器
|
||||
async def set_next_music_timeout(self, sec):
|
||||
self.cancel_next_timer()
|
||||
@@ -1254,11 +1330,12 @@ class XiaoMusicDevice:
|
||||
self.xiaomusic.save_cur_config()
|
||||
tts = PLAY_TYPE_TTS[play_type]
|
||||
await self.do_tts(tts)
|
||||
self.update_playlist()
|
||||
|
||||
async def play_music_list(self, list_name, music_name):
|
||||
self._last_cmd = "play_music_list"
|
||||
self._cur_play_list = list_name
|
||||
self._play_list = self.xiaomusic.music_list[list_name]
|
||||
self.device.cur_playlist = list_name
|
||||
self.update_playlist()
|
||||
self.log.info(f"开始播放列表{list_name}")
|
||||
await self._play(music_name)
|
||||
|
||||
@@ -1308,7 +1385,7 @@ class XiaoMusicDevice:
|
||||
device.cancel_next_timer()
|
||||
|
||||
def get_cur_play_list(self):
|
||||
return self._cur_play_list
|
||||
return self.device.cur_playlist
|
||||
|
||||
# 清空所有定时器
|
||||
def cancel_all_timer(self):
|
||||
|
||||
Reference in New Issue
Block a user