fix keyerrors in queue
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Wed, 1 Jun 2022 13:48:15 +0000 (15:48 +0200)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Wed, 1 Jun 2022 13:48:15 +0000 (15:48 +0200)
music_assistant/mass.py
music_assistant/models/player_queue.py
setup.py

index 4cd451a5d34469f72bbce3d5b864ec8c329cb27b..e889f92f8377abfe11146e2223296d721debdbe3 100644 (file)
@@ -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
index 047d1150a6691670a0fc0f2cf4c839a47d4a923a..547794b95ab394714a41a9a20f46b5a0e1566a1e 100644 (file)
@@ -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
index 4932c62bbee9b1c6e3459d2c0db7ffc5c2771eb6..fc77fb0117789c6beea34629b5c6336921a46c99 100644 (file)
--- 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"