Skip to content

Commit

Permalink
Fix/autoplay queue (#282)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
EvieePy authored Feb 7, 2024
1 parent 85c1aaf commit 90b1da8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "wavelink"
version = "3.2.0"
version = "3.2.1"
authors = [
{ name="PythonistaGuild, EvieePy", email="evieepy@gmail.com" },
]
Expand Down
2 changes: 1 addition & 1 deletion wavelink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
__author__ = "PythonistaGuild, EvieePy"
__license__ = "MIT"
__copyright__ = "Copyright 2019-Present (c) PythonistaGuild, EvieePy"
__version__ = "3.2.0"
__version__ = "3.2.1"


from .enums import *
Expand Down
25 changes: 13 additions & 12 deletions wavelink/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,36 +351,37 @@ async def _search(query: str | None) -> T_a:
# track for result in results for track in result...
filtered_r: list[Playable] = [t for r in results for t in r]

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

if not self._current:
now: Playable = filtered_r.pop(1)
now._recommended = True
self.auto_queue.history.put(now)

await self.play(now, add_history=False)

# Possibly adjust these thresholds?
history: list[Playable] = (
self.auto_queue[:40] + self.queue[:40] + self.queue.history[:-41:-1] + self.auto_queue.history[:-61:-1]
)

added: int = 0

random.shuffle(filtered_r)
for track in filtered_r:
if track in history:
continue

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

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

# Probably don't need this here as it's likely to be cancelled instantly...
self._inactivity_start()
if not self._current:
try:
now: Playable = self.auto_queue.get()
self.auto_queue.history.put(now)

await self.play(now, add_history=False)
except wavelink.QueueEmpty:
logger.info(f'Player "{self.guild.id}" could not load any songs via AutoPlay.')
self._inactivity_start()

@property
def inactive_timeout(self) -> int | None:
Expand Down

0 comments on commit 90b1da8

Please sign in to comment.