Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions plexapi/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,17 @@
"""
return self._parent().setSelectedAudioStream(self)

def levels(self, subSample=128):
""" Returns a list of :class:`~plexapi.media.Level` objects for this AudioStream.
Only available for Tracks which have been analyzed for loudness.

Attributes:
subSample (int): The number of loudness samples to return. Default 128.
"""
key = f'/library/streams/{self.id}/levels'
params = {'subsample': subSample}
return self.fetchItems(key, params=params)

Check warning on line 445 in plexapi/media.py

View check run for this annotation

Codecov / codecov/patch

plexapi/media.py#L443-L445

Added lines #L443 - L445 were not covered by tests

@deprecated('Use "setSelected" instead.')
def setDefault(self):
return self.setSelected()
Expand Down Expand Up @@ -1343,3 +1354,15 @@
self.quality = data.attrib.get('quality')
self.title = data.attrib.get('title')
self.url = data.attrib.get('url')


@utils.registerPlexObject
class Level(PlexObject):
""" Represents a single loudness Level sample for an AudioStream.

Attributes:
loudness (float): Loudness level value
"""
def _loadData(self, data):
""" Load attribute values from Plex XML response. """
self.loudness = utils.cast(float, data.attrib.get('v'))

Check warning on line 1368 in plexapi/media.py

View check run for this annotation

Codecov / codecov/patch

plexapi/media.py#L1368

Added line #L1368 was not covered by tests
2 changes: 2 additions & 0 deletions tests/test_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ def test_audio_Track_attrs(album):
assert stream.lra is None
assert stream.peak is None
assert stream.startRamp is None
if stream.loudness is not None:
assert len(stream.levels(subSample=32)) == 32


def test_audio_Track_album(album):
Expand Down