Skip to content

Commit

Permalink
feat: 新增最近新增歌单 close #273
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxi committed Dec 3, 2024
1 parent 8c92afd commit 733c44d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions xiaomusic/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ class Config:
play_type_seq_tts_msg: str = os.getenv(
"XIAOMUSIC_PLAY_TYPE_SEQ_TTS_MSG", "已经设置为顺序播放"
)
recently_added_playlist_len: int = int(
os.getenv("XIAOMUSIC_RECENTLY_ADDED_PLAYLIST_LEN", "50")
)

def append_keyword(self, keys, action):
for key in keys.split(","):
Expand Down
3 changes: 3 additions & 0 deletions xiaomusic/static/default/setting.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ <h2>小爱音箱设置面板
<option value="false" selected>false</option>
</select>

<label for="recently_added_playlist_len">最近新增的歌曲数量:</label>
<input id="recently_added_playlist_len" type="number" value="50" />

<label for="music_list_url">歌单地址:</label>
<input id="music_list_url" type="text" value="https://gist.githubusercontent.com/hanxi/dda82d964a28f8110f8fba81c3ff8314/raw/example.json" />

Expand Down
18 changes: 13 additions & 5 deletions xiaomusic/xiaomusic.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,13 +641,15 @@ def _gen_all_music_list(self):
"全部": [], # 包含所有歌曲和所有电台
"下载": [], # 下载目录下的
"其他": [], # 主目录下的
"最近新增": [], # 按文件时间排序
}
)
# 全部,所有,自定义歌单(收藏)
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.music_list["最近新增"] = sorted(
self.all_music.keys(),
key=lambda x: os.path.getctime(self.all_music[x]),
reverse=True,
)[: self.config.recently_added_playlist_len]

# 网络歌单
try:
Expand All @@ -656,6 +658,12 @@ def _gen_all_music_list(self):
except Exception as e:
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
]

# 文件夹歌单
for dir_name, musics in all_music_by_dir.items():
self.music_list[dir_name] = list(musics.keys())
Expand Down

0 comments on commit 733c44d

Please sign in to comment.