Skip to content
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
62 changes: 58 additions & 4 deletions plexapi/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,14 @@ def _loadData(self, data):

@utils.registerPlexObject
class Session(PlexObject):
""" Represents a current session. """
""" Represents a current session.

Attributes:
TAG (str): 'Session'
id (str): The unique identifier for the session.
bandwidth (int): The Plex streaming brain reserved bandwidth for the session.
location (str): The location of the session (lan, wan, or cellular)
"""
TAG = 'Session'

def _loadData(self, data):
Expand All @@ -444,7 +451,41 @@ def _loadData(self, data):

@utils.registerPlexObject
class TranscodeSession(PlexObject):
""" Represents a current transcode session. """
""" Represents a current transcode session.

Attributes:
TAG (str): 'TranscodeSession'
audioChannels (int): The number of audio channels of the transcoded media.
audioCodec (str): The audio codec of the transcoded media.
audioDecision (str): The transcode decision for the audio stream.
complete (bool): True if the transcode is complete.
container (str): The container of the transcoded media.
context (str): The context for the transcode sesson.
duration (int): The duration of the transcoded media in milliseconds.
height (int): The height of the transcoded media in pixels.
key (str): API URL (ex: /transcode/sessions/<id>).
maxOffsetAvailable (float): Unknown.
minOffsetAvailable (float): Unknown.
progress (float): The progress percentage of the transcode.
protocol (str): The protocol of the transcode.
remaining (int): Unknown.
size (int): The size of the transcoded media in bytes.
sourceAudioCodec (str): The audio codec of the source media.
sourceVideoCodec (str): The video codec of the source media.
speed (float): The speed of the transcode.
subtitleDecision (str): The transcode decision for the subtitle stream
throttled (bool): True if the transcode is throttled.
timestamp (int): The epoch timestamp when the transcode started.
transcodeHwDecoding (str): The hardware transcoding decoder engine.
transcodeHwDecodingTitle (str): The title of the hardware transcoding decoder engine.
transcodeHwEncoding (str): The hardware transcoding encoder engine.
transcodeHwEncodingTitle (str): The title of the hardware transcoding encoder engine.
transcodeHwFullPipeline (str): True if hardware decoding and encoding is being used for the transcode.
transcodeHwRequested (str): True if hardware transcoding was requested for the transcode.
videoCodec (str): The video codec of the transcoded media.
videoDecision (str): The transcode decision for the video stream.
width (str): The width of the transcoded media in pixels.
"""
TAG = 'TranscodeSession'

def _loadData(self, data):
Expand All @@ -453,17 +494,30 @@ def _loadData(self, data):
self.audioChannels = cast(int, data.attrib.get('audioChannels'))
self.audioCodec = data.attrib.get('audioCodec')
self.audioDecision = data.attrib.get('audioDecision')
self.complete = cast(bool, data.attrib.get('complete', '0'))
self.container = data.attrib.get('container')
self.context = data.attrib.get('context')
self.duration = cast(int, data.attrib.get('duration'))
self.height = cast(int, data.attrib.get('height'))
self.key = data.attrib.get('key')
self.maxOffsetAvailable = cast(float, data.attrib.get('maxOffsetAvailable'))
self.minOffsetAvailable = cast(float, data.attrib.get('minOffsetAvailable'))
self.progress = cast(float, data.attrib.get('progress'))
self.protocol = data.attrib.get('protocol')
self.remaining = cast(int, data.attrib.get('remaining'))
self.speed = cast(int, data.attrib.get('speed'))
self.throttled = cast(int, data.attrib.get('throttled'))
self.size = cast(int, data.attrib.get('size'))
self.sourceAudioCodec = data.attrib.get('sourceAudioCodec')
self.sourceVideoCodec = data.attrib.get('sourceVideoCodec')
self.speed = cast(float, data.attrib.get('speed'))
self.subtitleDecision = data.attrib.get('subtitleDecision')
self.throttled = cast(bool, data.attrib.get('throttled', '0'))
self.timestamp = cast(float, data.attrib.get('timeStamp'))
self.transcodeHwDecoding = data.attrib.get('transcodeHwDecoding')
self.transcodeHwDecodingTitle = data.attrib.get('transcodeHwDecodingTitle')
self.transcodeHwEncoding = data.attrib.get('transcodeHwEncoding')
self.transcodeHwEncodingTitle = data.attrib.get('transcodeHwEncodingTitle')
self.transcodeHwFullPipeline = cast(bool, data.attrib.get('transcodeHwFullPipeline', '0'))
self.transcodeHwRequested = cast(bool, data.attrib.get('transcodeHwRequested', '0'))
self.videoCodec = data.attrib.get('videoCodec')
self.videoDecision = data.attrib.get('videoDecision')
self.width = cast(int, data.attrib.get('width'))
Expand Down
4 changes: 4 additions & 0 deletions plexapi/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,10 @@ def sessions(self):
""" Returns a list of all active session (currently playing) media objects. """
return self.fetchItems('/status/sessions')

def transcodeSessions(self):
""" Returns a list of all active :class:`~plexapi.media.TranscodeSession` objects. """
return self.fetchItems('/transcode/sessions')

def startAlertListener(self, callback=None):
""" Creates a websocket connection to the Plex Server to optionally recieve
notifications. These often include messages from Plex about media scans
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
FRAMERATES = {"24p", "PAL", "NTSC"}
PROFILES = {"advanced simple", "main", "constrained baseline"}
RESOLUTIONS = {"sd", "480", "576", "720", "1080"}
HW_DECODERS = {'dxva2', 'videotoolbox', 'mediacodecndk', 'vaapi', 'nvdec'}
HW_ENCODERS = {'qsv', 'mf', 'videotoolbox', 'mediacodecndk', 'vaapi', 'nvenc', 'x264'}
ENTITLEMENTS = {
"ios",
"roku",
Expand Down
5 changes: 5 additions & 0 deletions tests/payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@
<StatisticsResources timespan="6" at="1609708619" hostCpuUtilization="10.000" processCpuUtilization="4.415" hostMemoryUtilization="64.281" processMemoryUtilization="3.669"/>
</MediaContainer>
"""

SEVER_TRANSCODE_SESSIONS = """<MediaContainer size="1">
<TranscodeSession key="qucs2leop3yzm0sng4urq1o0" throttled="0" complete="0" progress="1.2999999523162842" size="73138224" speed="6.4000000953674316" duration="6654989" remaining="988" context="streaming" sourceVideoCodec="h264" sourceAudioCodec="dca" videoDecision="transcode" audioDecision="transcode" protocol="dash" container="mp4" videoCodec="h264" audioCodec="aac" audioChannels="2" transcodeHwRequested="1" transcodeHwDecoding="dxva2" transcodeHwDecodingTitle="Windows (DXVA2)" transcodeHwEncoding="qsv" transcodeHwEncodingTitle="Intel (QuickSync)" transcodeHwFullPipeline="0" timeStamp="1611533677.0316164" maxOffsetAvailable="84.000667334000667" minOffsetAvailable="0" height="720" width="1280" />
</MediaContainer>
"""
40 changes: 39 additions & 1 deletion tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from requests import Session

from . import conftest as utils
from .payloads import SERVER_RESOURCES
from .payloads import SERVER_RESOURCES, SEVER_TRANSCODE_SESSIONS


def test_server_attr(plex, account):
Expand Down Expand Up @@ -458,3 +458,41 @@ def test_server_dashboard_resources(plex, requests_mock):
assert utils.is_float(resource.processCpuUtilization, gte=0.0)
assert utils.is_float(resource.processMemoryUtilization, gte=0.0)
assert resource.timespan == 6 # Default seconds timespan


def test_server_transcode_sessions(plex, requests_mock):
url = plex.url("/transcode/sessions")
requests_mock.get(url, text=SEVER_TRANSCODE_SESSIONS)
transcode_sessions = plex.transcodeSessions()
assert len(transcode_sessions)
session = transcode_sessions[0]
assert session.audioChannels == 2
assert session.audioCodec in utils.CODECS
assert session.audioDecision == "transcode"
assert session.complete is False
assert session.container in utils.CONTAINERS
assert session.context == "streaming"
assert utils.is_int(session.duration, gte=100000)
assert utils.is_int(session.height, gte=480)
assert len(session.key)
assert utils.is_float(session.maxOffsetAvailable, gte=0.0)
assert utils.is_float(session.minOffsetAvailable, gte=0.0)
assert utils.is_float(session.progress)
assert session.protocol == "dash"
assert utils.is_int(session.remaining)
assert utils.is_int(session.size)
assert session.sourceAudioCodec in utils.CODECS
assert session.sourceVideoCodec in utils.CODECS
assert utils.is_float(session.speed)
assert session.subtitleDecision is None
assert session.throttled is False
assert utils.is_float(session.timestamp, gte=1600000000)
assert session.transcodeHwDecoding in utils.HW_DECODERS
assert session.transcodeHwDecodingTitle == "Windows (DXVA2)"
assert session.transcodeHwEncoding in utils.HW_ENCODERS
assert session.transcodeHwEncodingTitle == "Intel (QuickSync)"
assert session.transcodeHwFullPipeline is False
assert session.transcodeHwRequested is True
assert session.videoCodec in utils.CODECS
assert session.videoDecision == "transcode"
assert utils.is_int(session.width, gte=852)