Skip to content
This repository was archived by the owner on Apr 5, 2025. It is now read-only.

Commit 90b1da8

Browse files
authored
Fix/autoplay queue (#282)
* Fixe AutoPlay randomizing the queue and playing before tracks are inserted. * Check if tracks were actually added. * Forgot to add to auto_queue history * Change logic in play (AutoPlay) * Bump version (3.2.1)
1 parent 85c1aaf commit 90b1da8

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "wavelink"
7-
version = "3.2.0"
7+
version = "3.2.1"
88
authors = [
99
{ name="PythonistaGuild, EvieePy", email="[email protected]" },
1010
]

wavelink/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
__author__ = "PythonistaGuild, EvieePy"
2626
__license__ = "MIT"
2727
__copyright__ = "Copyright 2019-Present (c) PythonistaGuild, EvieePy"
28-
__version__ = "3.2.0"
28+
__version__ = "3.2.1"
2929

3030

3131
from .enums import *

wavelink/player.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -351,36 +351,37 @@ async def _search(query: str | None) -> T_a:
351351
# track for result in results for track in result...
352352
filtered_r: list[Playable] = [t for r in results for t in r]
353353

354-
if not filtered_r:
355-
logger.debug(f'Player "{self.guild.id}" could not load any songs via AutoPlay.')
354+
if not filtered_r and not self.auto_queue:
355+
logger.info(f'Player "{self.guild.id}" could not load any songs via AutoPlay.')
356356
self._inactivity_start()
357357
return
358358

359-
if not self._current:
360-
now: Playable = filtered_r.pop(1)
361-
now._recommended = True
362-
self.auto_queue.history.put(now)
363-
364-
await self.play(now, add_history=False)
365-
366359
# Possibly adjust these thresholds?
367360
history: list[Playable] = (
368361
self.auto_queue[:40] + self.queue[:40] + self.queue.history[:-41:-1] + self.auto_queue.history[:-61:-1]
369362
)
370363

371364
added: int = 0
365+
366+
random.shuffle(filtered_r)
372367
for track in filtered_r:
373368
if track in history:
374369
continue
375370

376371
track._recommended = True
377372
added += await self.auto_queue.put_wait(track)
378373

379-
random.shuffle(self.auto_queue._items)
380374
logger.debug(f'Player "{self.guild.id}" added "{added}" tracks to the auto_queue via AutoPlay.')
381375

382-
# Probably don't need this here as it's likely to be cancelled instantly...
383-
self._inactivity_start()
376+
if not self._current:
377+
try:
378+
now: Playable = self.auto_queue.get()
379+
self.auto_queue.history.put(now)
380+
381+
await self.play(now, add_history=False)
382+
except wavelink.QueueEmpty:
383+
logger.info(f'Player "{self.guild.id}" could not load any songs via AutoPlay.')
384+
self._inactivity_start()
384385

385386
@property
386387
def inactive_timeout(self) -> int | None:

0 commit comments

Comments
 (0)