-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from kutu-dev/feat/play-queue
Feat/play queue
- Loading branch information
Showing
8 changed files
with
223 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from typing import TYPE_CHECKING, Any, Self | ||
|
||
from dateutil import parser | ||
|
||
from .song import Song | ||
from .user import User | ||
|
||
if TYPE_CHECKING: | ||
from ..subsonic import Subsonic | ||
|
||
|
||
class PlayQueue: | ||
"""Representation of all the data related to a play queue in Subsonic.""" | ||
|
||
def __init__( | ||
self, | ||
subsonic: "Subsonic", | ||
entry: list[dict[str, Any]], | ||
current: str | None = None, | ||
position: int | None = None, | ||
username: str | None = None, | ||
changed: str | None = None, | ||
changedBy: str | None = None, | ||
) -> None: | ||
self.__subsonic = subsonic | ||
self.current = Song(self.__subsonic, current) if current else None | ||
self.position = position | ||
self.user = User(username) if username else None | ||
self.changed = parser.parse(changed) if changed else None | ||
self.changed_by = changedBy | ||
self.songs = ( | ||
[Song(self.__subsonic, **song) for song in entry] if entry else None | ||
) | ||
|
||
def generate(self) -> "PlayQueue": | ||
"""Return a new play queue with all the data updated from the API, | ||
using the endpoint that return the most information possible. | ||
Useful for making copies with updated data or updating the object itself | ||
with immutability, e.g., foo = foo.generate(). | ||
:return: A new share object with all the data updated. | ||
:rtype: PlayQueue | ||
""" | ||
|
||
get_play_queue = self.__subsonic.bookmarks.get_play_queue() | ||
|
||
return get_play_queue | ||
|
||
def save(self) -> Self: | ||
"""Calls the "savePlayQueue" endpoint of the API. | ||
Saves the play queue using the parameters in the object. | ||
:return: _description_ | ||
:rtype: Self | ||
""" | ||
|
||
# TODO This should raise an exception? | ||
song_ids: list[str] = [song.id for song in self.songs] if self.songs else [] | ||
|
||
self.__subsonic.bookmarks.save_play_queue( | ||
song_ids, self.current.id if self.current else None, self.position | ||
) | ||
|
||
return self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from typing import Any | ||
|
||
import responses | ||
from knuckles import Subsonic | ||
from knuckles.models.play_queue import PlayQueue | ||
from responses import Response | ||
|
||
|
||
@responses.activate | ||
def test_generate( | ||
subsonic: Subsonic, | ||
mock_get_play_queue: Response, | ||
username: dict[str, Any], | ||
) -> None: | ||
responses.add(mock_get_play_queue) | ||
|
||
requested_queue = subsonic.bookmarks.get_play_queue() | ||
requested_queue.username = "Foo" | ||
requested_queue = requested_queue.generate() | ||
|
||
assert requested_queue.user.username == username | ||
|
||
|
||
@responses.activate | ||
def test_save( | ||
subsonic: Subsonic, | ||
mock_get_play_queue: Response, | ||
mock_save_play_queue: Response, | ||
) -> None: | ||
responses.add(mock_get_play_queue) | ||
responses.add(mock_save_play_queue) | ||
|
||
requested_queue = subsonic.bookmarks.get_play_queue() | ||
requested_queue = requested_queue.save() | ||
|
||
assert type(requested_queue) is PlayQueue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters