Skip to content

Commit

Permalink
feat: 新增单曲播放和顺序播放功能 close #277
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxi committed Nov 28, 2024
1 parent 93d2047 commit def63b2
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 79 deletions.
94 changes: 35 additions & 59 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies = [
"aiohttp>=3.8.6",
"miservice-fork>=2.7.0",
"mutagen>=1.47.0",
"yt-dlp>=2024.07.01",
"yt-dlp>=2024.11.18",
"uvicorn>=0.30.1",
"fastapi>=0.115.4",
"starlette>=0.37.2",
Expand Down
20 changes: 18 additions & 2 deletions xiaomusic/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
PLAY_TYPE_ALL,
PLAY_TYPE_ONE,
PLAY_TYPE_RND,
PLAY_TYPE_SEQ,
PLAY_TYPE_SIN,
)
from xiaomusic.utils import validate_proxy

Expand All @@ -21,7 +23,9 @@ def default_key_word_dict():
"上一首": "play_prev",
"单曲循环": "set_play_type_one",
"全部循环": "set_play_type_all",
"随机播放": "set_random_play",
"随机播放": "set_play_type_rnd",
"单曲播放": "set_play_type_sin",
"顺序播放": "set_play_type_seq",
"分钟后关机": "stop_after_minute",
"刷新列表": "gen_music_list",
"加入收藏": "add_to_favorites",
Expand Down Expand Up @@ -53,6 +57,8 @@ def default_key_match_order():
"单曲循环",
"全部循环",
"随机播放",
"单曲播放",
"顺序播放",
"关机",
"刷新列表",
"播放列表第",
Expand Down Expand Up @@ -98,7 +104,7 @@ class Config:
ffmpeg_location: str = os.getenv("XIAOMUSIC_FFMPEG_LOCATION", "./ffmpeg/bin")
active_cmd: str = os.getenv(
"XIAOMUSIC_ACTIVE_CMD",
"play,set_random_play,playlocal,play_music_list,play_music_list_index,stop_after_minute,stop",
"play,set_play_type_rnd,playlocal,play_music_list,play_music_list_index,stop_after_minute,stop",
)
exclude_dirs: str = os.getenv("XIAOMUSIC_EXCLUDE_DIRS", "@eaDir,tmp")
music_path_depth: int = int(os.getenv("XIAOMUSIC_MUSIC_PATH_DEPTH", "10"))
Expand Down Expand Up @@ -175,6 +181,12 @@ class Config:
play_type_rnd_tts_msg: str = os.getenv(
"XIAOMUSIC_PLAY_TYPE_RND_TTS_MSG", "已经设置为随机播放"
)
play_type_sin_tts_msg: str = os.getenv(
"XIAOMUSIC_PLAY_TYPE_SIN_TTS_MSG", "已经设置为单曲播放"
)
play_type_seq_tts_msg: str = os.getenv(
"XIAOMUSIC_PLAY_TYPE_SEQ_TTS_MSG", "已经设置为顺序播放"
)

def append_keyword(self, keys, action):
for key in keys.split(","):
Expand Down Expand Up @@ -302,4 +314,8 @@ def get_play_type_tts(self, play_type):
return self.play_type_all_tts_msg
if play_type == PLAY_TYPE_RND:
return self.play_type_rnd_tts_msg
if play_type == PLAY_TYPE_SIN:
return self.play_type_sin_tts_msg
if play_type == PLAY_TYPE_SEQ:
return self.play_type_seq_tts_msg
return ""
2 changes: 2 additions & 0 deletions xiaomusic/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
PLAY_TYPE_ONE = 0 # 单曲循环
PLAY_TYPE_ALL = 1 # 全部循环
PLAY_TYPE_RND = 2 # 随机播放
PLAY_TYPE_SIN = 3 # 单曲播放
PLAY_TYPE_SEQ = 4 # 顺序播放

# 需要采用 mina 获取对话记录的设备型号
GET_ASK_BY_MINA = {
Expand Down
20 changes: 15 additions & 5 deletions xiaomusic/static/default/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ $(function(){
append_op_button_name("加入收藏");
append_op_button_name("取消收藏");

append_op_button_name("上一首");
append_op_button_name("关机");
append_op_button_name("下一首");

const PLAY_TYPE_ONE = 0; // 单曲循环
const PLAY_TYPE_ALL = 1; // 全部循环
const PLAY_TYPE_RND = 2; // 随机播放
const PLAY_TYPE_SIN = 3; // 单曲播放
const PLAY_TYPE_SEQ = 4; // 顺序播放
append_op_button("play_type_all", "全部循环", "全部循环");
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("play_type_sin", "单曲播放", "单曲播放");
append_op_button("play_type_seq", "顺序播放", "顺序播放");

append_op_button_name("刷新列表");

Expand Down Expand Up @@ -71,6 +75,12 @@ $(function(){
} else if (cur_device.play_type == PLAY_TYPE_RND) {
$("#play_type_rnd").css('background-color', '#b1a8f3');
$("#play_type_rnd").text('✔️ 随机播放');
} else if (cur_device.play_type == PLAY_TYPE_SIN) {
$("#play_type_sin").css('background-color', '#b1a8f3');
$("#play_type_sin").text('✔️ 单曲播放');
} else if (cur_device.play_type == PLAY_TYPE_SEQ) {
$("#play_type_seq").css('background-color', '#b1a8f3');
$("#play_type_seq").text('✔️ 顺序播放');
}
}
}
Expand Down Expand Up @@ -298,7 +308,7 @@ $(function(){
if (cmd == "刷新列表") {
check_status_refresh_music_list(3); // 最多重试3次
}
if (["全部循环", "单曲循环", "随机播放"].includes(cmd)) {
if (["全部循环", "单曲循环", "随机播放", "单曲播放", "顺序播放"].includes(cmd)) {
location.reload();
}
},
Expand Down
4 changes: 2 additions & 2 deletions xiaomusic/static/default/debug.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<meta name="viewport" content="width=device-width">
<title>Debug For XiaoMusic</title>

<link rel="stylesheet" type="text/css" href="./style.css?version=1732033916">
<link rel="stylesheet" type="text/css" href="./style.css?version=1732788412">
<script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script>
<script src="./jquery-3.7.1.min.js?version=1732033916"></script>
<script src="./jquery-3.7.1.min.js?version=1732788412"></script>

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-Z09NC1K7ZW"></script>
Expand Down
4 changes: 2 additions & 2 deletions xiaomusic/static/default/downloadtool.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>歌曲下载工具</title>
<link rel="stylesheet" type="text/css" href="./style.css?version=1732033916">
<script src="./jquery-3.7.1.min.js?version=1732033916"></script>
<link rel="stylesheet" type="text/css" href="./style.css?version=1732788412">
<script src="./jquery-3.7.1.min.js?version=1732788412"></script>

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-Z09NC1K7ZW"></script>
Expand Down
6 changes: 3 additions & 3 deletions xiaomusic/static/default/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width">
<title>小爱音箱操控面板</title>
<script src="./jquery-3.7.1.min.js?version=1732033916"></script>
<script src="./app.js?version=1732033916"></script>
<link rel="stylesheet" type="text/css" href="./style.css?version=1732033916">
<script src="./jquery-3.7.1.min.js?version=1732788412"></script>
<script src="./app.js?version=1732788412"></script>
<link rel="stylesheet" type="text/css" href="./style.css?version=1732788412">

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-Z09NC1K7ZW"></script>
Expand Down
2 changes: 1 addition & 1 deletion xiaomusic/static/default/m3u.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width">
<title>M3U to JSON Converter</title>
<link rel="stylesheet" type="text/css" href="./style.css?version=1732033916">
<link rel="stylesheet" type="text/css" href="./style.css?version=1732788412">

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-Z09NC1K7ZW"></script>
Expand Down
Loading

0 comments on commit def63b2

Please sign in to comment.