fix: download track on !keep when local file is missing

When the initial download failed during playback and the track streamed
directly from URL, !keep would refuse with "No local file". Now it
downloads the track on the spot before keeping it.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
user
2026-02-22 17:01:44 +01:00
parent 6083de13f9
commit 36da191b45
2 changed files with 46 additions and 4 deletions

View File

@@ -1405,8 +1405,20 @@ async def cmd_keep(bot, message):
await bot.reply(message, "Nothing playing")
return
if track.local_path is None:
await bot.reply(message, "No local file for current track")
return
if not track.url:
await bot.reply(message, "No local file for current track")
return
# Download on the spot -- track was streaming without a local file
loop = asyncio.get_running_loop()
tid = hashlib.md5(track.url.encode()).hexdigest()[:12]
dl_path = await loop.run_in_executor(
None, _download_track, track.url, tid, track.title,
)
if dl_path:
track.local_path = dl_path
else:
await bot.reply(message, "Download failed, cannot keep track")
return
track.keep = True
# Check if this track is already kept (by normalized URL)