Add lyricStreams() convenience method (#1303)

* Move videoStreams, audioStreams, lyricStreams to Playable

* Add lyricStreams to Playable

* Simplify returning list of streams

* Add test for track.lyricStreams()
This commit is contained in:
JonnyWong16 2023-12-22 12:33:27 -08:00 committed by GitHub
parent 46c20a598f
commit f7522afd6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 36 deletions

View file

@ -771,6 +771,30 @@ class Playable:
for part in item.parts:
yield part
def videoStreams(self):
""" Returns a list of :class:`~plexapi.media.videoStream` objects for all MediaParts. """
if self.isPartialObject():
self.reload()
return sum((part.videoStreams() for part in self.iterParts()), [])
def audioStreams(self):
""" Returns a list of :class:`~plexapi.media.AudioStream` objects for all MediaParts. """
if self.isPartialObject():
self.reload()
return sum((part.audioStreams() for part in self.iterParts()), [])
def subtitleStreams(self):
""" Returns a list of :class:`~plexapi.media.SubtitleStream` objects for all MediaParts. """
if self.isPartialObject():
self.reload()
return sum((part.subtitleStreams() for part in self.iterParts()), [])
def lyricStreams(self):
""" Returns a list of :class:`~plexapi.media.LyricStream` objects for all MediaParts. """
if self.isPartialObject():
self.reload()
return sum((part.lyricStreams() for part in self.iterParts()), [])
def play(self, client):
""" Start playback on the specified client.

View file

@ -97,42 +97,6 @@ class Video(PlexPartialObject, PlayedUnplayedMixin):
""" Returns str, default title for a new syncItem. """
return self.title
def videoStreams(self):
""" Returns a list of :class:`~plexapi.media.videoStream` objects for all MediaParts. """
streams = []
if self.isPartialObject():
self.reload()
parts = self.iterParts()
for part in parts:
streams += part.videoStreams()
return streams
def audioStreams(self):
""" Returns a list of :class:`~plexapi.media.AudioStream` objects for all MediaParts. """
streams = []
if self.isPartialObject():
self.reload()
parts = self.iterParts()
for part in parts:
streams += part.audioStreams()
return streams
def subtitleStreams(self):
""" Returns a list of :class:`~plexapi.media.SubtitleStream` objects for all MediaParts. """
streams = []
if self.isPartialObject():
self.reload()
parts = self.iterParts()
for part in parts:
streams += part.subtitleStreams()
return streams
def uploadSubtitles(self, filepath):
""" Upload Subtitle file for video. """
url = f'{self.key}/subtitles'

View file

@ -394,6 +394,10 @@ def test_audio_Track_artist(album, artist):
assert tracks[0].artist() == artist
def test_audio_Track_lyricStreams(track):
assert not track.lyricStreams()
def test_audio_Track_mixins_images(track):
test_mixins.attr_artUrl(track)
test_mixins.attr_posterUrl(track)