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
) -> 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
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))
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)
# 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
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"