2016-03-21 04:26:02 +00:00
|
|
|
|
# -*- coding: utf-8 -*-
|
2023-05-24 21:50:30 +00:00
|
|
|
|
import os
|
2023-07-28 03:05:40 +00:00
|
|
|
|
from functools import cached_property
|
2020-05-12 21:15:16 +00:00
|
|
|
|
from urllib.parse import urlencode
|
|
|
|
|
from xml.etree import ElementTree
|
|
|
|
|
|
2015-09-05 14:09:15 +00:00
|
|
|
|
import requests
|
2023-05-24 21:50:30 +00:00
|
|
|
|
|
|
|
|
|
from plexapi import BASE_HEADERS, CONFIG, TIMEOUT, log, logfilter
|
2020-05-12 21:15:16 +00:00
|
|
|
|
from plexapi import utils
|
2017-02-25 04:50:58 +00:00
|
|
|
|
from plexapi.alert import AlertListener
|
2017-02-06 04:52:10 +00:00
|
|
|
|
from plexapi.base import PlexObject
|
2016-04-02 06:19:32 +00:00
|
|
|
|
from plexapi.client import PlexClient
|
2021-05-28 05:50:30 +00:00
|
|
|
|
from plexapi.collection import Collection
|
2020-04-09 20:56:26 +00:00
|
|
|
|
from plexapi.exceptions import BadRequest, NotFound, Unauthorized
|
2020-11-16 05:10:13 +00:00
|
|
|
|
from plexapi.library import Hub, Library, Path, File
|
2020-05-12 21:15:16 +00:00
|
|
|
|
from plexapi.media import Conversion, Optimized
|
2016-04-11 03:49:23 +00:00
|
|
|
|
from plexapi.playlist import Playlist
|
2014-12-29 03:21:58 +00:00
|
|
|
|
from plexapi.playqueue import PlayQueue
|
2020-05-12 21:15:16 +00:00
|
|
|
|
from plexapi.settings import Settings
|
2023-07-28 03:05:40 +00:00
|
|
|
|
from plexapi.utils import deprecated
|
2020-05-12 21:15:16 +00:00
|
|
|
|
from requests.status_codes import _codes as codes
|
2017-02-13 02:55:55 +00:00
|
|
|
|
|
2021-01-24 20:21:56 +00:00
|
|
|
|
# Need these imports to populate utils.PLEXOBJECTS
|
2021-02-15 06:33:03 +00:00
|
|
|
|
from plexapi import audio as _audio # noqa: F401
|
|
|
|
|
from plexapi import collection as _collection # noqa: F401
|
2021-01-24 20:21:56 +00:00
|
|
|
|
from plexapi import media as _media # noqa: F401
|
|
|
|
|
from plexapi import photo as _photo # noqa: F401
|
|
|
|
|
from plexapi import playlist as _playlist # noqa: F401
|
|
|
|
|
from plexapi import video as _video # noqa: F401
|
2014-12-29 03:21:58 +00:00
|
|
|
|
|
|
|
|
|
|
2017-02-06 04:52:10 +00:00
|
|
|
|
class PlexServer(PlexObject):
|
2017-02-03 06:29:19 +00:00
|
|
|
|
""" This is the main entry point to interacting with a Plex server. It allows you to
|
|
|
|
|
list connected clients, browse your library sections and perform actions such as
|
|
|
|
|
emptying trash. If you do not know the auth token required to access your Plex
|
|
|
|
|
server, or simply want to access your server with your username and password, you
|
|
|
|
|
can also create an PlexServer instance from :class:`~plexapi.myplex.MyPlexAccount`.
|
|
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
baseurl (str): Base url for to access the Plex Media Server (default: 'http://localhost:32400').
|
|
|
|
|
token (str): Required Plex authentication token to access the server.
|
|
|
|
|
session (requests.Session, optional): Use your own session object if you want to
|
2021-05-12 00:03:16 +00:00
|
|
|
|
cache the http responses from the server.
|
|
|
|
|
timeout (int, optional): Timeout in seconds on initial connection to the server
|
|
|
|
|
(default config.TIMEOUT).
|
2017-02-03 06:29:19 +00:00
|
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
|
allowCameraUpload (bool): True if server allows camera upload.
|
|
|
|
|
allowChannelAccess (bool): True if server allows channel access (iTunes?).
|
|
|
|
|
allowMediaDeletion (bool): True is server allows media to be deleted.
|
|
|
|
|
allowSharing (bool): True is server allows sharing.
|
|
|
|
|
allowSync (bool): True is server allows sync.
|
|
|
|
|
backgroundProcessing (bool): Unknown
|
|
|
|
|
certificate (bool): True if server has an HTTPS certificate.
|
|
|
|
|
companionProxy (bool): Unknown
|
|
|
|
|
diagnostics (bool): Unknown
|
|
|
|
|
eventStream (bool): Unknown
|
|
|
|
|
friendlyName (str): Human friendly name for this server.
|
|
|
|
|
hubSearch (bool): True if `Hub Search <https://www.plex.tv/blog
|
|
|
|
|
/seek-plex-shall-find-leveling-web-app/>`_ is enabled. I believe this
|
|
|
|
|
is enabled for everyone
|
|
|
|
|
machineIdentifier (str): Unique ID for this server (looks like an md5).
|
|
|
|
|
multiuser (bool): True if `multiusers <https://support.plex.tv/hc/en-us/articles
|
|
|
|
|
/200250367-Multi-User-Support>`_ are enabled.
|
|
|
|
|
myPlex (bool): Unknown (True if logged into myPlex?).
|
|
|
|
|
myPlexMappingState (str): Unknown (ex: mapped).
|
|
|
|
|
myPlexSigninState (str): Unknown (ex: ok).
|
2017-08-11 19:14:32 +00:00
|
|
|
|
myPlexSubscription (bool): True if you have a myPlex subscription.
|
2017-02-03 06:29:19 +00:00
|
|
|
|
myPlexUsername (str): Email address if signed into myPlex (user@example.com)
|
2017-04-29 05:47:21 +00:00
|
|
|
|
ownerFeatures (list): List of features allowed by the server owner. This may be based
|
2017-02-03 06:29:19 +00:00
|
|
|
|
on your PlexPass subscription. Features include: camera_upload, cloudsync,
|
|
|
|
|
content_filter, dvr, hardware_transcoding, home, lyrics, music_videos, pass,
|
|
|
|
|
photo_autotags, premium_music_metadata, session_bandwidth_restrictions, sync,
|
|
|
|
|
trailers, webhooks (and maybe more).
|
|
|
|
|
photoAutoTag (bool): True if photo `auto-tagging <https://support.plex.tv/hc/en-us
|
|
|
|
|
/articles/234976627-Auto-Tagging-of-Photos>`_ is enabled.
|
|
|
|
|
platform (str): Platform the server is hosted on (ex: Linux)
|
|
|
|
|
platformVersion (str): Platform version (ex: '6.1 (Build 7601)', '4.4.0-59-generic').
|
|
|
|
|
pluginHost (bool): Unknown
|
|
|
|
|
readOnlyLibraries (bool): Unknown
|
|
|
|
|
requestParametersInCookie (bool): Unknown
|
|
|
|
|
streamingBrainVersion (bool): Current `Streaming Brain <https://www.plex.tv/blog
|
|
|
|
|
/mcstreamy-brain-take-world-two-easy-steps/>`_ version.
|
|
|
|
|
sync (bool): True if `syncing to a device <https://support.plex.tv/hc/en-us/articles
|
|
|
|
|
/201053678-Sync-Media-to-a-Device>`_ is enabled.
|
|
|
|
|
transcoderActiveVideoSessions (int): Number of active video transcoding sessions.
|
|
|
|
|
transcoderAudio (bool): True if audio transcoding audio is available.
|
|
|
|
|
transcoderLyrics (bool): True if audio transcoding lyrics is available.
|
|
|
|
|
transcoderPhoto (bool): True if audio transcoding photos is available.
|
|
|
|
|
transcoderSubtitles (bool): True if audio transcoding subtitles is available.
|
|
|
|
|
transcoderVideo (bool): True if audio transcoding video is available.
|
|
|
|
|
transcoderVideoBitrates (bool): List of video bitrates.
|
|
|
|
|
transcoderVideoQualities (bool): List of video qualities.
|
|
|
|
|
transcoderVideoResolutions (bool): List of video resolutions.
|
|
|
|
|
updatedAt (int): Datetime the server was updated.
|
|
|
|
|
updater (bool): Unknown
|
|
|
|
|
version (str): Current Plex version (ex: 1.3.2.3112-1751929)
|
|
|
|
|
voiceSearch (bool): True if voice search is enabled. (is this Google Voice search?)
|
2017-06-05 02:01:07 +00:00
|
|
|
|
_baseurl (str): HTTP address of the client.
|
|
|
|
|
_token (str): Token used to access this client.
|
|
|
|
|
_session (obj): Requests session object used to access this client.
|
2016-12-15 23:06:12 +00:00
|
|
|
|
"""
|
2017-02-06 04:52:10 +00:00
|
|
|
|
key = '/'
|
|
|
|
|
|
2017-04-24 02:59:22 +00:00
|
|
|
|
def __init__(self, baseurl=None, token=None, session=None, timeout=None):
|
2017-02-22 06:22:10 +00:00
|
|
|
|
self._baseurl = baseurl or CONFIG.get('auth.server_baseurl', 'http://localhost:32400')
|
2019-01-19 22:05:12 +00:00
|
|
|
|
self._baseurl = self._baseurl.rstrip('/')
|
2017-02-20 03:18:23 +00:00
|
|
|
|
self._token = logfilter.add_secret(token or CONFIG.get('auth.server_token'))
|
2018-01-05 02:44:35 +00:00
|
|
|
|
self._showSecrets = CONFIG.get('log.show_secrets', '').lower() == 'true'
|
2017-02-06 04:52:10 +00:00
|
|
|
|
self._session = session or requests.Session()
|
2023-08-30 16:41:12 +00:00
|
|
|
|
self._timeout = timeout or TIMEOUT
|
2017-05-27 02:35:33 +00:00
|
|
|
|
self._myPlexAccount = None # cached myPlexAccount
|
2021-01-03 02:14:35 +00:00
|
|
|
|
self._systemAccounts = None # cached list of SystemAccount
|
|
|
|
|
self._systemDevices = None # cached list of SystemDevice
|
2021-05-11 23:38:50 +00:00
|
|
|
|
data = self.query(self.key, timeout=self._timeout)
|
2017-04-24 02:59:22 +00:00
|
|
|
|
super(PlexServer, self).__init__(self, data, self.key)
|
2017-02-03 06:29:19 +00:00
|
|
|
|
|
|
|
|
|
def _loadData(self, data):
|
|
|
|
|
""" Load attribute values from Plex XML response. """
|
2017-02-04 08:08:47 +00:00
|
|
|
|
self._data = data
|
2021-05-27 02:45:12 +00:00
|
|
|
|
self.allowCameraUpload = utils.cast(bool, data.attrib.get('allowCameraUpload'))
|
|
|
|
|
self.allowChannelAccess = utils.cast(bool, data.attrib.get('allowChannelAccess'))
|
|
|
|
|
self.allowMediaDeletion = utils.cast(bool, data.attrib.get('allowMediaDeletion'))
|
|
|
|
|
self.allowSharing = utils.cast(bool, data.attrib.get('allowSharing'))
|
|
|
|
|
self.allowSync = utils.cast(bool, data.attrib.get('allowSync'))
|
|
|
|
|
self.backgroundProcessing = utils.cast(bool, data.attrib.get('backgroundProcessing'))
|
|
|
|
|
self.certificate = utils.cast(bool, data.attrib.get('certificate'))
|
|
|
|
|
self.companionProxy = utils.cast(bool, data.attrib.get('companionProxy'))
|
2017-02-03 16:39:46 +00:00
|
|
|
|
self.diagnostics = utils.toList(data.attrib.get('diagnostics'))
|
2021-05-27 02:45:12 +00:00
|
|
|
|
self.eventStream = utils.cast(bool, data.attrib.get('eventStream'))
|
2014-12-29 03:21:58 +00:00
|
|
|
|
self.friendlyName = data.attrib.get('friendlyName')
|
2021-05-27 02:45:12 +00:00
|
|
|
|
self.hubSearch = utils.cast(bool, data.attrib.get('hubSearch'))
|
2014-12-29 03:21:58 +00:00
|
|
|
|
self.machineIdentifier = data.attrib.get('machineIdentifier')
|
2021-05-27 02:45:12 +00:00
|
|
|
|
self.multiuser = utils.cast(bool, data.attrib.get('multiuser'))
|
|
|
|
|
self.myPlex = utils.cast(bool, data.attrib.get('myPlex'))
|
2014-12-29 03:21:58 +00:00
|
|
|
|
self.myPlexMappingState = data.attrib.get('myPlexMappingState')
|
|
|
|
|
self.myPlexSigninState = data.attrib.get('myPlexSigninState')
|
2021-05-27 02:45:12 +00:00
|
|
|
|
self.myPlexSubscription = utils.cast(bool, data.attrib.get('myPlexSubscription'))
|
2014-12-29 03:21:58 +00:00
|
|
|
|
self.myPlexUsername = data.attrib.get('myPlexUsername')
|
2017-02-03 16:39:46 +00:00
|
|
|
|
self.ownerFeatures = utils.toList(data.attrib.get('ownerFeatures'))
|
2021-05-27 02:45:12 +00:00
|
|
|
|
self.photoAutoTag = utils.cast(bool, data.attrib.get('photoAutoTag'))
|
2014-12-29 03:21:58 +00:00
|
|
|
|
self.platform = data.attrib.get('platform')
|
|
|
|
|
self.platformVersion = data.attrib.get('platformVersion')
|
2021-05-27 02:45:12 +00:00
|
|
|
|
self.pluginHost = utils.cast(bool, data.attrib.get('pluginHost'))
|
|
|
|
|
self.readOnlyLibraries = utils.cast(int, data.attrib.get('readOnlyLibraries'))
|
|
|
|
|
self.requestParametersInCookie = utils.cast(bool, data.attrib.get('requestParametersInCookie'))
|
2017-02-03 06:29:19 +00:00
|
|
|
|
self.streamingBrainVersion = data.attrib.get('streamingBrainVersion')
|
2021-05-27 02:45:12 +00:00
|
|
|
|
self.sync = utils.cast(bool, data.attrib.get('sync'))
|
2015-06-15 02:45:22 +00:00
|
|
|
|
self.transcoderActiveVideoSessions = int(data.attrib.get('transcoderActiveVideoSessions', 0))
|
2021-05-27 02:45:12 +00:00
|
|
|
|
self.transcoderAudio = utils.cast(bool, data.attrib.get('transcoderAudio'))
|
|
|
|
|
self.transcoderLyrics = utils.cast(bool, data.attrib.get('transcoderLyrics'))
|
|
|
|
|
self.transcoderPhoto = utils.cast(bool, data.attrib.get('transcoderPhoto'))
|
|
|
|
|
self.transcoderSubtitles = utils.cast(bool, data.attrib.get('transcoderSubtitles'))
|
|
|
|
|
self.transcoderVideo = utils.cast(bool, data.attrib.get('transcoderVideo'))
|
2017-02-03 16:39:46 +00:00
|
|
|
|
self.transcoderVideoBitrates = utils.toList(data.attrib.get('transcoderVideoBitrates'))
|
|
|
|
|
self.transcoderVideoQualities = utils.toList(data.attrib.get('transcoderVideoQualities'))
|
|
|
|
|
self.transcoderVideoResolutions = utils.toList(data.attrib.get('transcoderVideoResolutions'))
|
2017-02-04 17:43:50 +00:00
|
|
|
|
self.updatedAt = utils.toDatetime(data.attrib.get('updatedAt'))
|
2021-05-27 02:45:12 +00:00
|
|
|
|
self.updater = utils.cast(bool, data.attrib.get('updater'))
|
2014-12-29 03:21:58 +00:00
|
|
|
|
self.version = data.attrib.get('version')
|
2021-05-27 02:45:12 +00:00
|
|
|
|
self.voiceSearch = utils.cast(bool, data.attrib.get('voiceSearch'))
|
2014-12-29 03:21:58 +00:00
|
|
|
|
|
2017-02-06 04:52:10 +00:00
|
|
|
|
def _headers(self, **kwargs):
|
|
|
|
|
""" Returns dict containing base headers for all requests to the server. """
|
|
|
|
|
headers = BASE_HEADERS.copy()
|
|
|
|
|
if self._token:
|
|
|
|
|
headers['X-Plex-Token'] = self._token
|
|
|
|
|
headers.update(kwargs)
|
|
|
|
|
return headers
|
|
|
|
|
|
2021-05-30 01:22:27 +00:00
|
|
|
|
def _uriRoot(self):
|
2022-08-28 05:56:01 +00:00
|
|
|
|
return f'server://{self.machineIdentifier}/com.plexapp.plugins.library'
|
2021-05-30 01:22:27 +00:00
|
|
|
|
|
2022-12-21 19:51:45 +00:00
|
|
|
|
@cached_property
|
2014-12-29 03:21:58 +00:00
|
|
|
|
def library(self):
|
2017-02-03 06:29:19 +00:00
|
|
|
|
""" Library to browse or search your media. """
|
2022-12-21 19:51:45 +00:00
|
|
|
|
try:
|
|
|
|
|
data = self.query(Library.key)
|
|
|
|
|
except BadRequest:
|
|
|
|
|
# Only the owner has access to /library
|
|
|
|
|
# so just return the library without the data.
|
|
|
|
|
data = self.query('/library/sections/')
|
|
|
|
|
return Library(self, data)
|
2014-12-29 03:21:58 +00:00
|
|
|
|
|
2022-12-21 19:51:45 +00:00
|
|
|
|
@cached_property
|
2017-02-23 06:33:30 +00:00
|
|
|
|
def settings(self):
|
|
|
|
|
""" Returns a list of all server settings. """
|
2022-12-21 19:51:45 +00:00
|
|
|
|
data = self.query(Settings.key)
|
|
|
|
|
return Settings(self, data)
|
2017-02-23 06:33:30 +00:00
|
|
|
|
|
2023-08-27 19:06:40 +00:00
|
|
|
|
def identity(self):
|
|
|
|
|
""" Returns the Plex server identity. """
|
|
|
|
|
data = self.query('/identity')
|
|
|
|
|
return Identity(self, data)
|
|
|
|
|
|
2014-12-29 03:21:58 +00:00
|
|
|
|
def account(self):
|
2017-02-03 06:29:19 +00:00
|
|
|
|
""" Returns the :class:`~plexapi.server.Account` object this server belongs to. """
|
2017-02-09 04:29:17 +00:00
|
|
|
|
data = self.query(Account.key)
|
2016-04-07 05:39:04 +00:00
|
|
|
|
return Account(self, data)
|
2019-06-29 20:16:55 +00:00
|
|
|
|
|
2021-05-22 21:44:16 +00:00
|
|
|
|
def claim(self, account):
|
|
|
|
|
""" Claim the Plex server using a :class:`~plexapi.myplex.MyPlexAccount`.
|
|
|
|
|
This will only work with an unclaimed server on localhost or the same subnet.
|
2023-08-29 03:29:39 +00:00
|
|
|
|
|
2021-05-22 21:44:16 +00:00
|
|
|
|
Parameters:
|
|
|
|
|
account (:class:`~plexapi.myplex.MyPlexAccount`): The account used to
|
|
|
|
|
claim the server.
|
|
|
|
|
"""
|
|
|
|
|
key = '/myplex/claim'
|
|
|
|
|
params = {'token': account.claimToken()}
|
|
|
|
|
data = self.query(key, method=self._session.post, params=params)
|
|
|
|
|
return Account(self, data)
|
|
|
|
|
|
|
|
|
|
def unclaim(self):
|
|
|
|
|
""" Unclaim the Plex server. This will remove the server from your
|
|
|
|
|
:class:`~plexapi.myplex.MyPlexAccount`.
|
|
|
|
|
"""
|
|
|
|
|
data = self.query(Account.key, method=self._session.delete)
|
|
|
|
|
return Account(self, data)
|
|
|
|
|
|
2020-09-16 23:16:01 +00:00
|
|
|
|
@property
|
|
|
|
|
def activities(self):
|
|
|
|
|
"""Returns all current PMS activities."""
|
|
|
|
|
activities = []
|
|
|
|
|
for elem in self.query(Activity.key):
|
|
|
|
|
activities.append(Activity(self, elem))
|
|
|
|
|
return activities
|
|
|
|
|
|
2020-03-16 18:25:26 +00:00
|
|
|
|
def agents(self, mediaType=None):
|
2022-01-24 00:15:10 +00:00
|
|
|
|
""" Returns a list of :class:`~plexapi.media.Agent` objects this server has available. """
|
2020-03-10 20:07:29 +00:00
|
|
|
|
key = '/system/agents'
|
2020-03-16 18:25:26 +00:00
|
|
|
|
if mediaType:
|
2022-08-28 05:56:01 +00:00
|
|
|
|
key += f'?mediaType={utils.searchType(mediaType)}'
|
2020-03-16 17:23:33 +00:00
|
|
|
|
return self.fetchItems(key)
|
2020-03-10 20:07:29 +00:00
|
|
|
|
|
2019-06-29 20:16:55 +00:00
|
|
|
|
def createToken(self, type='delegation', scope='all'):
|
2021-05-11 23:38:50 +00:00
|
|
|
|
""" Create a temp access token for the server. """
|
2020-04-16 19:06:36 +00:00
|
|
|
|
if not self._token:
|
|
|
|
|
# Handle unclaimed servers
|
|
|
|
|
return None
|
2022-08-28 05:56:01 +00:00
|
|
|
|
q = self.query(f'/security/token?type={type}&scope={scope}')
|
2019-06-29 20:16:55 +00:00
|
|
|
|
return q.attrib.get('token')
|
|
|
|
|
|
2023-05-24 20:55:36 +00:00
|
|
|
|
def switchUser(self, user, session=None, timeout=None):
|
2021-05-11 23:38:50 +00:00
|
|
|
|
""" Returns a new :class:`~plexapi.server.PlexServer` object logged in as the given username.
|
|
|
|
|
Note: Only the admin account can switch to other users.
|
2023-08-29 03:29:39 +00:00
|
|
|
|
|
2021-05-11 23:38:50 +00:00
|
|
|
|
Parameters:
|
2023-05-24 20:55:36 +00:00
|
|
|
|
user (:class:`~plexapi.myplex.MyPlexUser` or str): `MyPlexUser` object, username,
|
|
|
|
|
email, or user id of the user to log in to the server.
|
2021-05-12 00:03:16 +00:00
|
|
|
|
session (requests.Session, optional): Use your own session object if you want to
|
|
|
|
|
cache the http responses from the server. This will default to the same
|
|
|
|
|
session as the admin account if no new session is provided.
|
|
|
|
|
timeout (int, optional): Timeout in seconds on initial connection to the server.
|
|
|
|
|
This will default to the same timeout as the admin account if no new timeout
|
|
|
|
|
is provided.
|
2021-05-11 23:38:50 +00:00
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
from plexapi.server import PlexServer
|
|
|
|
|
# Login to the Plex server using the admin token
|
|
|
|
|
plex = PlexServer('http://plexserver:32400', token='2ffLuB84dqLswk9skLos')
|
|
|
|
|
# Login to the same Plex server using a different account
|
|
|
|
|
userPlex = plex.switchUser("Username")
|
|
|
|
|
|
|
|
|
|
"""
|
2023-05-24 20:55:36 +00:00
|
|
|
|
from plexapi.myplex import MyPlexUser
|
|
|
|
|
user = user if isinstance(user, MyPlexUser) else self.myPlexAccount().user(user)
|
2021-05-11 23:38:50 +00:00
|
|
|
|
userToken = user.get_token(self.machineIdentifier)
|
2021-05-12 00:03:16 +00:00
|
|
|
|
if session is None:
|
|
|
|
|
session = self._session
|
|
|
|
|
if timeout is None:
|
|
|
|
|
timeout = self._timeout
|
|
|
|
|
return PlexServer(self._baseurl, token=userToken, session=session, timeout=timeout)
|
2021-05-11 23:38:50 +00:00
|
|
|
|
|
2019-06-03 04:44:21 +00:00
|
|
|
|
def systemAccounts(self):
|
2021-03-22 19:35:57 +00:00
|
|
|
|
""" Returns a list of :class:`~plexapi.server.SystemAccount` objects this server contains. """
|
2021-01-03 01:54:17 +00:00
|
|
|
|
if self._systemAccounts is None:
|
2021-01-03 18:41:38 +00:00
|
|
|
|
key = '/accounts'
|
|
|
|
|
self._systemAccounts = self.fetchItems(key, SystemAccount)
|
2021-01-03 01:54:17 +00:00
|
|
|
|
return self._systemAccounts
|
2021-01-03 01:25:39 +00:00
|
|
|
|
|
2021-03-22 19:35:57 +00:00
|
|
|
|
def systemAccount(self, accountID):
|
|
|
|
|
""" Returns the :class:`~plexapi.server.SystemAccount` object for the specified account ID.
|
|
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
accountID (int): The :class:`~plexapi.server.SystemAccount` ID.
|
|
|
|
|
"""
|
|
|
|
|
try:
|
|
|
|
|
return next(account for account in self.systemAccounts() if account.id == accountID)
|
|
|
|
|
except StopIteration:
|
2022-08-28 05:56:01 +00:00
|
|
|
|
raise NotFound(f'Unknown account with accountID={accountID}') from None
|
2021-03-22 19:35:57 +00:00
|
|
|
|
|
2021-01-03 01:25:39 +00:00
|
|
|
|
def systemDevices(self):
|
2021-03-22 19:35:57 +00:00
|
|
|
|
""" Returns a list of :class:`~plexapi.server.SystemDevice` objects this server contains. """
|
2021-01-03 01:54:17 +00:00
|
|
|
|
if self._systemDevices is None:
|
2021-01-03 18:41:38 +00:00
|
|
|
|
key = '/devices'
|
|
|
|
|
self._systemDevices = self.fetchItems(key, SystemDevice)
|
2021-01-03 01:54:17 +00:00
|
|
|
|
return self._systemDevices
|
2014-12-29 03:21:58 +00:00
|
|
|
|
|
2021-03-22 19:35:57 +00:00
|
|
|
|
def systemDevice(self, deviceID):
|
|
|
|
|
""" Returns the :class:`~plexapi.server.SystemDevice` object for the specified device ID.
|
|
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
deviceID (int): The :class:`~plexapi.server.SystemDevice` ID.
|
|
|
|
|
"""
|
|
|
|
|
try:
|
|
|
|
|
return next(device for device in self.systemDevices() if device.id == deviceID)
|
|
|
|
|
except StopIteration:
|
2022-08-28 05:56:01 +00:00
|
|
|
|
raise NotFound(f'Unknown device with deviceID={deviceID}') from None
|
2021-03-22 19:35:57 +00:00
|
|
|
|
|
2017-05-19 03:04:57 +00:00
|
|
|
|
def myPlexAccount(self):
|
|
|
|
|
""" Returns a :class:`~plexapi.myplex.MyPlexAccount` object using the same
|
|
|
|
|
token to access this server. If you are not the owner of this PlexServer
|
2022-02-27 03:26:08 +00:00
|
|
|
|
you're likely to receive an authentication error calling this.
|
2017-05-19 03:04:57 +00:00
|
|
|
|
"""
|
2017-05-27 02:35:33 +00:00
|
|
|
|
if self._myPlexAccount is None:
|
|
|
|
|
from plexapi.myplex import MyPlexAccount
|
2022-12-21 21:01:37 +00:00
|
|
|
|
self._myPlexAccount = MyPlexAccount(token=self._token, session=self._session)
|
2017-05-27 02:35:33 +00:00
|
|
|
|
return self._myPlexAccount
|
2017-05-19 03:04:57 +00:00
|
|
|
|
|
|
|
|
|
def _myPlexClientPorts(self):
|
2017-05-27 02:35:33 +00:00
|
|
|
|
""" Sometimes the PlexServer does not properly advertise port numbers required
|
2022-02-27 03:26:08 +00:00
|
|
|
|
to connect. This attempts to look up device port number from plex.tv.
|
2017-05-27 02:35:33 +00:00
|
|
|
|
See issue #126: Make PlexServer.clients() more user friendly.
|
|
|
|
|
https://github.com/pkkid/python-plexapi/issues/126
|
|
|
|
|
"""
|
2017-05-19 03:04:57 +00:00
|
|
|
|
try:
|
|
|
|
|
ports = {}
|
|
|
|
|
account = self.myPlexAccount()
|
|
|
|
|
for device in account.devices():
|
|
|
|
|
if device.connections and ':' in device.connections[0][6:]:
|
|
|
|
|
ports[device.clientIdentifier] = device.connections[0].split(':')[-1]
|
|
|
|
|
return ports
|
|
|
|
|
except Exception as err:
|
2017-07-30 18:49:06 +00:00
|
|
|
|
log.warning('Unable to fetch client ports from myPlex: %s', err)
|
2017-05-19 03:04:57 +00:00
|
|
|
|
return ports
|
|
|
|
|
|
2020-11-16 05:21:08 +00:00
|
|
|
|
def browse(self, path=None, includeFiles=True):
|
2020-11-16 01:54:48 +00:00
|
|
|
|
""" Browse the system file path using the Plex API.
|
|
|
|
|
Returns list of :class:`~plexapi.library.Path` and :class:`~plexapi.library.File` objects.
|
|
|
|
|
|
|
|
|
|
Parameters:
|
2020-11-21 01:00:45 +00:00
|
|
|
|
path (:class:`~plexapi.library.Path` or str, optional): Full path to browse.
|
2020-11-16 05:21:08 +00:00
|
|
|
|
includeFiles (bool): True to include files when browsing (Default).
|
|
|
|
|
False to only return folders.
|
2020-11-16 01:54:48 +00:00
|
|
|
|
"""
|
2020-11-16 05:21:08 +00:00
|
|
|
|
if isinstance(path, Path):
|
|
|
|
|
key = path.key
|
|
|
|
|
elif path is not None:
|
|
|
|
|
base64path = utils.base64str(path)
|
2022-08-28 05:56:01 +00:00
|
|
|
|
key = f'/services/browse/{base64path}'
|
2020-11-16 01:54:48 +00:00
|
|
|
|
else:
|
2020-11-16 05:21:08 +00:00
|
|
|
|
key = '/services/browse'
|
2023-10-31 23:30:53 +00:00
|
|
|
|
key += f'?includeFiles={int(includeFiles)}' # starting with PMS v1.32.7.7621 this must set explicitly
|
2020-11-16 01:54:48 +00:00
|
|
|
|
return self.fetchItems(key)
|
|
|
|
|
|
|
|
|
|
def walk(self, path=None):
|
|
|
|
|
""" Walk the system file tree using the Plex API similar to `os.walk`.
|
|
|
|
|
Yields a 3-tuple `(path, paths, files)` where
|
|
|
|
|
`path` is a string of the directory path,
|
|
|
|
|
`paths` is a list of :class:`~plexapi.library.Path` objects, and
|
|
|
|
|
`files` is a list of :class:`~plexapi.library.File` objects.
|
|
|
|
|
|
|
|
|
|
Parameters:
|
2020-11-21 01:00:45 +00:00
|
|
|
|
path (:class:`~plexapi.library.Path` or str, optional): Full path to walk.
|
2020-11-16 01:54:48 +00:00
|
|
|
|
"""
|
|
|
|
|
paths = []
|
|
|
|
|
files = []
|
2020-11-16 05:10:13 +00:00
|
|
|
|
for item in self.browse(path):
|
|
|
|
|
if isinstance(item, Path):
|
2020-11-16 01:54:48 +00:00
|
|
|
|
paths.append(item)
|
2020-11-16 05:10:13 +00:00
|
|
|
|
elif isinstance(item, File):
|
2020-11-16 01:54:48 +00:00
|
|
|
|
files.append(item)
|
2020-11-16 05:10:13 +00:00
|
|
|
|
|
|
|
|
|
if isinstance(path, Path):
|
|
|
|
|
path = path.path
|
|
|
|
|
|
|
|
|
|
yield path or '', paths, files
|
2020-11-16 01:54:48 +00:00
|
|
|
|
|
|
|
|
|
for _path in paths:
|
2020-11-16 05:10:13 +00:00
|
|
|
|
for path, paths, files in self.walk(_path):
|
2020-11-16 01:54:48 +00:00
|
|
|
|
yield path, paths, files
|
|
|
|
|
|
2021-10-26 21:47:34 +00:00
|
|
|
|
def isBrowsable(self, path):
|
|
|
|
|
""" Returns True if the Plex server can browse the given path.
|
|
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
path (:class:`~plexapi.library.Path` or str): Full path to browse.
|
|
|
|
|
"""
|
|
|
|
|
if isinstance(path, Path):
|
|
|
|
|
path = path.path
|
|
|
|
|
paths = [p.path for p in self.browse(os.path.dirname(path), includeFiles=False)]
|
|
|
|
|
return path in paths
|
|
|
|
|
|
2014-12-29 03:21:58 +00:00
|
|
|
|
def clients(self):
|
2017-04-28 01:21:40 +00:00
|
|
|
|
""" Returns list of all :class:`~plexapi.client.PlexClient` objects connected to server. """
|
2014-12-29 03:21:58 +00:00
|
|
|
|
items = []
|
2017-05-19 03:04:57 +00:00
|
|
|
|
ports = None
|
2017-02-09 04:29:17 +00:00
|
|
|
|
for elem in self.query('/clients'):
|
2017-02-26 21:47:40 +00:00
|
|
|
|
port = elem.attrib.get('port')
|
2017-05-19 03:04:57 +00:00
|
|
|
|
if not port:
|
2017-07-30 18:49:06 +00:00
|
|
|
|
log.warning('%s did not advertise a port, checking plex.tv.', elem.attrib.get('name'))
|
2017-05-19 03:04:57 +00:00
|
|
|
|
ports = self._myPlexClientPorts() if ports is None else ports
|
|
|
|
|
port = ports.get(elem.attrib.get('machineIdentifier'))
|
2022-08-28 05:56:01 +00:00
|
|
|
|
baseurl = f"http://{elem.attrib['host']}:{port}"
|
2017-07-30 18:49:06 +00:00
|
|
|
|
items.append(PlexClient(baseurl=baseurl, server=self,
|
|
|
|
|
token=self._token, data=elem, connect=False))
|
|
|
|
|
|
2014-12-29 03:21:58 +00:00
|
|
|
|
return items
|
|
|
|
|
|
|
|
|
|
def client(self, name):
|
2024-06-22 18:13:14 +00:00
|
|
|
|
""" Returns the :class:`~plexapi.client.PlexClient` that matches the specified name
|
|
|
|
|
or machine identifier.
|
2016-12-15 23:55:48 +00:00
|
|
|
|
|
2017-02-03 06:29:19 +00:00
|
|
|
|
Parameters:
|
2024-06-22 18:13:14 +00:00
|
|
|
|
name (str): Name or machine identifier of the client to return.
|
2016-12-15 23:06:12 +00:00
|
|
|
|
|
2017-02-03 06:29:19 +00:00
|
|
|
|
Raises:
|
2021-01-03 00:44:18 +00:00
|
|
|
|
:exc:`~plexapi.exceptions.NotFound`: Unknown client name.
|
2016-12-15 23:06:12 +00:00
|
|
|
|
"""
|
2017-07-30 18:49:06 +00:00
|
|
|
|
for client in self.clients():
|
2024-06-22 18:13:14 +00:00
|
|
|
|
if client and (client.title == name or client.machineIdentifier == name):
|
2017-07-30 18:49:06 +00:00
|
|
|
|
return client
|
|
|
|
|
|
2022-08-28 05:56:01 +00:00
|
|
|
|
raise NotFound(f'Unknown client name: {name}')
|
2014-12-29 03:21:58 +00:00
|
|
|
|
|
2021-05-28 05:50:30 +00:00
|
|
|
|
def createCollection(self, title, section, items=None, smart=False, limit=None,
|
|
|
|
|
libtype=None, sort=None, filters=None, **kwargs):
|
|
|
|
|
""" Creates and returns a new :class:`~plexapi.collection.Collection`.
|
|
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
title (str): Title of the collection.
|
|
|
|
|
section (:class:`~plexapi.library.LibrarySection`, str): The library section to create the collection in.
|
2021-05-30 00:58:55 +00:00
|
|
|
|
items (List): Regular collections only, list of :class:`~plexapi.audio.Audio`,
|
|
|
|
|
:class:`~plexapi.video.Video`, or :class:`~plexapi.photo.Photo` objects to be added to the collection.
|
2021-05-28 05:50:30 +00:00
|
|
|
|
smart (bool): True to create a smart collection. Default False.
|
|
|
|
|
limit (int): Smart collections only, limit the number of items in the collection.
|
|
|
|
|
libtype (str): Smart collections only, the specific type of content to filter
|
2021-07-27 01:46:30 +00:00
|
|
|
|
(movie, show, season, episode, artist, album, track, photoalbum, photo).
|
2021-05-28 05:50:30 +00:00
|
|
|
|
sort (str or list, optional): Smart collections only, a string of comma separated sort fields
|
|
|
|
|
or a list of sort fields in the format ``column:dir``.
|
2021-05-30 00:58:55 +00:00
|
|
|
|
See :func:`~plexapi.library.LibrarySection.search` for more info.
|
2021-05-28 05:50:30 +00:00
|
|
|
|
filters (dict): Smart collections only, a dictionary of advanced filters.
|
2021-05-30 00:58:55 +00:00
|
|
|
|
See :func:`~plexapi.library.LibrarySection.search` for more info.
|
2021-05-28 05:50:30 +00:00
|
|
|
|
**kwargs (dict): Smart collections only, additional custom filters to apply to the
|
2021-05-30 00:58:55 +00:00
|
|
|
|
search results. See :func:`~plexapi.library.LibrarySection.search` for more info.
|
2021-05-28 05:50:30 +00:00
|
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
|
:class:`plexapi.exceptions.BadRequest`: When no items are included to create the collection.
|
|
|
|
|
:class:`plexapi.exceptions.BadRequest`: When mixing media types in the collection.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
:class:`~plexapi.collection.Collection`: A new instance of the created Collection.
|
2022-12-21 19:32:43 +00:00
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
# Create a regular collection
|
|
|
|
|
movies = plex.library.section("Movies")
|
|
|
|
|
movie1 = movies.get("Big Buck Bunny")
|
|
|
|
|
movie2 = movies.get("Sita Sings the Blues")
|
|
|
|
|
collection = plex.createCollection(
|
|
|
|
|
title="Favorite Movies",
|
|
|
|
|
section=movies,
|
|
|
|
|
items=[movie1, movie2]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Create a smart collection
|
|
|
|
|
collection = plex.createCollection(
|
|
|
|
|
title="Recently Aired Comedy TV Shows",
|
|
|
|
|
section="TV Shows",
|
|
|
|
|
smart=True,
|
|
|
|
|
sort="episode.originallyAvailableAt:desc",
|
|
|
|
|
filters={"episode.originallyAvailableAt>>": "4w", "genre": "comedy"}
|
|
|
|
|
)
|
2023-05-24 20:55:22 +00:00
|
|
|
|
|
2021-05-28 05:50:30 +00:00
|
|
|
|
"""
|
|
|
|
|
return Collection.create(
|
|
|
|
|
self, title, section, items=items, smart=smart, limit=limit,
|
|
|
|
|
libtype=libtype, sort=sort, filters=filters, **kwargs)
|
|
|
|
|
|
|
|
|
|
def createPlaylist(self, title, section=None, items=None, smart=False, limit=None,
|
2022-12-21 19:32:43 +00:00
|
|
|
|
libtype=None, sort=None, filters=None, m3ufilepath=None, **kwargs):
|
2017-02-03 06:29:19 +00:00
|
|
|
|
""" Creates and returns a new :class:`~plexapi.playlist.Playlist`.
|
2017-02-14 21:12:56 +00:00
|
|
|
|
|
2017-02-03 06:29:19 +00:00
|
|
|
|
Parameters:
|
2021-05-28 02:53:38 +00:00
|
|
|
|
title (str): Title of the playlist.
|
2022-12-21 19:32:43 +00:00
|
|
|
|
section (:class:`~plexapi.library.LibrarySection`, str): Smart playlists and m3u import only,
|
|
|
|
|
the library section to create the playlist in.
|
2021-05-30 00:58:55 +00:00
|
|
|
|
items (List): Regular playlists only, list of :class:`~plexapi.audio.Audio`,
|
|
|
|
|
:class:`~plexapi.video.Video`, or :class:`~plexapi.photo.Photo` objects to be added to the playlist.
|
2021-05-28 02:53:38 +00:00
|
|
|
|
smart (bool): True to create a smart playlist. Default False.
|
|
|
|
|
limit (int): Smart playlists only, limit the number of items in the playlist.
|
2021-07-27 01:46:30 +00:00
|
|
|
|
libtype (str): Smart playlists only, the specific type of content to filter
|
|
|
|
|
(movie, show, season, episode, artist, album, track, photoalbum, photo).
|
2021-05-28 02:53:38 +00:00
|
|
|
|
sort (str or list, optional): Smart playlists only, a string of comma separated sort fields
|
|
|
|
|
or a list of sort fields in the format ``column:dir``.
|
2021-05-30 00:58:55 +00:00
|
|
|
|
See :func:`~plexapi.library.LibrarySection.search` for more info.
|
2021-05-28 02:53:38 +00:00
|
|
|
|
filters (dict): Smart playlists only, a dictionary of advanced filters.
|
2021-05-30 00:58:55 +00:00
|
|
|
|
See :func:`~plexapi.library.LibrarySection.search` for more info.
|
2022-12-21 19:32:43 +00:00
|
|
|
|
m3ufilepath (str): Music playlists only, the full file path to an m3u file to import.
|
|
|
|
|
Note: This will overwrite any playlist previously created from the same m3u file.
|
2021-05-28 02:53:38 +00:00
|
|
|
|
**kwargs (dict): Smart playlists only, additional custom filters to apply to the
|
2021-05-30 00:58:55 +00:00
|
|
|
|
search results. See :func:`~plexapi.library.LibrarySection.search` for more info.
|
2021-05-28 02:53:38 +00:00
|
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
|
:class:`plexapi.exceptions.BadRequest`: When no items are included to create the playlist.
|
|
|
|
|
:class:`plexapi.exceptions.BadRequest`: When mixing media types in the playlist.
|
2022-12-21 19:32:43 +00:00
|
|
|
|
:class:`plexapi.exceptions.BadRequest`: When attempting to import m3u file into non-music library.
|
|
|
|
|
:class:`plexapi.exceptions.BadRequest`: When failed to import m3u file.
|
2021-05-28 02:53:38 +00:00
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
:class:`~plexapi.playlist.Playlist`: A new instance of the created Playlist.
|
2022-12-21 19:32:43 +00:00
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
# Create a regular playlist
|
|
|
|
|
episodes = plex.library.section("TV Shows").get("Game of Thrones").episodes()
|
|
|
|
|
playlist = plex.createPlaylist(
|
|
|
|
|
title="GoT Episodes",
|
|
|
|
|
items=episodes
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Create a smart playlist
|
|
|
|
|
playlist = plex.createPlaylist(
|
|
|
|
|
title="Top 10 Unwatched Movies",
|
|
|
|
|
section="Movies",
|
|
|
|
|
smart=True,
|
|
|
|
|
limit=10,
|
|
|
|
|
sort="audienceRating:desc",
|
|
|
|
|
filters={"audienceRating>>": 8.0, "unwatched": True}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Create a music playlist from an m3u file
|
|
|
|
|
playlist = plex.createPlaylist(
|
|
|
|
|
title="Favorite Tracks",
|
|
|
|
|
section="Music",
|
|
|
|
|
m3ufilepath="/path/to/playlist.m3u"
|
|
|
|
|
)
|
2023-05-24 20:55:22 +00:00
|
|
|
|
|
2016-12-15 23:55:48 +00:00
|
|
|
|
"""
|
2021-05-28 05:50:30 +00:00
|
|
|
|
return Playlist.create(
|
|
|
|
|
self, title, section=section, items=items, smart=smart, limit=limit,
|
2022-12-21 19:32:43 +00:00
|
|
|
|
libtype=libtype, sort=sort, filters=filters, m3ufilepath=m3ufilepath, **kwargs)
|
2016-04-11 03:49:23 +00:00
|
|
|
|
|
2017-02-14 21:12:56 +00:00
|
|
|
|
def createPlayQueue(self, item, **kwargs):
|
2017-02-03 06:29:19 +00:00
|
|
|
|
""" Creates and returns a new :class:`~plexapi.playqueue.PlayQueue`.
|
|
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
item (Media or Playlist): Media or playlist to add to PlayQueue.
|
2020-09-11 21:23:27 +00:00
|
|
|
|
kwargs (dict): See `~plexapi.playqueue.PlayQueue.create`.
|
2017-02-03 06:29:19 +00:00
|
|
|
|
"""
|
2017-02-14 21:12:56 +00:00
|
|
|
|
return PlayQueue.create(self, item, **kwargs)
|
2014-12-29 03:21:58 +00:00
|
|
|
|
|
2023-05-24 18:37:37 +00:00
|
|
|
|
def downloadDatabases(self, savepath=None, unpack=False, showstatus=False):
|
2017-05-27 02:35:33 +00:00
|
|
|
|
""" Download databases.
|
|
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
savepath (str): Defaults to current working dir.
|
|
|
|
|
unpack (bool): Unpack the zip file.
|
2023-05-24 18:37:37 +00:00
|
|
|
|
showstatus(bool): Display a progressbar.
|
2017-05-27 02:35:33 +00:00
|
|
|
|
"""
|
2017-02-27 04:59:46 +00:00
|
|
|
|
url = self.url('/diagnostics/databases')
|
2023-05-24 18:37:37 +00:00
|
|
|
|
filepath = utils.download(url, self._token, None, savepath, self._session, unpack=unpack, showstatus=showstatus)
|
2017-02-27 04:59:46 +00:00
|
|
|
|
return filepath
|
|
|
|
|
|
2023-05-24 18:37:37 +00:00
|
|
|
|
def downloadLogs(self, savepath=None, unpack=False, showstatus=False):
|
2017-05-27 02:35:33 +00:00
|
|
|
|
""" Download server logs.
|
|
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
savepath (str): Defaults to current working dir.
|
|
|
|
|
unpack (bool): Unpack the zip file.
|
2023-05-24 18:37:37 +00:00
|
|
|
|
showstatus(bool): Display a progressbar.
|
2017-05-27 02:35:33 +00:00
|
|
|
|
"""
|
2017-02-27 04:59:46 +00:00
|
|
|
|
url = self.url('/diagnostics/logs')
|
2023-05-24 18:37:37 +00:00
|
|
|
|
filepath = utils.download(url, self._token, None, savepath, self._session, unpack=unpack, showstatus=showstatus)
|
2017-02-27 04:59:46 +00:00
|
|
|
|
return filepath
|
|
|
|
|
|
2022-05-17 02:51:39 +00:00
|
|
|
|
def butlerTasks(self):
|
|
|
|
|
""" Return a list of :class:`~plexapi.base.ButlerTask` objects. """
|
|
|
|
|
return self.fetchItems('/butler')
|
|
|
|
|
|
|
|
|
|
def runButlerTask(self, task):
|
|
|
|
|
""" Manually run a butler task immediately instead of waiting for the scheduled task to run.
|
|
|
|
|
Note: The butler task is run asynchronously. Check Plex Web to monitor activity.
|
2023-08-29 03:29:39 +00:00
|
|
|
|
|
2022-05-17 02:51:39 +00:00
|
|
|
|
Parameters:
|
|
|
|
|
task (str): The name of the task to run. (e.g. 'BackupDatabase')
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
availableTasks = [task.name for task in plex.butlerTasks()]
|
|
|
|
|
print("Available butler tasks:", availableTasks)
|
2023-05-24 20:55:22 +00:00
|
|
|
|
|
2022-05-17 02:51:39 +00:00
|
|
|
|
"""
|
2023-08-27 21:10:18 +00:00
|
|
|
|
validTasks = [_task.name for _task in self.butlerTasks()]
|
2022-05-17 02:51:39 +00:00
|
|
|
|
if task not in validTasks:
|
|
|
|
|
raise BadRequest(
|
|
|
|
|
f'Invalid butler task: {task}. Available tasks are: {validTasks}'
|
|
|
|
|
)
|
|
|
|
|
self.query(f'/butler/{task}', method=self._session.post)
|
2022-08-26 21:44:50 +00:00
|
|
|
|
return self
|
2022-05-17 02:51:39 +00:00
|
|
|
|
|
2021-02-15 05:59:11 +00:00
|
|
|
|
@deprecated('use "checkForUpdate" instead')
|
2017-07-18 15:59:23 +00:00
|
|
|
|
def check_for_update(self, force=True, download=False):
|
2022-05-17 02:51:39 +00:00
|
|
|
|
return self.checkForUpdate(force=force, download=download)
|
2021-02-15 05:59:11 +00:00
|
|
|
|
|
|
|
|
|
def checkForUpdate(self, force=True, download=False):
|
2023-10-04 04:18:18 +00:00
|
|
|
|
""" Returns a :class:`~plexapi.server.Release` object containing release info
|
|
|
|
|
if an update is available or None if no update is available.
|
2017-07-18 15:59:23 +00:00
|
|
|
|
|
2022-05-17 02:51:39 +00:00
|
|
|
|
Parameters:
|
2017-07-18 15:59:23 +00:00
|
|
|
|
force (bool): Force server to check for new releases
|
|
|
|
|
download (bool): Download if a update is available.
|
|
|
|
|
"""
|
2022-08-28 05:56:01 +00:00
|
|
|
|
part = f'/updater/check?download={1 if download else 0}'
|
2017-07-18 15:59:23 +00:00
|
|
|
|
if force:
|
|
|
|
|
self.query(part, method=self._session.put)
|
2018-09-14 18:03:23 +00:00
|
|
|
|
releases = self.fetchItems('/updater/status')
|
|
|
|
|
if len(releases):
|
|
|
|
|
return releases[0]
|
2017-07-18 15:59:23 +00:00
|
|
|
|
|
2017-07-17 23:34:28 +00:00
|
|
|
|
def isLatest(self):
|
2023-10-04 04:18:18 +00:00
|
|
|
|
""" Returns True if the installed version of Plex Media Server is the latest. """
|
|
|
|
|
release = self.checkForUpdate(force=True)
|
|
|
|
|
return release is None
|
|
|
|
|
|
|
|
|
|
def canInstallUpdate(self):
|
|
|
|
|
""" Returns True if the newest version of Plex Media Server can be installed automatically.
|
|
|
|
|
(e.g. Windows and Mac can install updates automatically, but Docker and NAS devices cannot.)
|
|
|
|
|
"""
|
2023-09-17 23:04:41 +00:00
|
|
|
|
release = self.query('/updater/status')
|
|
|
|
|
return utils.cast(bool, release.get('canInstall'))
|
2017-07-18 15:59:23 +00:00
|
|
|
|
|
|
|
|
|
def installUpdate(self):
|
2023-10-04 04:18:18 +00:00
|
|
|
|
""" Automatically install the newest version of Plex Media Server. """
|
2017-07-18 21:20:49 +00:00
|
|
|
|
# We can add this but dunno how useful this is since it sometimes
|
|
|
|
|
# requires user action using a gui.
|
2017-09-30 06:44:24 +00:00
|
|
|
|
part = '/updater/apply'
|
2021-02-15 05:59:11 +00:00
|
|
|
|
release = self.checkForUpdate(force=True, download=True)
|
2017-07-30 05:05:27 +00:00
|
|
|
|
if release and release.version != self.version:
|
2017-07-18 15:59:23 +00:00
|
|
|
|
# figure out what method this is..
|
|
|
|
|
return self.query(part, method=self._session.put)
|
2017-07-17 23:34:28 +00:00
|
|
|
|
|
2023-05-24 21:50:30 +00:00
|
|
|
|
def history(self, maxresults=None, mindate=None, ratingKey=None, accountID=None, librarySectionID=None):
|
2019-06-03 03:12:07 +00:00
|
|
|
|
""" Returns a list of media items from watched history. If there are many results, they will
|
|
|
|
|
be fetched from the server in batches of X_PLEX_CONTAINER_SIZE amounts. If you're only
|
|
|
|
|
looking for the first <num> results, it would be wise to set the maxresults option to that
|
|
|
|
|
amount so this functions doesn't iterate over all results on the server.
|
|
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
maxresults (int): Only return the specified number of results (optional).
|
2019-06-29 20:16:55 +00:00
|
|
|
|
mindate (datetime): Min datetime to return results from. This really helps speed
|
2019-06-03 03:12:07 +00:00
|
|
|
|
up the result listing. For example: datetime.now() - timedelta(days=7)
|
2019-11-14 22:28:46 +00:00
|
|
|
|
ratingKey (int/str) Request history for a specific ratingKey item.
|
2019-11-16 21:35:20 +00:00
|
|
|
|
accountID (int/str) Request history for a specific account ID.
|
|
|
|
|
librarySectionID (int/str) Request history for a specific library section ID.
|
2019-06-03 03:12:07 +00:00
|
|
|
|
"""
|
2019-08-06 20:55:03 +00:00
|
|
|
|
args = {'sort': 'viewedAt:desc'}
|
2019-11-14 17:21:49 +00:00
|
|
|
|
if ratingKey:
|
|
|
|
|
args['metadataItemID'] = ratingKey
|
2019-11-16 21:35:20 +00:00
|
|
|
|
if accountID:
|
|
|
|
|
args['accountID'] = accountID
|
|
|
|
|
if librarySectionID:
|
|
|
|
|
args['librarySectionID'] = librarySectionID
|
2019-06-03 03:12:07 +00:00
|
|
|
|
if mindate:
|
|
|
|
|
args['viewedAt>'] = int(mindate.timestamp())
|
2023-08-29 03:29:39 +00:00
|
|
|
|
|
2023-05-24 21:50:30 +00:00
|
|
|
|
key = f'/status/sessions/history/all{utils.joinArgs(args)}'
|
|
|
|
|
return self.fetchItems(key, maxresults=maxresults)
|
2016-12-15 23:06:12 +00:00
|
|
|
|
|
2021-07-27 01:45:58 +00:00
|
|
|
|
def playlists(self, playlistType=None, sectionId=None, title=None, sort=None, **kwargs):
|
2021-05-27 07:26:53 +00:00
|
|
|
|
""" Returns a list of all :class:`~plexapi.playlist.Playlist` objects on the server.
|
|
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
playlistType (str, optional): The type of playlists to return (audio, video, photo).
|
|
|
|
|
Default returns all playlists.
|
2021-07-27 01:45:58 +00:00
|
|
|
|
sectionId (int, optional): The section ID (key) of the library to search within.
|
|
|
|
|
title (str, optional): General string query to search for. Partial string matches are allowed.
|
|
|
|
|
sort (str or list, optional): A string of comma separated sort fields in the format ``column:dir``.
|
2021-05-27 07:26:53 +00:00
|
|
|
|
"""
|
2021-07-27 01:45:58 +00:00
|
|
|
|
args = {}
|
|
|
|
|
if playlistType is not None:
|
|
|
|
|
args['playlistType'] = playlistType
|
|
|
|
|
if sectionId is not None:
|
|
|
|
|
args['sectionID'] = sectionId
|
|
|
|
|
if title is not None:
|
|
|
|
|
args['title'] = title
|
|
|
|
|
if sort is not None:
|
|
|
|
|
# TODO: Automatically retrieve and validate sort field similar to LibrarySection.search()
|
|
|
|
|
args['sort'] = sort
|
|
|
|
|
|
2022-08-28 05:56:01 +00:00
|
|
|
|
key = f'/playlists{utils.joinArgs(args)}'
|
2021-07-27 01:45:58 +00:00
|
|
|
|
return self.fetchItems(key, **kwargs)
|
2016-12-15 23:06:12 +00:00
|
|
|
|
|
2017-02-03 06:29:19 +00:00
|
|
|
|
def playlist(self, title):
|
|
|
|
|
""" Returns the :class:`~plexapi.client.Playlist` that matches the specified title.
|
2016-12-15 23:55:48 +00:00
|
|
|
|
|
2017-02-03 06:29:19 +00:00
|
|
|
|
Parameters:
|
|
|
|
|
title (str): Title of the playlist to return.
|
2016-12-15 23:55:48 +00:00
|
|
|
|
|
2017-02-03 06:29:19 +00:00
|
|
|
|
Raises:
|
2021-07-27 01:45:58 +00:00
|
|
|
|
:exc:`~plexapi.exceptions.NotFound`: Unable to find playlist.
|
2016-12-15 23:55:48 +00:00
|
|
|
|
"""
|
2021-07-27 01:45:58 +00:00
|
|
|
|
try:
|
|
|
|
|
return self.playlists(title=title, title__iexact=title)[0]
|
|
|
|
|
except IndexError:
|
2022-08-28 05:56:01 +00:00
|
|
|
|
raise NotFound(f'Unable to find playlist with title "{title}".') from None
|
2014-12-29 03:21:58 +00:00
|
|
|
|
|
2020-01-29 14:15:45 +00:00
|
|
|
|
def optimizedItems(self, removeAll=None):
|
2019-10-10 14:43:52 +00:00
|
|
|
|
""" Returns list of all :class:`~plexapi.media.Optimized` objects connected to server. """
|
2020-01-29 14:15:45 +00:00
|
|
|
|
if removeAll is True:
|
|
|
|
|
key = '/playlists/generators?type=42'
|
|
|
|
|
self.query(key, method=self._server._session.delete)
|
|
|
|
|
else:
|
|
|
|
|
backgroundProcessing = self.fetchItem('/playlists?type=42')
|
2022-08-28 05:56:01 +00:00
|
|
|
|
return self.fetchItems(f'{backgroundProcessing.key}/items', cls=Optimized)
|
2019-10-09 03:27:23 +00:00
|
|
|
|
|
2021-05-14 23:28:59 +00:00
|
|
|
|
@deprecated('use "plexapi.media.Optimized.items()" instead')
|
2020-01-30 15:45:14 +00:00
|
|
|
|
def optimizedItem(self, optimizedID):
|
|
|
|
|
""" Returns single queued optimized item :class:`~plexapi.media.Video` object.
|
|
|
|
|
Allows for using optimized item ID to connect back to source item.
|
|
|
|
|
"""
|
2019-10-09 03:27:23 +00:00
|
|
|
|
|
2020-01-27 19:17:23 +00:00
|
|
|
|
backgroundProcessing = self.fetchItem('/playlists?type=42')
|
2022-08-28 05:56:01 +00:00
|
|
|
|
return self.fetchItem(f'{backgroundProcessing.key}/items/{optimizedID}/items')
|
2019-10-09 03:27:23 +00:00
|
|
|
|
|
2020-01-29 14:16:13 +00:00
|
|
|
|
def conversions(self, pause=None):
|
2019-10-10 15:12:34 +00:00
|
|
|
|
""" Returns list of all :class:`~plexapi.media.Conversion` objects connected to server. """
|
2020-01-29 14:16:13 +00:00
|
|
|
|
if pause is True:
|
|
|
|
|
self.query('/:/prefs?BackgroundQueueIdlePaused=1', method=self._server._session.put)
|
|
|
|
|
elif pause is False:
|
|
|
|
|
self.query('/:/prefs?BackgroundQueueIdlePaused=0', method=self._server._session.put)
|
|
|
|
|
else:
|
|
|
|
|
return self.fetchItems('/playQueues/1', cls=Conversion)
|
2019-10-10 15:12:34 +00:00
|
|
|
|
|
2020-01-29 14:11:07 +00:00
|
|
|
|
def currentBackgroundProcess(self):
|
|
|
|
|
""" Returns list of all :class:`~plexapi.media.TranscodeJob` objects running or paused on server. """
|
|
|
|
|
return self.fetchItems('/status/sessions/background')
|
2019-10-10 15:12:34 +00:00
|
|
|
|
|
2024-04-19 19:00:24 +00:00
|
|
|
|
def query(self, key, method=None, headers=None, params=None, timeout=None, **kwargs):
|
2017-02-09 04:29:17 +00:00
|
|
|
|
""" Main method used to handle HTTPS requests to the Plex server. This method helps
|
|
|
|
|
by encoding the response to utf-8 and parsing the returned XML into and
|
|
|
|
|
ElementTree object. Returns None if no data exists in the response.
|
|
|
|
|
"""
|
2017-04-15 00:47:59 +00:00
|
|
|
|
url = self.url(key)
|
2017-02-09 04:29:17 +00:00
|
|
|
|
method = method or self._session.get
|
2023-08-30 16:41:12 +00:00
|
|
|
|
timeout = timeout or self._timeout
|
2017-02-09 04:29:17 +00:00
|
|
|
|
log.debug('%s %s', method.__name__.upper(), url)
|
|
|
|
|
headers = self._headers(**headers or {})
|
2024-04-19 19:00:24 +00:00
|
|
|
|
response = method(url, headers=headers, params=params, timeout=timeout, **kwargs)
|
2020-10-08 17:51:19 +00:00
|
|
|
|
if response.status_code not in (200, 201, 204):
|
2017-02-09 04:29:17 +00:00
|
|
|
|
codename = codes.get(response.status_code)[0]
|
2017-05-27 02:35:33 +00:00
|
|
|
|
errtext = response.text.replace('\n', ' ')
|
2022-08-28 05:56:01 +00:00
|
|
|
|
message = f'({response.status_code}) {codename}; {response.url} {errtext}'
|
2020-04-09 20:56:26 +00:00
|
|
|
|
if response.status_code == 401:
|
|
|
|
|
raise Unauthorized(message)
|
2020-04-15 22:09:27 +00:00
|
|
|
|
elif response.status_code == 404:
|
|
|
|
|
raise NotFound(message)
|
2020-04-09 20:56:26 +00:00
|
|
|
|
else:
|
|
|
|
|
raise BadRequest(message)
|
2024-08-17 21:07:12 +00:00
|
|
|
|
data = utils.cleanXMLString(response.text).encode('utf8')
|
2017-02-25 07:37:30 +00:00
|
|
|
|
return ElementTree.fromstring(data) if data.strip() else None
|
2017-02-09 04:29:17 +00:00
|
|
|
|
|
2021-03-11 05:53:24 +00:00
|
|
|
|
def search(self, query, mediatype=None, limit=None, sectionId=None):
|
2017-02-03 06:29:19 +00:00
|
|
|
|
""" Returns a list of media items or filter categories from the resulting
|
|
|
|
|
`Hub Search <https://www.plex.tv/blog/seek-plex-shall-find-leveling-web-app/>`_
|
|
|
|
|
against all items in your Plex library. This searches genres, actors, directors,
|
|
|
|
|
playlists, as well as all the obvious media titles. It performs spell-checking
|
|
|
|
|
against your search terms (because KUROSAWA is hard to spell). It also provides
|
|
|
|
|
contextual search results. So for example, if you search for 'Pernice', it’ll
|
|
|
|
|
return 'Pernice Brothers' as the artist result, but we’ll also go ahead and
|
|
|
|
|
return your most-listened to albums and tracks from the artist. If you type
|
|
|
|
|
'Arnold' you’ll get a result for the actor, but also the most recently added
|
|
|
|
|
movies he’s in.
|
|
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
query (str): Query to use when searching your library.
|
2021-03-11 05:53:24 +00:00
|
|
|
|
mediatype (str, optional): Limit your search to the specified media type.
|
2021-01-24 20:48:38 +00:00
|
|
|
|
actor, album, artist, autotag, collection, director, episode, game, genre,
|
|
|
|
|
movie, photo, photoalbum, place, playlist, shared, show, tag, track
|
2021-03-11 05:53:24 +00:00
|
|
|
|
limit (int, optional): Limit to the specified number of results per Hub.
|
|
|
|
|
sectionId (int, optional): The section ID (key) of the library to search within.
|
2017-01-03 22:58:35 +00:00
|
|
|
|
"""
|
2017-02-03 06:29:19 +00:00
|
|
|
|
results = []
|
2021-01-24 20:48:38 +00:00
|
|
|
|
params = {
|
|
|
|
|
'query': query,
|
|
|
|
|
'includeCollections': 1,
|
|
|
|
|
'includeExternalMedia': 1}
|
2017-01-03 22:58:35 +00:00
|
|
|
|
if limit:
|
2017-02-03 06:29:19 +00:00
|
|
|
|
params['limit'] = limit
|
2021-03-11 05:53:24 +00:00
|
|
|
|
if sectionId:
|
|
|
|
|
params['sectionId'] = sectionId
|
2022-08-28 05:56:01 +00:00
|
|
|
|
key = f'/hubs/search?{urlencode(params)}'
|
2017-02-13 02:55:55 +00:00
|
|
|
|
for hub in self.fetchItems(key, Hub):
|
2021-01-24 20:48:38 +00:00
|
|
|
|
if mediatype:
|
|
|
|
|
if hub.type == mediatype:
|
|
|
|
|
return hub.items
|
|
|
|
|
else:
|
|
|
|
|
results += hub.items
|
2017-02-03 06:29:19 +00:00
|
|
|
|
return results
|
2016-01-28 12:09:36 +00:00
|
|
|
|
|
2023-05-24 19:03:28 +00:00
|
|
|
|
def continueWatching(self):
|
|
|
|
|
""" Return a list of all items in the Continue Watching hub. """
|
2023-07-27 20:52:08 +00:00
|
|
|
|
return self.fetchItems('/hubs/continueWatching/items')
|
2023-05-24 19:03:28 +00:00
|
|
|
|
|
2015-02-17 20:35:17 +00:00
|
|
|
|
def sessions(self):
|
2017-02-03 06:29:19 +00:00
|
|
|
|
""" Returns a list of all active session (currently playing) media objects. """
|
2017-02-07 06:20:49 +00:00
|
|
|
|
return self.fetchItems('/status/sessions')
|
2016-04-07 05:39:04 +00:00
|
|
|
|
|
2021-01-25 01:33:07 +00:00
|
|
|
|
def transcodeSessions(self):
|
|
|
|
|
""" Returns a list of all active :class:`~plexapi.media.TranscodeSession` objects. """
|
|
|
|
|
return self.fetchItems('/transcode/sessions')
|
|
|
|
|
|
2022-08-06 02:52:09 +00:00
|
|
|
|
def startAlertListener(self, callback=None, callbackError=None):
|
2022-05-16 20:39:42 +00:00
|
|
|
|
""" Creates a websocket connection to the Plex Server to optionally receive
|
2017-02-11 04:26:09 +00:00
|
|
|
|
notifications. These often include messages from Plex about media scans
|
|
|
|
|
as well as updates to currently running Transcode Sessions.
|
|
|
|
|
|
2022-08-06 02:52:09 +00:00
|
|
|
|
Returns a new :class:`~plexapi.alert.AlertListener` object.
|
|
|
|
|
|
|
|
|
|
Note: ``websocket-client`` must be installed in order to use this feature.
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
>> pip install websocket-client
|
2017-02-11 04:26:09 +00:00
|
|
|
|
|
|
|
|
|
Parameters:
|
2022-05-16 20:39:42 +00:00
|
|
|
|
callback (func): Callback function to call on received messages.
|
2022-08-06 02:52:09 +00:00
|
|
|
|
callbackError (func): Callback function to call on errors.
|
2017-02-11 04:26:09 +00:00
|
|
|
|
|
2020-11-23 04:43:59 +00:00
|
|
|
|
Raises:
|
2020-11-23 20:20:56 +00:00
|
|
|
|
:exc:`~plexapi.exception.Unsupported`: Websocket-client not installed.
|
2017-02-11 04:26:09 +00:00
|
|
|
|
"""
|
2022-08-06 02:52:09 +00:00
|
|
|
|
notifier = AlertListener(self, callback, callbackError)
|
2017-02-11 04:08:36 +00:00
|
|
|
|
notifier.start()
|
|
|
|
|
return notifier
|
|
|
|
|
|
2021-11-20 21:53:00 +00:00
|
|
|
|
def transcodeImage(self, imageUrl, height, width,
|
2023-03-10 00:18:27 +00:00
|
|
|
|
opacity=None, saturation=None, blur=None, background=None, blendColor=None,
|
2021-11-20 21:53:00 +00:00
|
|
|
|
minSize=True, upscale=True, imageFormat=None):
|
|
|
|
|
""" Returns the URL for a transcoded image.
|
2017-02-03 06:29:19 +00:00
|
|
|
|
|
|
|
|
|
Parameters:
|
2021-11-20 21:53:00 +00:00
|
|
|
|
imageUrl (str): The URL to the image
|
|
|
|
|
(eg. returned by :func:`~plexapi.mixins.PosterUrlMixin.thumbUrl`
|
|
|
|
|
or :func:`~plexapi.mixins.ArtUrlMixin.artUrl`).
|
|
|
|
|
The URL can be an online image.
|
2017-02-03 06:29:19 +00:00
|
|
|
|
height (int): Height to transcode the image to.
|
|
|
|
|
width (int): Width to transcode the image to.
|
2021-11-20 21:53:00 +00:00
|
|
|
|
opacity (int, optional): Change the opacity of the image (0 to 100)
|
|
|
|
|
saturation (int, optional): Change the saturation of the image (0 to 100).
|
|
|
|
|
blur (int, optional): The blur to apply to the image in pixels (e.g. 3).
|
|
|
|
|
background (str, optional): The background hex colour to apply behind the opacity (e.g. '000000').
|
2023-03-10 00:18:27 +00:00
|
|
|
|
blendColor (str, optional): The hex colour to blend the image with (e.g. '000000').
|
2021-11-20 21:53:00 +00:00
|
|
|
|
minSize (bool, optional): Maintain smallest dimension. Default True.
|
|
|
|
|
upscale (bool, optional): Upscale the image if required. Default True.
|
|
|
|
|
imageFormat (str, optional): 'jpeg' (default) or 'png'.
|
2017-01-02 21:19:07 +00:00
|
|
|
|
"""
|
2021-11-20 21:53:00 +00:00
|
|
|
|
params = {
|
|
|
|
|
'url': imageUrl,
|
|
|
|
|
'height': height,
|
|
|
|
|
'width': width,
|
|
|
|
|
'minSize': int(bool(minSize)),
|
|
|
|
|
'upscale': int(bool(upscale))
|
|
|
|
|
}
|
|
|
|
|
if opacity is not None:
|
|
|
|
|
params['opacity'] = opacity
|
|
|
|
|
if saturation is not None:
|
|
|
|
|
params['saturation'] = saturation
|
|
|
|
|
if blur is not None:
|
|
|
|
|
params['blur'] = blur
|
|
|
|
|
if background is not None:
|
|
|
|
|
params['background'] = str(background).strip('#')
|
2023-03-10 00:18:27 +00:00
|
|
|
|
if blendColor is not None:
|
|
|
|
|
params['blendColor'] = str(blendColor).strip('#')
|
2021-11-20 21:53:00 +00:00
|
|
|
|
if imageFormat is not None:
|
|
|
|
|
params['format'] = imageFormat.lower()
|
|
|
|
|
|
2022-08-28 05:56:01 +00:00
|
|
|
|
key = f'/photo/:/transcode{utils.joinArgs(params)}'
|
2021-11-20 21:53:00 +00:00
|
|
|
|
return self.url(key, includeToken=True)
|
2017-01-02 21:19:07 +00:00
|
|
|
|
|
2018-01-05 02:44:35 +00:00
|
|
|
|
def url(self, key, includeToken=None):
|
|
|
|
|
""" Build a URL string with proper token argument. Token will be appended to the URL
|
|
|
|
|
if either includeToken is True or CONFIG.log.show_secrets is 'true'.
|
|
|
|
|
"""
|
|
|
|
|
if self._token and (includeToken or self._showSecrets):
|
2017-02-13 02:55:55 +00:00
|
|
|
|
delim = '&' if '?' in key else '?'
|
2022-08-28 05:56:01 +00:00
|
|
|
|
return f'{self._baseurl}{key}{delim}X-Plex-Token={self._token}'
|
|
|
|
|
return f'{self._baseurl}{key}'
|
2017-03-06 22:18:10 +00:00
|
|
|
|
|
2018-09-08 15:25:16 +00:00
|
|
|
|
def refreshSynclist(self):
|
|
|
|
|
""" Force PMS to download new SyncList from Plex.tv. """
|
|
|
|
|
return self.query('/sync/refreshSynclists', self._session.put)
|
|
|
|
|
|
|
|
|
|
def refreshContent(self):
|
|
|
|
|
""" Force PMS to refresh content for known SyncLists. """
|
|
|
|
|
return self.query('/sync/refreshContent', self._session.put)
|
|
|
|
|
|
|
|
|
|
def refreshSync(self):
|
|
|
|
|
""" Calls :func:`~plexapi.server.PlexServer.refreshSynclist` and
|
|
|
|
|
:func:`~plexapi.server.PlexServer.refreshContent`, just like the Plex Web UI does when you click 'refresh'.
|
|
|
|
|
"""
|
|
|
|
|
self.refreshSynclist()
|
|
|
|
|
self.refreshContent()
|
|
|
|
|
|
2020-02-26 13:55:24 +00:00
|
|
|
|
def _allowMediaDeletion(self, toggle=False):
|
2020-02-25 21:39:49 +00:00
|
|
|
|
""" Toggle allowMediaDeletion.
|
|
|
|
|
Parameters:
|
|
|
|
|
toggle (bool): True enables Media Deletion
|
2020-02-26 13:55:44 +00:00
|
|
|
|
False or None disable Media Deletion (Default)
|
2020-02-25 21:39:49 +00:00
|
|
|
|
"""
|
2020-02-26 13:56:29 +00:00
|
|
|
|
if self.allowMediaDeletion and toggle is False:
|
|
|
|
|
log.debug('Plex is currently allowed to delete media. Toggling off.')
|
|
|
|
|
elif self.allowMediaDeletion and toggle is True:
|
|
|
|
|
log.debug('Plex is currently allowed to delete media. Toggle set to allow, exiting.')
|
|
|
|
|
raise BadRequest('Plex is currently allowed to delete media. Toggle set to allow, exiting.')
|
|
|
|
|
elif self.allowMediaDeletion is None and toggle is True:
|
|
|
|
|
log.debug('Plex is currently not allowed to delete media. Toggle set to allow.')
|
|
|
|
|
else:
|
|
|
|
|
log.debug('Plex is currently not allowed to delete media. Toggle set to not allow, exiting.')
|
|
|
|
|
raise BadRequest('Plex is currently not allowed to delete media. Toggle set to not allow, exiting.')
|
2020-02-25 21:39:49 +00:00
|
|
|
|
value = 1 if toggle is True else 0
|
2022-08-28 05:56:01 +00:00
|
|
|
|
return self.query(f'/:/prefs?allowMediaDeletion={value}', self._session.put)
|
2020-02-25 21:39:49 +00:00
|
|
|
|
|
2021-01-03 02:01:55 +00:00
|
|
|
|
def bandwidth(self, timespan=None, **kwargs):
|
2021-01-03 01:54:48 +00:00
|
|
|
|
""" Returns a list of :class:`~plexapi.server.StatisticsBandwidth` objects
|
|
|
|
|
with the Plex server dashboard bandwidth data.
|
2021-01-03 00:44:02 +00:00
|
|
|
|
|
|
|
|
|
Parameters:
|
2021-01-03 02:02:29 +00:00
|
|
|
|
timespan (str, optional): The timespan to bin the bandwidth data. Default is seconds.
|
|
|
|
|
Available timespans: seconds, hours, days, weeks, months.
|
2021-01-03 00:44:02 +00:00
|
|
|
|
**kwargs (dict, optional): Any of the available filters that can be applied to the bandwidth data.
|
|
|
|
|
The time frame (at) and bytes can also be filtered using less than or greater than (see examples below).
|
|
|
|
|
|
2021-01-03 01:25:39 +00:00
|
|
|
|
* accountID (int): The :class:`~plexapi.server.SystemAccount` ID to filter.
|
2021-01-03 01:04:00 +00:00
|
|
|
|
* at (datetime): The time frame to filter (inclusive). The time frame can be either:
|
2021-01-03 02:21:50 +00:00
|
|
|
|
1. An exact time frame (e.g. Only December 1st 2020 `at=datetime(2020, 12, 1)`).
|
|
|
|
|
2. Before a specific time (e.g. Before and including December 2020 `at<=datetime(2020, 12, 1)`).
|
|
|
|
|
3. After a specific time (e.g. After and including January 2021 `at>=datetime(2021, 1, 1)`).
|
2021-01-03 01:04:00 +00:00
|
|
|
|
* bytes (int): The amount of bytes to filter (inclusive). The bytes can be either:
|
2021-01-03 02:21:50 +00:00
|
|
|
|
1. An exact number of bytes (not very useful) (e.g. `bytes=1024**3`).
|
|
|
|
|
2. Less than or equal number of bytes (e.g. `bytes<=1024**3`).
|
|
|
|
|
3. Greater than or equal number of bytes (e.g. `bytes>=1024**3`).
|
2021-01-03 01:25:39 +00:00
|
|
|
|
* deviceID (int): The :class:`~plexapi.server.SystemDevice` ID to filter.
|
2021-01-03 00:44:02 +00:00
|
|
|
|
* lan (bool): True to only retrieve local bandwidth, False to only retrieve remote bandwidth.
|
2021-01-03 01:04:00 +00:00
|
|
|
|
Default returns all local and remote bandwidth.
|
2021-01-03 00:44:02 +00:00
|
|
|
|
|
|
|
|
|
Raises:
|
2021-01-03 01:04:00 +00:00
|
|
|
|
:exc:`~plexapi.exceptions.BadRequest`: When applying an invalid timespan or unknown filter.
|
2021-01-03 00:44:02 +00:00
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
from plexapi.server import PlexServer
|
|
|
|
|
plex = PlexServer('http://localhost:32400', token='xxxxxxxxxxxxxxxxxxxx')
|
|
|
|
|
|
2021-01-03 02:21:50 +00:00
|
|
|
|
# Filter bandwidth data for December 2020 and later, and more than 1 GB used.
|
2021-01-03 00:44:02 +00:00
|
|
|
|
filters = {
|
|
|
|
|
'at>': datetime(2020, 12, 1),
|
|
|
|
|
'bytes>': 1024**3
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Retrieve bandwidth data in one day timespans.
|
2021-01-03 02:01:55 +00:00
|
|
|
|
bandwidthData = plex.bandwidth(timespan='days', **filters)
|
2021-01-03 00:44:02 +00:00
|
|
|
|
|
2021-01-03 02:21:50 +00:00
|
|
|
|
# Print out bandwidth usage for each account and device combination.
|
2021-01-03 02:01:55 +00:00
|
|
|
|
for bandwidth in sorted(bandwidthData, key=lambda x: x.at):
|
2021-01-03 00:44:02 +00:00
|
|
|
|
account = bandwidth.account()
|
|
|
|
|
device = bandwidth.device()
|
|
|
|
|
gigabytes = round(bandwidth.bytes / 1024**3, 3)
|
|
|
|
|
local = 'local' if bandwidth.lan else 'remote'
|
|
|
|
|
date = bandwidth.at.strftime('%Y-%m-%d')
|
2022-11-08 21:40:18 +00:00
|
|
|
|
print(f'{account.name} used {gigabytes} GB of {local} bandwidth on {date} from {device.name}')
|
2021-01-03 00:44:02 +00:00
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
params = {}
|
|
|
|
|
|
2021-01-03 02:08:43 +00:00
|
|
|
|
if timespan is None:
|
|
|
|
|
params['timespan'] = 6 # Default to seconds
|
|
|
|
|
else:
|
2021-01-03 00:44:02 +00:00
|
|
|
|
timespans = {
|
|
|
|
|
'seconds': 6,
|
|
|
|
|
'hours': 4,
|
|
|
|
|
'days': 3,
|
|
|
|
|
'weeks': 2,
|
|
|
|
|
'months': 1
|
|
|
|
|
}
|
|
|
|
|
try:
|
|
|
|
|
params['timespan'] = timespans[timespan]
|
|
|
|
|
except KeyError:
|
2022-08-28 05:56:01 +00:00
|
|
|
|
raise BadRequest(f"Invalid timespan specified: {timespan}. "
|
|
|
|
|
f"Available timespans: {', '.join(timespans.keys())}")
|
2021-01-03 00:44:02 +00:00
|
|
|
|
|
|
|
|
|
filters = {'accountID', 'at', 'at<', 'at>', 'bytes', 'bytes<', 'bytes>', 'deviceID', 'lan'}
|
|
|
|
|
|
|
|
|
|
for key, value in kwargs.items():
|
|
|
|
|
if key not in filters:
|
2022-08-28 05:56:01 +00:00
|
|
|
|
raise BadRequest(f'Unknown filter: {key}={value}')
|
2021-01-03 00:44:02 +00:00
|
|
|
|
if key.startswith('at'):
|
|
|
|
|
try:
|
2021-05-27 02:45:12 +00:00
|
|
|
|
value = utils.cast(int, value.timestamp())
|
2021-01-03 00:44:02 +00:00
|
|
|
|
except AttributeError:
|
2022-08-28 05:56:01 +00:00
|
|
|
|
raise BadRequest(f'Time frame filter must be a datetime object: {key}={value}')
|
2021-01-03 00:44:02 +00:00
|
|
|
|
elif key.startswith('bytes') or key == 'lan':
|
2021-05-27 02:45:12 +00:00
|
|
|
|
value = utils.cast(int, value)
|
2021-01-03 00:44:02 +00:00
|
|
|
|
elif key == 'accountID':
|
|
|
|
|
if value == self.myPlexAccount().id:
|
|
|
|
|
value = 1 # The admin account is accountID=1
|
|
|
|
|
params[key] = value
|
|
|
|
|
|
2022-08-28 05:56:01 +00:00
|
|
|
|
key = f'/statistics/bandwidth?{urlencode(params)}'
|
2021-01-03 18:41:38 +00:00
|
|
|
|
return self.fetchItems(key, StatisticsBandwidth)
|
2021-01-03 00:44:02 +00:00
|
|
|
|
|
2021-01-03 02:01:55 +00:00
|
|
|
|
def resources(self):
|
2021-01-03 01:54:48 +00:00
|
|
|
|
""" Returns a list of :class:`~plexapi.server.StatisticsResources` objects
|
|
|
|
|
with the Plex server dashboard resources data. """
|
2021-01-03 00:44:02 +00:00
|
|
|
|
key = '/statistics/resources?timespan=6'
|
2021-01-03 18:41:38 +00:00
|
|
|
|
return self.fetchItems(key, StatisticsResources)
|
2021-01-03 00:44:02 +00:00
|
|
|
|
|
2021-09-26 22:23:09 +00:00
|
|
|
|
def _buildWebURL(self, base=None, endpoint=None, **kwargs):
|
|
|
|
|
""" Build the Plex Web URL for the object.
|
2021-08-04 20:12:33 +00:00
|
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
base (str): The base URL before the fragment (``#!``).
|
|
|
|
|
Default is https://app.plex.tv/desktop.
|
2021-09-26 22:23:09 +00:00
|
|
|
|
endpoint (str): The Plex Web URL endpoint.
|
|
|
|
|
None for server, 'playlist' for playlists, 'details' for all other media types.
|
|
|
|
|
**kwargs (dict): Dictionary of URL parameters.
|
2021-08-04 20:12:33 +00:00
|
|
|
|
"""
|
|
|
|
|
if base is None:
|
|
|
|
|
base = 'https://app.plex.tv/desktop/'
|
|
|
|
|
|
2021-09-26 22:23:09 +00:00
|
|
|
|
if endpoint:
|
2022-08-28 05:56:01 +00:00
|
|
|
|
return f'{base}#!/server/{self.machineIdentifier}/{endpoint}{utils.joinArgs(kwargs)}'
|
2021-09-26 22:23:09 +00:00
|
|
|
|
else:
|
2022-08-28 05:56:01 +00:00
|
|
|
|
return f'{base}#!/media/{self.machineIdentifier}/com.plexapp.plugins.library{utils.joinArgs(kwargs)}'
|
2021-09-26 22:23:09 +00:00
|
|
|
|
|
|
|
|
|
def getWebURL(self, base=None, playlistTab=None):
|
|
|
|
|
""" Returns the Plex Web URL for the server.
|
2021-08-04 20:12:33 +00:00
|
|
|
|
|
2021-09-26 22:23:09 +00:00
|
|
|
|
Parameters:
|
|
|
|
|
base (str): The base URL before the fragment (``#!``).
|
|
|
|
|
Default is https://app.plex.tv/desktop.
|
|
|
|
|
playlistTab (str): The playlist tab (audio, video, photo). Only used for the playlist URL.
|
|
|
|
|
"""
|
|
|
|
|
if playlistTab is not None:
|
2022-08-28 05:56:01 +00:00
|
|
|
|
params = {'source': 'playlists', 'pivot': f'playlists.{playlistTab}'}
|
2021-09-26 22:23:09 +00:00
|
|
|
|
else:
|
|
|
|
|
params = {'key': '/hubs', 'pageType': 'hub'}
|
|
|
|
|
return self._buildWebURL(base=base, **params)
|
2021-08-04 20:12:33 +00:00
|
|
|
|
|
2017-01-02 21:19:07 +00:00
|
|
|
|
|
2017-02-06 04:52:10 +00:00
|
|
|
|
class Account(PlexObject):
|
2017-02-03 06:29:19 +00:00
|
|
|
|
""" Contains the locally cached MyPlex account information. The properties provided don't
|
|
|
|
|
match the :class:`~plexapi.myplex.MyPlexAccount` object very well. I believe this exists
|
|
|
|
|
because access to myplex is not required to get basic plex information. I can't imagine
|
|
|
|
|
object is terribly useful except unless you were needed this information while offline.
|
|
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
server (:class:`~plexapi.server.PlexServer`): PlexServer this account is connected to (optional)
|
|
|
|
|
data (ElementTree): Response from PlexServer used to build this object (optional).
|
|
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
|
authToken (str): Plex authentication token to access the server.
|
|
|
|
|
mappingError (str): Unknown
|
|
|
|
|
mappingErrorMessage (str): Unknown
|
|
|
|
|
mappingState (str): Unknown
|
|
|
|
|
privateAddress (str): Local IP address of the Plex server.
|
|
|
|
|
privatePort (str): Local port of the Plex server.
|
|
|
|
|
publicAddress (str): Public IP address of the Plex server.
|
|
|
|
|
publicPort (str): Public port of the Plex server.
|
|
|
|
|
signInState (str): Signin state for this account (ex: ok).
|
|
|
|
|
subscriptionActive (str): True if the account subscription is active.
|
|
|
|
|
subscriptionFeatures (str): List of features allowed by the server for this account.
|
|
|
|
|
This may be based on your PlexPass subscription. Features include: camera_upload,
|
|
|
|
|
cloudsync, content_filter, dvr, hardware_transcoding, home, lyrics, music_videos,
|
|
|
|
|
pass, photo_autotags, premium_music_metadata, session_bandwidth_restrictions,
|
|
|
|
|
sync, trailers, webhooks' (and maybe more).
|
|
|
|
|
subscriptionState (str): 'Active' if this subscription is active.
|
|
|
|
|
username (str): Plex account username (user@example.com).
|
2016-12-15 23:06:12 +00:00
|
|
|
|
"""
|
2017-02-06 04:52:10 +00:00
|
|
|
|
key = '/myplex/account'
|
|
|
|
|
|
|
|
|
|
def _loadData(self, data):
|
2017-02-04 08:08:47 +00:00
|
|
|
|
self._data = data
|
2016-04-07 05:39:04 +00:00
|
|
|
|
self.authToken = data.attrib.get('authToken')
|
|
|
|
|
self.username = data.attrib.get('username')
|
|
|
|
|
self.mappingState = data.attrib.get('mappingState')
|
|
|
|
|
self.mappingError = data.attrib.get('mappingError')
|
|
|
|
|
self.mappingErrorMessage = data.attrib.get('mappingErrorMessage')
|
|
|
|
|
self.signInState = data.attrib.get('signInState')
|
|
|
|
|
self.publicAddress = data.attrib.get('publicAddress')
|
|
|
|
|
self.publicPort = data.attrib.get('publicPort')
|
|
|
|
|
self.privateAddress = data.attrib.get('privateAddress')
|
|
|
|
|
self.privatePort = data.attrib.get('privatePort')
|
2017-02-03 16:39:46 +00:00
|
|
|
|
self.subscriptionFeatures = utils.toList(data.attrib.get('subscriptionFeatures'))
|
2021-05-27 02:45:12 +00:00
|
|
|
|
self.subscriptionActive = utils.cast(bool, data.attrib.get('subscriptionActive'))
|
2016-04-07 05:39:04 +00:00
|
|
|
|
self.subscriptionState = data.attrib.get('subscriptionState')
|
2019-06-03 04:44:21 +00:00
|
|
|
|
|
|
|
|
|
|
2020-09-16 23:16:01 +00:00
|
|
|
|
class Activity(PlexObject):
|
|
|
|
|
"""A currently running activity on the PlexServer."""
|
|
|
|
|
key = '/activities'
|
|
|
|
|
|
|
|
|
|
def _loadData(self, data):
|
|
|
|
|
self._data = data
|
2021-05-27 02:45:12 +00:00
|
|
|
|
self.cancellable = utils.cast(bool, data.attrib.get('cancellable'))
|
|
|
|
|
self.progress = utils.cast(int, data.attrib.get('progress'))
|
2020-09-16 23:16:01 +00:00
|
|
|
|
self.title = data.attrib.get('title')
|
|
|
|
|
self.subtitle = data.attrib.get('subtitle')
|
|
|
|
|
self.type = data.attrib.get('type')
|
|
|
|
|
self.uuid = data.attrib.get('uuid')
|
|
|
|
|
|
|
|
|
|
|
2021-02-15 05:56:28 +00:00
|
|
|
|
@utils.registerPlexObject
|
|
|
|
|
class Release(PlexObject):
|
|
|
|
|
TAG = 'Release'
|
|
|
|
|
key = '/updater/status'
|
|
|
|
|
|
|
|
|
|
def _loadData(self, data):
|
|
|
|
|
self.download_key = data.attrib.get('key')
|
|
|
|
|
self.version = data.attrib.get('version')
|
|
|
|
|
self.added = data.attrib.get('added')
|
|
|
|
|
self.fixed = data.attrib.get('fixed')
|
|
|
|
|
self.downloadURL = data.attrib.get('downloadURL')
|
|
|
|
|
self.state = data.attrib.get('state')
|
|
|
|
|
|
|
|
|
|
|
2019-06-03 04:44:21 +00:00
|
|
|
|
class SystemAccount(PlexObject):
|
2021-01-03 01:25:39 +00:00
|
|
|
|
""" Represents a single system account.
|
2021-01-03 00:44:02 +00:00
|
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
|
TAG (str): 'Account'
|
|
|
|
|
autoSelectAudio (bool): True or False if the account has automatic audio language enabled.
|
|
|
|
|
defaultAudioLanguage (str): The default audio language code for the account.
|
|
|
|
|
defaultSubtitleLanguage (str): The default subtitle language code for the account.
|
|
|
|
|
id (int): The Plex account ID.
|
|
|
|
|
key (str): API URL (/accounts/<id>)
|
|
|
|
|
name (str): The username of the account.
|
|
|
|
|
subtitleMode (bool): The subtitle mode for the account.
|
|
|
|
|
thumb (str): URL for the account thumbnail.
|
|
|
|
|
"""
|
|
|
|
|
TAG = 'Account'
|
|
|
|
|
|
|
|
|
|
def _loadData(self, data):
|
|
|
|
|
self._data = data
|
2021-05-27 02:45:12 +00:00
|
|
|
|
self.autoSelectAudio = utils.cast(bool, data.attrib.get('autoSelectAudio'))
|
2021-01-03 00:44:02 +00:00
|
|
|
|
self.defaultAudioLanguage = data.attrib.get('defaultAudioLanguage')
|
|
|
|
|
self.defaultSubtitleLanguage = data.attrib.get('defaultSubtitleLanguage')
|
2021-05-27 02:45:12 +00:00
|
|
|
|
self.id = utils.cast(int, data.attrib.get('id'))
|
2021-01-03 00:44:02 +00:00
|
|
|
|
self.key = data.attrib.get('key')
|
|
|
|
|
self.name = data.attrib.get('name')
|
2021-05-27 02:45:12 +00:00
|
|
|
|
self.subtitleMode = utils.cast(int, data.attrib.get('subtitleMode'))
|
2021-01-03 00:44:02 +00:00
|
|
|
|
self.thumb = data.attrib.get('thumb')
|
2021-01-03 01:25:39 +00:00
|
|
|
|
# For backwards compatibility
|
|
|
|
|
self.accountID = self.id
|
|
|
|
|
self.accountKey = self.key
|
2021-01-03 00:44:02 +00:00
|
|
|
|
|
|
|
|
|
|
2021-01-03 01:25:39 +00:00
|
|
|
|
class SystemDevice(PlexObject):
|
|
|
|
|
""" Represents a single system device.
|
2021-01-03 00:44:02 +00:00
|
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
|
TAG (str): 'Device'
|
2021-03-22 19:35:57 +00:00
|
|
|
|
clientIdentifier (str): The unique identifier for the device.
|
2022-02-27 03:26:08 +00:00
|
|
|
|
createdAt (datetime): Datetime the device was created.
|
2021-01-03 02:21:50 +00:00
|
|
|
|
id (int): The ID of the device (not the same as :class:`~plexapi.myplex.MyPlexDevice` ID).
|
2021-01-03 01:25:39 +00:00
|
|
|
|
key (str): API URL (/devices/<id>)
|
2021-01-03 00:44:02 +00:00
|
|
|
|
name (str): The name of the device.
|
|
|
|
|
platform (str): OS the device is running (Linux, Windows, Chrome, etc.)
|
|
|
|
|
"""
|
|
|
|
|
TAG = 'Device'
|
|
|
|
|
|
|
|
|
|
def _loadData(self, data):
|
|
|
|
|
self._data = data
|
2021-03-22 19:35:57 +00:00
|
|
|
|
self.clientIdentifier = data.attrib.get('clientIdentifier')
|
2021-01-03 00:44:02 +00:00
|
|
|
|
self.createdAt = utils.toDatetime(data.attrib.get('createdAt'))
|
2021-05-27 02:45:12 +00:00
|
|
|
|
self.id = utils.cast(int, data.attrib.get('id'))
|
2022-08-28 05:56:01 +00:00
|
|
|
|
self.key = f'/devices/{self.id}'
|
2021-01-03 00:44:02 +00:00
|
|
|
|
self.name = data.attrib.get('name')
|
|
|
|
|
self.platform = data.attrib.get('platform')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class StatisticsBandwidth(PlexObject):
|
|
|
|
|
""" Represents a single statistics bandwidth data.
|
|
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
|
TAG (str): 'StatisticsBandwidth'
|
2021-01-03 01:25:39 +00:00
|
|
|
|
accountID (int): The associated :class:`~plexapi.server.SystemAccount` ID.
|
2022-02-27 03:26:08 +00:00
|
|
|
|
at (datetime): Datetime of the bandwidth data.
|
|
|
|
|
bytes (int): The total number of bytes for the specified time span.
|
2021-01-03 01:25:39 +00:00
|
|
|
|
deviceID (int): The associated :class:`~plexapi.server.SystemDevice` ID.
|
2022-02-27 03:26:08 +00:00
|
|
|
|
lan (bool): True or False whether the bandwidth is local or remote.
|
|
|
|
|
timespan (int): The time span for the bandwidth data.
|
2021-01-03 00:44:02 +00:00
|
|
|
|
1: months, 2: weeks, 3: days, 4: hours, 6: seconds.
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
TAG = 'StatisticsBandwidth'
|
|
|
|
|
|
|
|
|
|
def _loadData(self, data):
|
|
|
|
|
self._data = data
|
2021-05-27 02:45:12 +00:00
|
|
|
|
self.accountID = utils.cast(int, data.attrib.get('accountID'))
|
2021-01-03 00:44:02 +00:00
|
|
|
|
self.at = utils.toDatetime(data.attrib.get('at'))
|
2021-05-27 02:45:12 +00:00
|
|
|
|
self.bytes = utils.cast(int, data.attrib.get('bytes'))
|
|
|
|
|
self.deviceID = utils.cast(int, data.attrib.get('deviceID'))
|
|
|
|
|
self.lan = utils.cast(bool, data.attrib.get('lan'))
|
|
|
|
|
self.timespan = utils.cast(int, data.attrib.get('timespan'))
|
2021-01-03 00:44:02 +00:00
|
|
|
|
|
|
|
|
|
def __repr__(self):
|
2022-11-08 21:40:18 +00:00
|
|
|
|
return '<{}>'.format(
|
|
|
|
|
':'.join([p for p in [
|
|
|
|
|
self.__class__.__name__,
|
|
|
|
|
self._clean(self.accountID),
|
|
|
|
|
self._clean(self.deviceID),
|
|
|
|
|
self._clean(int(self.at.timestamp()))
|
|
|
|
|
] if p])
|
|
|
|
|
)
|
2021-01-03 00:44:02 +00:00
|
|
|
|
|
|
|
|
|
def account(self):
|
2021-01-03 01:25:39 +00:00
|
|
|
|
""" Returns the :class:`~plexapi.server.SystemAccount` associated with the bandwidth data. """
|
2021-03-22 19:35:57 +00:00
|
|
|
|
return self._server.systemAccount(self.accountID)
|
2021-01-03 00:44:02 +00:00
|
|
|
|
|
|
|
|
|
def device(self):
|
2021-01-03 01:25:39 +00:00
|
|
|
|
""" Returns the :class:`~plexapi.server.SystemDevice` associated with the bandwidth data. """
|
2021-03-22 19:35:57 +00:00
|
|
|
|
return self._server.systemDevice(self.deviceID)
|
2021-01-03 00:44:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class StatisticsResources(PlexObject):
|
|
|
|
|
""" Represents a single statistics resources data.
|
|
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
|
TAG (str): 'StatisticsResources'
|
2022-02-27 03:26:08 +00:00
|
|
|
|
at (datetime): Datetime of the resource data.
|
2021-01-03 00:44:02 +00:00
|
|
|
|
hostCpuUtilization (float): The system CPU usage %.
|
|
|
|
|
hostMemoryUtilization (float): The Plex Media Server CPU usage %.
|
|
|
|
|
processCpuUtilization (float): The system RAM usage %.
|
|
|
|
|
processMemoryUtilization (float): The Plex Media Server RAM usage %.
|
2022-02-27 03:26:08 +00:00
|
|
|
|
timespan (int): The time span for the resource data (6: seconds).
|
2021-01-03 00:44:02 +00:00
|
|
|
|
"""
|
|
|
|
|
TAG = 'StatisticsResources'
|
|
|
|
|
|
|
|
|
|
def _loadData(self, data):
|
|
|
|
|
self._data = data
|
|
|
|
|
self.at = utils.toDatetime(data.attrib.get('at'))
|
2021-05-27 02:45:12 +00:00
|
|
|
|
self.hostCpuUtilization = utils.cast(float, data.attrib.get('hostCpuUtilization'))
|
|
|
|
|
self.hostMemoryUtilization = utils.cast(float, data.attrib.get('hostMemoryUtilization'))
|
|
|
|
|
self.processCpuUtilization = utils.cast(float, data.attrib.get('processCpuUtilization'))
|
|
|
|
|
self.processMemoryUtilization = utils.cast(float, data.attrib.get('processMemoryUtilization'))
|
|
|
|
|
self.timespan = utils.cast(int, data.attrib.get('timespan'))
|
2021-01-03 00:44:02 +00:00
|
|
|
|
|
|
|
|
|
def __repr__(self):
|
2022-08-28 05:56:01 +00:00
|
|
|
|
return f"<{':'.join([p for p in [self.__class__.__name__, self._clean(int(self.at.timestamp()))] if p])}>"
|
2022-05-17 02:51:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@utils.registerPlexObject
|
|
|
|
|
class ButlerTask(PlexObject):
|
|
|
|
|
""" Represents a single scheduled butler task.
|
2023-08-29 03:29:39 +00:00
|
|
|
|
|
2022-05-17 02:51:39 +00:00
|
|
|
|
Attributes:
|
|
|
|
|
TAG (str): 'ButlerTask'
|
|
|
|
|
description (str): The description of the task.
|
|
|
|
|
enabled (bool): Whether the task is enabled.
|
|
|
|
|
interval (int): The interval the task is run in days.
|
|
|
|
|
name (str): The name of the task.
|
|
|
|
|
scheduleRandomized (bool): Whether the task schedule is randomized.
|
|
|
|
|
title (str): The title of the task.
|
|
|
|
|
"""
|
|
|
|
|
TAG = 'ButlerTask'
|
|
|
|
|
|
|
|
|
|
def _loadData(self, data):
|
|
|
|
|
self._data = data
|
|
|
|
|
self.description = data.attrib.get('description')
|
|
|
|
|
self.enabled = utils.cast(bool, data.attrib.get('enabled'))
|
|
|
|
|
self.interval = utils.cast(int, data.attrib.get('interval'))
|
|
|
|
|
self.name = data.attrib.get('name')
|
|
|
|
|
self.scheduleRandomized = utils.cast(bool, data.attrib.get('scheduleRandomized'))
|
|
|
|
|
self.title = data.attrib.get('title')
|
2023-08-27 19:06:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Identity(PlexObject):
|
|
|
|
|
""" Represents a server identity.
|
|
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
|
claimed (bool): True or False if the server is claimed.
|
|
|
|
|
machineIdentifier (str): The Plex server machine identifier.
|
|
|
|
|
version (str): The Plex server version.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
|
return f"<{self.__class__.__name__}:{self.machineIdentifier}>"
|
2023-08-29 03:29:39 +00:00
|
|
|
|
|
2023-08-27 19:06:40 +00:00
|
|
|
|
def _loadData(self, data):
|
|
|
|
|
self._data = data
|
|
|
|
|
self.claimed = utils.cast(bool, data.attrib.get('claimed'))
|
|
|
|
|
self.machineIdentifier = data.attrib.get('machineIdentifier')
|
|
|
|
|
self.version = data.attrib.get('version')
|