From 2b2aeabcac4bd91357c1d93c31e07c6f2029a33a Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Wed, 1 Jun 2022 15:48:15 +0200 Subject: [PATCH] fix keyerrors in queue --- music_assistant/mass.py | 3 +-- music_assistant/models/player_queue.py | 16 ++++++++-------- setup.py | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/music_assistant/mass.py b/music_assistant/mass.py index 4cd451a5..e889f92f 100644 --- a/music_assistant/mass.py +++ b/music_assistant/mass.py @@ -8,7 +8,6 @@ import threading from collections import deque from functools import partial from time import time -from tkinter import NONE from types import TracebackType from typing import Any, Callable, Coroutine, Deque, List, Optional, Tuple, Type, Union from uuid import uuid4 @@ -141,7 +140,7 @@ class MusicAssistant: ) -> BackgroundJob: """Add job to be (slowly) processed in the background.""" if not allow_duplicate: - if existing := next((x for x in self._jobs if x.name == name), NONE): + if existing := next((x for x in self._jobs if x.name == name), None): self.logger.debug("Ignored duplicate job: %s", name) coro.close() return existing diff --git a/music_assistant/models/player_queue.py b/music_assistant/models/player_queue.py index 047d1150..547794b9 100644 --- a/music_assistant/models/player_queue.py +++ b/music_assistant/models/player_queue.py @@ -338,12 +338,12 @@ class PlayerQueue: items = self._items.copy() item_index = self.index_by_id(queue_item_id) if pos_shift == 0 and self.player.state == PlayerState.PLAYING: - new_index = self._current_index + 1 + new_index = (self._current_index or 0) + 1 elif pos_shift == 0: - new_index = self._current_index + new_index = self._current_index or 0 else: new_index = item_index + pos_shift - if (new_index < self._current_index) or (new_index > len(self.items)): + if (new_index < (self._current_index or 0)) or (new_index > len(self.items)): return # move the item in the list items.insert(new_index, items.pop(item_index)) @@ -408,11 +408,12 @@ class PlayerQueue: async def append(self, queue_items: List[QueueItem]) -> None: """Append new items at the end of the queue.""" + cur_index = self._current_index or 0 for index, item in enumerate(queue_items): item.sort_index = len(self.items) + index if self.settings.shuffle_enabled: - played_items = self.items[: self._current_index] - next_items = self.items[self._current_index + 1 :] + queue_items + played_items = self.items[:cur_index] + next_items = self.items[cur_index + 1 :] + queue_items next_items = random.sample(next_items, len(next_items)) items = played_items + [self.current_item] + next_items await self.update(items) @@ -439,11 +440,10 @@ class PlayerQueue: # always signal update if playback state changed self.signal_update() + cur_index = self._current_index or 0 if self.player.state == PlayerState.IDLE: # handle end of queue - if self._current_index and self._current_index >= ( - len(self._items) - 1 - ): + if cur_index >= (len(self._items) - 1): self._current_index += 1 self._current_item_elapsed_time = 0 # repeat enabled (of whole queue), play queue from beginning diff --git a/setup.py b/setup.py index 4932c62b..fc77fb01 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ from setuptools import find_packages, setup PROJECT_NAME = "Music Assistant" PROJECT_PACKAGE_NAME = "music_assistant" -PROJECT_VERSION = "1.1.20" +PROJECT_VERSION = "1.1.22" PROJECT_REQ_PYTHON_VERSION = "3.9" PROJECT_LICENSE = "Apache License 2.0" PROJECT_AUTHOR = "Marcel van der Veldt" -- 2.34.1