mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-25 13:10:17 +00:00
Simplify building MediaPartStream objects (#1328)
* Simplify MediaPart._buildStreams * Remove isChildOf check for photo and track attributes * Add parent object when automatically building PlexObject * Remove check of track only attribute in tests
This commit is contained in:
parent
b3ef1c22dd
commit
e3d90a5945
3 changed files with 22 additions and 29 deletions
|
@ -98,7 +98,7 @@ class PlexObject:
|
|||
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):
|
||||
|
|
|
@ -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.
|
||||
|
@ -74,7 +74,7 @@ class Media(PlexObject):
|
|||
self.width = utils.cast(int, data.attrib.get('width'))
|
||||
self.uuid = data.attrib.get('uuid')
|
||||
|
||||
if self._isChildOf(etag='Photo'):
|
||||
# Photo only attributes
|
||||
self.aperture = data.attrib.get('aperture')
|
||||
self.exposure = data.attrib.get('exposure')
|
||||
self.iso = utils.cast(int, data.attrib.get('iso'))
|
||||
|
@ -158,11 +158,8 @@ class MediaPart(PlexObject):
|
|||
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):
|
||||
|
@ -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.
|
||||
|
@ -411,7 +408,7 @@ class AudioStream(MediaPartStream):
|
|||
self.samplingRate = utils.cast(int, data.attrib.get('samplingRate'))
|
||||
self.streamIdentifier = utils.cast(int, data.attrib.get('streamIdentifier'))
|
||||
|
||||
if self._isChildOf(etag='Track'):
|
||||
# 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'))
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue