Skip to content

feat: Add sonicAdventure method to MusicSection #1361

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

Merged
merged 12 commits into from
Mar 16, 2024
27 changes: 27 additions & 0 deletions plexapi/library.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import annotations

import re
from typing import Any, TYPE_CHECKING
import warnings
from collections import defaultdict
from datetime import datetime
Expand All @@ -17,6 +20,10 @@
from plexapi.utils import deprecated


if TYPE_CHECKING:
from plexapi.audio import Track


class Library(PlexObject):
""" Represents a PlexServer library. This contains all sections of media defined
in your Plex server including video, shows and audio.
Expand Down Expand Up @@ -2033,6 +2040,26 @@ def sync(self, bitrate, limit=None, **kwargs):
kwargs['policy'] = Policy.create(limit)
return super(MusicSection, self).sync(**kwargs)

def sonicAdventure(
self,
startID: int,
endID: int,
**kwargs: Any,
) -> list[Track]:
""" Returns a list of tracks from this library section that are part of a sonic adventure.
ID's should be of a track, other ID's will return an empty list or items itself or an error.

Parameters:
startID (int): The ratingKey of the first track in the sonic adventure.
endID (int): The ratingKey of the last track in the sonic adventure.

Returns:
List[:class:`~plexapi.audio.Track`]: a list of tracks from this library section
that are part of a sonic adventure.
"""
key = f"/library/sections/{self.key}/computePath?startID={startID}&endID={endID}"
return self.fetchItems(key, **kwargs)


class PhotoSection(LibrarySection, PhotoalbumEditMixins, PhotoEditMixins):
""" Represents a :class:`~plexapi.library.LibrarySection` section containing photos.
Expand Down
7 changes: 7 additions & 0 deletions tests/test_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,13 @@ def test_library_MusicSection_recentlyAdded(music, artist):
assert track in music.recentlyAddedTracks()


def test_library_MusicSection_sonicAdventure(music):
tracks = music.searchTracks()
adventure = music.sonicAdventure(tracks[0].ratingKey, tracks[-1].ratingKey)
assert len(adventure)
assert all(isinstance(t, plexapi.audio.Track) for t in adventure)


def test_library_PhotoSection_searchAlbums(photos, photoalbum):
title = photoalbum.title
assert len(photos.searchAlbums(title=title))
Expand Down