Skip to content
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

Simplify building MediaPartStream objects #1328

Merged
merged 4 commits into from
Feb 4, 2024
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
2 changes: 1 addition & 1 deletion plexapi/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _buildItem(self, elem, cls=None, initpath=None):
ecls = utils.PLEXOBJECTS.get(ehash, utils.PLEXOBJECTS.get(elem.tag))
# log.debug('Building %s as %s', elem.tag, ecls.__name__)
if ecls is not None:
return ecls(self._server, elem, initpath)
return ecls(self._server, elem, initpath, parent=self)
raise UnknownType(f"Unknown library type <{elem.tag} type='{etype}'../>")

def _buildItemOrNone(self, elem, cls=None, initpath=None):
Expand Down
45 changes: 21 additions & 24 deletions plexapi/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Media(PlexObject):
videoResolution (str): The video resolution of the media (ex: sd).
width (int): The width of the video in pixels (ex: 608).

<Photo_only_attributes>: The following attributes are only available for photos.
Photo_only_attributes: The following attributes are only available for photos.

* aperture (str): The aperture used to take the photo.
* exposure (str): The exposure used to take the photo.
Expand Down Expand Up @@ -74,13 +74,13 @@ def _loadData(self, data):
self.width = utils.cast(int, data.attrib.get('width'))
self.uuid = data.attrib.get('uuid')

if self._isChildOf(etag='Photo'):
self.aperture = data.attrib.get('aperture')
self.exposure = data.attrib.get('exposure')
self.iso = utils.cast(int, data.attrib.get('iso'))
self.lens = data.attrib.get('lens')
self.make = data.attrib.get('make')
self.model = data.attrib.get('model')
# Photo only attributes
self.aperture = data.attrib.get('aperture')
self.exposure = data.attrib.get('exposure')
self.iso = utils.cast(int, data.attrib.get('iso'))
self.lens = data.attrib.get('lens')
self.make = data.attrib.get('make')
self.model = data.attrib.get('model')

parent = self._parent()
self._parentKey = parent.key
Expand Down Expand Up @@ -158,11 +158,8 @@ def _loadData(self, data):
self.videoProfile = data.attrib.get('videoProfile')

def _buildStreams(self, data):
streams = []
for cls in (VideoStream, AudioStream, SubtitleStream, LyricStream):
items = self.findItems(data, cls, streamType=cls.STREAMTYPE)
streams.extend(items)
return streams
""" Returns a list of :class:`~plexapi.media.MediaPartStream` objects in this MediaPart. """
return self.findItems(data)

@property
def hasPreviewThumbnails(self):
Expand Down Expand Up @@ -384,7 +381,7 @@ class AudioStream(MediaPartStream):
samplingRate (int): The sampling rate of the audio stream (ex: xxx)
streamIdentifier (int): The stream identifier of the audio stream.

<Track_only_attributes>: The following attributes are only available for tracks.
Track_only_attributes: The following attributes are only available for tracks.

* albumGain (float): The gain for the album.
* albumPeak (float): The peak for the album.
Expand All @@ -411,16 +408,16 @@ def _loadData(self, data):
self.samplingRate = utils.cast(int, data.attrib.get('samplingRate'))
self.streamIdentifier = utils.cast(int, data.attrib.get('streamIdentifier'))

if self._isChildOf(etag='Track'):
self.albumGain = utils.cast(float, data.attrib.get('albumGain'))
self.albumPeak = utils.cast(float, data.attrib.get('albumPeak'))
self.albumRange = utils.cast(float, data.attrib.get('albumRange'))
self.endRamp = data.attrib.get('endRamp')
self.gain = utils.cast(float, data.attrib.get('gain'))
self.loudness = utils.cast(float, data.attrib.get('loudness'))
self.lra = utils.cast(float, data.attrib.get('lra'))
self.peak = utils.cast(float, data.attrib.get('peak'))
self.startRamp = data.attrib.get('startRamp')
# Track only attributes
self.albumGain = utils.cast(float, data.attrib.get('albumGain'))
self.albumPeak = utils.cast(float, data.attrib.get('albumPeak'))
self.albumRange = utils.cast(float, data.attrib.get('albumRange'))
self.endRamp = data.attrib.get('endRamp')
self.gain = utils.cast(float, data.attrib.get('gain'))
self.loudness = utils.cast(float, data.attrib.get('loudness'))
self.lra = utils.cast(float, data.attrib.get('lra'))
self.peak = utils.cast(float, data.attrib.get('peak'))
self.startRamp = data.attrib.get('startRamp')

def setSelected(self):
""" Sets this audio stream as the selected audio stream.
Expand Down
4 changes: 0 additions & 4 deletions tests/test_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ def test_video_Movie_attrs(movies):
assert audio._server._baseurl == utils.SERVER_BASEURL
assert audio.title is None
assert audio.type == 2
with pytest.raises(AttributeError):
assert audio.albumGain is None # Check track only attributes are not available
# Media
media = movie.media[0]
assert media.aspectRatio >= 1.3
Expand All @@ -160,8 +158,6 @@ def test_video_Movie_attrs(movies):
assert media.videoProfile == "main"
assert media.videoResolution in utils.RESOLUTIONS
assert utils.is_int(media.width, gte=200)
with pytest.raises(AttributeError):
assert media.aperture is None # Check photo only attributes are not available
# Video
video = movie.media[0].parts[0].videoStreams()[0]
assert video.anamorphic is None
Expand Down