mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-22 11:43:13 +00:00
Rename "setDefault" to "setSelected" for media streams (#1206)
* Rename "setDefault" to "setSelected" * Update tests for setSelected subtitle stream
This commit is contained in:
parent
f67f4f7c2c
commit
0679816201
2 changed files with 55 additions and 20 deletions
|
@ -121,6 +121,7 @@ class MediaPart(PlexObject):
|
||||||
optimizedForStreaming (bool): True if the file is optimized for streaming.
|
optimizedForStreaming (bool): True if the file is optimized for streaming.
|
||||||
packetLength (int): The packet length of the file.
|
packetLength (int): The packet length of the file.
|
||||||
requiredBandwidths (str): The required bandwidths to stream the file.
|
requiredBandwidths (str): The required bandwidths to stream the file.
|
||||||
|
selected (bool): True if this media part is selected.
|
||||||
size (int): The size of the file in bytes (ex: 733884416).
|
size (int): The size of the file in bytes (ex: 733884416).
|
||||||
streams (List<:class:`~plexapi.media.MediaPartStream`>): List of stream objects.
|
streams (List<:class:`~plexapi.media.MediaPartStream`>): List of stream objects.
|
||||||
syncItemId (int): The unique ID for this media part if it is synced.
|
syncItemId (int): The unique ID for this media part if it is synced.
|
||||||
|
@ -184,38 +185,60 @@ class MediaPart(PlexObject):
|
||||||
""" Returns a list of :class:`~plexapi.media.LyricStream` objects in this MediaPart. """
|
""" Returns a list of :class:`~plexapi.media.LyricStream` objects in this MediaPart. """
|
||||||
return [stream for stream in self.streams if isinstance(stream, LyricStream)]
|
return [stream for stream in self.streams if isinstance(stream, LyricStream)]
|
||||||
|
|
||||||
def setDefaultAudioStream(self, stream):
|
def setSelectedAudioStream(self, stream):
|
||||||
""" Set the default :class:`~plexapi.media.AudioStream` for this MediaPart.
|
""" Set the selected :class:`~plexapi.media.AudioStream` for this MediaPart.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
stream (:class:`~plexapi.media.AudioStream`): AudioStream to set as default
|
stream (:class:`~plexapi.media.AudioStream`): Audio stream to set as selected
|
||||||
"""
|
"""
|
||||||
|
key = f'/library/parts/{self.id}'
|
||||||
|
params = {'allParts': 1}
|
||||||
|
|
||||||
if isinstance(stream, AudioStream):
|
if isinstance(stream, AudioStream):
|
||||||
key = f"/library/parts/{self.id}?audioStreamID={stream.id}&allParts=1"
|
params['audioStreamID'] = stream.id
|
||||||
else:
|
else:
|
||||||
key = f"/library/parts/{self.id}?audioStreamID={stream}&allParts=1"
|
params['audioStreamID'] = stream
|
||||||
self._server.query(key, method=self._server._session.put)
|
|
||||||
|
self._server.query(key, method=self._server._session.put, params=params)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def setDefaultSubtitleStream(self, stream):
|
def setSelectedSubtitleStream(self, stream):
|
||||||
""" Set the default :class:`~plexapi.media.SubtitleStream` for this MediaPart.
|
""" Set the selected :class:`~plexapi.media.SubtitleStream` for this MediaPart.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
stream (:class:`~plexapi.media.SubtitleStream`): SubtitleStream to set as default.
|
stream (:class:`~plexapi.media.SubtitleStream`): Subtitle stream to set as selected.
|
||||||
"""
|
"""
|
||||||
|
key = f'/library/parts/{self.id}'
|
||||||
|
params = {'allParts': 1}
|
||||||
|
|
||||||
if isinstance(stream, SubtitleStream):
|
if isinstance(stream, SubtitleStream):
|
||||||
key = f"/library/parts/{self.id}?subtitleStreamID={stream.id}&allParts=1"
|
params['subtitleStreamID'] = stream.id
|
||||||
else:
|
else:
|
||||||
key = f"/library/parts/{self.id}?subtitleStreamID={stream}&allParts=1"
|
params['subtitleStreamID'] = stream
|
||||||
|
|
||||||
self._server.query(key, method=self._server._session.put)
|
self._server.query(key, method=self._server._session.put)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def resetDefaultSubtitleStream(self):
|
def resetSelectedSubtitleStream(self):
|
||||||
""" Set default subtitle of this MediaPart to 'none'. """
|
""" Set the selected subtitle of this MediaPart to 'None'. """
|
||||||
key = f"/library/parts/{self.id}?subtitleStreamID=0&allParts=1"
|
key = f'/library/parts/{self.id}'
|
||||||
self._server.query(key, method=self._server._session.put)
|
params = {'subtitleStreamID': 0, 'allParts': 1}
|
||||||
|
|
||||||
|
self._server.query(key, method=self._server._session.put, params=params)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
@deprecated('Use "setSelectedAudioStream" instead.')
|
||||||
|
def setDefaultAudioStream(self, stream):
|
||||||
|
return self.setSelectedAudioStream(stream)
|
||||||
|
|
||||||
|
@deprecated('Use "setSelectedSubtitleStream" instead.')
|
||||||
|
def setDefaultSubtitleStream(self, stream):
|
||||||
|
return self.setSelectedSubtitleStream(stream)
|
||||||
|
|
||||||
|
@deprecated('Use "resetSelectedSubtitleStream" instead.')
|
||||||
|
def resetDefaultSubtitleStream(self):
|
||||||
|
return self.resetSelectedSubtitleStream()
|
||||||
|
|
||||||
|
|
||||||
class MediaPartStream(PlexObject):
|
class MediaPartStream(PlexObject):
|
||||||
""" Base class for media streams. These consist of video, audio, subtitles, and lyrics.
|
""" Base class for media streams. These consist of video, audio, subtitles, and lyrics.
|
||||||
|
@ -399,9 +422,15 @@ class AudioStream(MediaPartStream):
|
||||||
self.peak = utils.cast(float, data.attrib.get('peak'))
|
self.peak = utils.cast(float, data.attrib.get('peak'))
|
||||||
self.startRamp = data.attrib.get('startRamp')
|
self.startRamp = data.attrib.get('startRamp')
|
||||||
|
|
||||||
|
def setSelected(self):
|
||||||
|
""" Sets this audio stream as the selected audio stream.
|
||||||
|
Alias for :func:`~plexapi.media.MediaPart.setSelectedAudioStream`.
|
||||||
|
"""
|
||||||
|
return self._parent().setSelectedAudioStream(self)
|
||||||
|
|
||||||
|
@deprecated('Use "setSelected" instead.')
|
||||||
def setDefault(self):
|
def setDefault(self):
|
||||||
""" Sets this audio stream as the default audio stream. """
|
return self.setSelected()
|
||||||
return self._parent().setDefaultAudioStream(self)
|
|
||||||
|
|
||||||
|
|
||||||
@utils.registerPlexObject
|
@utils.registerPlexObject
|
||||||
|
@ -437,9 +466,15 @@ class SubtitleStream(MediaPartStream):
|
||||||
self.transient = data.attrib.get('transient')
|
self.transient = data.attrib.get('transient')
|
||||||
self.userID = utils.cast(int, data.attrib.get('userID'))
|
self.userID = utils.cast(int, data.attrib.get('userID'))
|
||||||
|
|
||||||
|
def setSelected(self):
|
||||||
|
""" Sets this subtitle stream as the selected subtitle stream.
|
||||||
|
Alias for :func:`~plexapi.media.MediaPart.setSelectedSubtitleStream`.
|
||||||
|
"""
|
||||||
|
return self._parent().setSelectedSubtitleStream(self)
|
||||||
|
|
||||||
|
@deprecated('Use "setSelected" instead.')
|
||||||
def setDefault(self):
|
def setDefault(self):
|
||||||
""" Sets this subtitle stream as the default subtitle stream. """
|
return self.setSelected()
|
||||||
return self._parent().setDefaultSubtitleStream(self)
|
|
||||||
|
|
||||||
|
|
||||||
class LyricStream(MediaPartStream):
|
class LyricStream(MediaPartStream):
|
||||||
|
|
|
@ -405,7 +405,7 @@ def test_video_Movie_upload_select_remove_subtitle(movie, subtitle):
|
||||||
subname = subtitle.name.rsplit(".", 1)[0]
|
subname = subtitle.name.rsplit(".", 1)[0]
|
||||||
assert subname in subtitles
|
assert subname in subtitles
|
||||||
|
|
||||||
movie.subtitleStreams()[0].setDefault()
|
movie.subtitleStreams()[0].setSelected()
|
||||||
movie.reload()
|
movie.reload()
|
||||||
|
|
||||||
subtitleSelection = movie.subtitleStreams()[0]
|
subtitleSelection = movie.subtitleStreams()[0]
|
||||||
|
|
Loading…
Reference in a new issue