Skip to content

Commit

Permalink
启动时生成一次播放列表,修复下一首越界判断问题
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxi committed Feb 24, 2024
1 parent 54b4417 commit 7a32917
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions xiaomusic/xiaomusic.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def __init__(self, config: Config):
self.log.addHandler(RichHandler())
self.log.debug(config)

# 启动时重新生成一次播放列表
self.gen_all_music_list()

async def poll_latest_ask(self):
async with ClientSession() as session:
session._cookie_jar = self.cookie_jar
Expand Down Expand Up @@ -324,6 +327,8 @@ async def download(self, name):

# 本地是否存在歌曲
def get_filename(self, name):
if name not in self._all_music:
return ""
filename = self._all_music[name]
self.log.debug("try get_filename. filename:%s", filename)
if os.path.exists(filename):
Expand Down Expand Up @@ -374,10 +379,6 @@ def add_download_music(self, name):
# 获取下一首
def get_next_music(self):
play_list_len = len(self._play_list)
if play_list_len == 0:
# 尝试重新生成一次播放列表
self.gen_all_music_list()
play_list_len = len(self._play_list)
if play_list_len == 0:
self.log.warning(f"没有随机到歌曲")
return ""
Expand All @@ -388,7 +389,7 @@ def get_next_music(self):
except ValueError:
pass
next_index = index + 1
if next_index > play_list_len:
if next_index >= play_list_len:
next_index = 0
filename = self._play_list[next_index]
return filename
Expand Down

0 comments on commit 7a32917

Please sign in to comment.