Skip to content

Commit b89bd23

Browse files
authored
Change MusicSection.stations() to return Playlist objects (#871)
* Fix library stations * `LibrarySection.stations()` returns a list of `Playlist` station objects * Add test for MusicSection stations
1 parent 570742c commit b89bd23

File tree

2 files changed

+8
-37
lines changed

2 files changed

+8
-37
lines changed

plexapi/library.py

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ def folders(self):
625625
def hubs(self):
626626
""" Returns a list of available :class:`~plexapi.library.Hub` for this library section.
627627
"""
628-
key = '/hubs/sections/%s' % self.key
628+
key = '/hubs/sections/%s?includeStations=1' % self.key
629629
return self.fetchItems(key)
630630

631631
def agents(self):
@@ -1817,9 +1817,8 @@ def albums(self):
18171817
return self.fetchItems(key)
18181818

18191819
def stations(self):
1820-
""" Returns a list of :class:`~plexapi.audio.Album` objects in this section. """
1821-
key = '/hubs/sections/%s?includeStations=1' % self.key
1822-
return self.fetchItems(key, cls=Station)
1820+
""" Returns a list of :class:`~plexapi.playlist.Playlist` stations in this section. """
1821+
return next((hub.items for hub in self.hubs() if hub.context == 'hub.music.stations'), None)
18231822

18241823
def searchArtists(self, **kwargs):
18251824
""" Search for an artist. See :func:`~plexapi.library.LibrarySection.search` for usage. """
@@ -2033,6 +2032,7 @@ class Hub(PlexObject):
20332032
context (str): The context of the hub.
20342033
hubKey (str): API URL for these specific hub items.
20352034
hubIdentifier (str): The identifier of the hub.
2035+
items (list): List of items in the hub.
20362036
key (str): API URL for the hub.
20372037
more (bool): True if there are more items to load (call reload() to fetch all items).
20382038
size (int): The number of items in the hub.
@@ -2185,39 +2185,6 @@ class Place(HubMediaTag):
21852185
TAGTYPE = 400
21862186

21872187

2188-
@utils.registerPlexObject
2189-
class Station(PlexObject):
2190-
""" Represents the Station area in the MusicSection.
2191-
2192-
Attributes:
2193-
TITLE (str): 'Stations'
2194-
TYPE (str): 'station'
2195-
hubIdentifier (str): Unknown.
2196-
size (int): Number of items found.
2197-
title (str): Title of this Hub.
2198-
type (str): Type of items in the Hub.
2199-
more (str): Unknown.
2200-
style (str): Unknown
2201-
items (str): List of items in the Hub.
2202-
"""
2203-
TITLE = 'Stations'
2204-
TYPE = 'station'
2205-
2206-
def _loadData(self, data):
2207-
""" Load attribute values from Plex XML response. """
2208-
self._data = data
2209-
self.hubIdentifier = data.attrib.get('hubIdentifier')
2210-
self.size = utils.cast(int, data.attrib.get('size'))
2211-
self.title = data.attrib.get('title')
2212-
self.type = data.attrib.get('type')
2213-
self.more = data.attrib.get('more')
2214-
self.style = data.attrib.get('style')
2215-
self.items = self.findItems(data)
2216-
2217-
def __len__(self):
2218-
return self.size
2219-
2220-
22212188
class FilteringType(PlexObject):
22222189
""" Represents a single filtering Type object for a library.
22232190

tests/test_library.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ def test_library_MusicSection_albums(music):
362362
assert len(music.albums())
363363

364364

365+
def test_library_MusicSection_stations(music):
366+
assert len(music.stations())
367+
368+
365369
def test_library_MusicSection_searchArtists(music):
366370
assert len(music.searchArtists(title="Broke for Free"))
367371

0 commit comments

Comments
 (0)