Skip to content

Commit 5b7d48f

Browse files
authored
Improve clips handling (#541)
* Improve clips handling * Remove year, add extraType * Don't bother refreshing for missing attribute * Update with attributes found in payload * Update docstrings for clips
1 parent fe27d76 commit 5b7d48f

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

plexapi/video.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class Video(PlexPartialObject):
1111
""" Base class for all video objects including :class:`~plexapi.video.Movie`,
1212
:class:`~plexapi.video.Show`, :class:`~plexapi.video.Season`,
13-
:class:`~plexapi.video.Episode`.
13+
:class:`~plexapi.video.Episode`, :class:`~plexapi.video.Clip`.
1414
1515
Attributes:
1616
addedAt (datetime): Datetime this item was added to the library.
@@ -774,24 +774,38 @@ def _defaultSyncTitle(self):
774774

775775
@utils.registerPlexObject
776776
class Clip(Playable, Video):
777-
""" Represents a single Clip."""
777+
"""Represents a single Clip.
778+
779+
Attributes:
780+
TAG (str): 'Video'
781+
TYPE (str): 'clip'
782+
duration (int): Duration of movie in milliseconds.
783+
extraType (int): Unknown
784+
guid: Plex GUID (com.plexapp.agents.imdb://tt4302938?lang=en).
785+
index (int): Plex index (?)
786+
originallyAvailableAt (datetime): Datetime movie was released.
787+
subtype (str): Type of clip
788+
viewOffset (int): View offset in milliseconds.
789+
"""
778790

779791
TAG = 'Video'
780792
TYPE = 'clip'
781793
METADATA_TYPE = 'clip'
782794

783795
def _loadData(self, data):
784-
self._data = data
785-
self.addedAt = data.attrib.get('addedAt')
786-
self.duration = data.attrib.get('duration')
796+
"""Load attribute values from Plex XML response."""
797+
Video._loadData(self, data)
798+
Playable._loadData(self, data)
799+
self.duration = utils.cast(int, data.attrib.get('duration'))
800+
self.extraType = utils.cast(int, data.attrib.get('extraType'))
787801
self.guid = data.attrib.get('guid')
788-
self.key = data.attrib.get('key')
802+
self.index = utils.cast(int, data.attrib.get('index'))
789803
self.originallyAvailableAt = data.attrib.get('originallyAvailableAt')
790-
self.ratingKey = data.attrib.get('ratingKey')
791-
self.skipDetails = utils.cast(int, data.attrib.get('skipDetails'))
792804
self.subtype = data.attrib.get('subtype')
793-
self.thumb = data.attrib.get('thumb')
794-
self.thumbAspectRatio = data.attrib.get('thumbAspectRatio')
795-
self.title = data.attrib.get('title')
796-
self.type = data.attrib.get('type')
797-
self.year = data.attrib.get('year')
805+
self.viewOffset = utils.cast(int, data.attrib.get('viewOffset', 0))
806+
807+
def section(self):
808+
"""Return the :class:`~plexapi.library.LibrarySection` this item belongs to."""
809+
# Clip payloads currently do not contain 'librarySectionID'.
810+
# Return None to avoid unnecessary attribute lookup attempts.
811+
return None

0 commit comments

Comments
 (0)