Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/autoplay queue #282

Merged
merged 5 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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="[email protected]" },
]
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
Loading