mirror of
https://github.com/LukeHagar/plexpy.git
synced 2025-12-09 20:57:44 +00:00
207 lines
9.2 KiB
Python
207 lines
9.2 KiB
Python
"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT."""
|
|
|
|
import requests as requests_http
|
|
from .sdkconfiguration import SDKConfiguration
|
|
from plex_api import utils
|
|
from plex_api._hooks import HookContext
|
|
from plex_api.models import errors, operations
|
|
|
|
class Media:
|
|
r"""API Calls interacting with Plex Media Server Media"""
|
|
sdk_configuration: SDKConfiguration
|
|
|
|
def __init__(self, sdk_config: SDKConfiguration) -> None:
|
|
self.sdk_configuration = sdk_config
|
|
|
|
|
|
|
|
def mark_played(self, key: float) -> operations.MarkPlayedResponse:
|
|
r"""Mark Media Played
|
|
This will mark the provided media key as Played.
|
|
"""
|
|
hook_ctx = HookContext(operation_id='markPlayed', oauth2_scopes=[], security_source=self.sdk_configuration.security)
|
|
request = operations.MarkPlayedRequest(
|
|
key=key,
|
|
)
|
|
|
|
base_url = utils.template_url(*self.sdk_configuration.get_server_details())
|
|
|
|
url = base_url + '/:/scrobble'
|
|
headers = {}
|
|
query_params = utils.get_query_params(operations.MarkPlayedRequest, request)
|
|
headers['Accept'] = 'application/json'
|
|
headers['user-agent'] = self.sdk_configuration.user_agent
|
|
|
|
if callable(self.sdk_configuration.security):
|
|
client = utils.configure_security_client(self.sdk_configuration.client, self.sdk_configuration.security())
|
|
else:
|
|
client = utils.configure_security_client(self.sdk_configuration.client, self.sdk_configuration.security)
|
|
|
|
|
|
try:
|
|
req = self.sdk_configuration.get_hooks().before_request(
|
|
hook_ctx,
|
|
requests_http.Request('GET', url, params=query_params, headers=headers).prepare(),
|
|
)
|
|
http_res = client.send(req)
|
|
except Exception as e:
|
|
_, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e)
|
|
raise e
|
|
|
|
if utils.match_status_codes(['400','401','4XX','5XX'], http_res.status_code):
|
|
http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None)
|
|
if e:
|
|
raise e
|
|
else:
|
|
result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res)
|
|
if isinstance(result, Exception):
|
|
raise result
|
|
http_res = result
|
|
|
|
content_type = http_res.headers.get('Content-Type')
|
|
|
|
res = operations.MarkPlayedResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res)
|
|
|
|
if http_res.status_code == 200:
|
|
pass
|
|
elif http_res.status_code == 400 or http_res.status_code >= 400 and http_res.status_code < 500 or http_res.status_code >= 500 and http_res.status_code < 600:
|
|
raise errors.SDKError('API error occurred', http_res.status_code, http_res.text, http_res)
|
|
elif http_res.status_code == 401:
|
|
if utils.match_content_type(content_type, 'application/json'):
|
|
out = utils.unmarshal_json(http_res.text, errors.MarkPlayedResponseBody)
|
|
out.raw_response = http_res
|
|
raise out
|
|
else:
|
|
raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
|
|
|
|
return res
|
|
|
|
|
|
|
|
def mark_unplayed(self, key: float) -> operations.MarkUnplayedResponse:
|
|
r"""Mark Media Unplayed
|
|
This will mark the provided media key as Unplayed.
|
|
"""
|
|
hook_ctx = HookContext(operation_id='markUnplayed', oauth2_scopes=[], security_source=self.sdk_configuration.security)
|
|
request = operations.MarkUnplayedRequest(
|
|
key=key,
|
|
)
|
|
|
|
base_url = utils.template_url(*self.sdk_configuration.get_server_details())
|
|
|
|
url = base_url + '/:/unscrobble'
|
|
headers = {}
|
|
query_params = utils.get_query_params(operations.MarkUnplayedRequest, request)
|
|
headers['Accept'] = 'application/json'
|
|
headers['user-agent'] = self.sdk_configuration.user_agent
|
|
|
|
if callable(self.sdk_configuration.security):
|
|
client = utils.configure_security_client(self.sdk_configuration.client, self.sdk_configuration.security())
|
|
else:
|
|
client = utils.configure_security_client(self.sdk_configuration.client, self.sdk_configuration.security)
|
|
|
|
|
|
try:
|
|
req = self.sdk_configuration.get_hooks().before_request(
|
|
hook_ctx,
|
|
requests_http.Request('GET', url, params=query_params, headers=headers).prepare(),
|
|
)
|
|
http_res = client.send(req)
|
|
except Exception as e:
|
|
_, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e)
|
|
raise e
|
|
|
|
if utils.match_status_codes(['400','401','4XX','5XX'], http_res.status_code):
|
|
http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None)
|
|
if e:
|
|
raise e
|
|
else:
|
|
result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res)
|
|
if isinstance(result, Exception):
|
|
raise result
|
|
http_res = result
|
|
|
|
content_type = http_res.headers.get('Content-Type')
|
|
|
|
res = operations.MarkUnplayedResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res)
|
|
|
|
if http_res.status_code == 200:
|
|
pass
|
|
elif http_res.status_code == 400 or http_res.status_code >= 400 and http_res.status_code < 500 or http_res.status_code >= 500 and http_res.status_code < 600:
|
|
raise errors.SDKError('API error occurred', http_res.status_code, http_res.text, http_res)
|
|
elif http_res.status_code == 401:
|
|
if utils.match_content_type(content_type, 'application/json'):
|
|
out = utils.unmarshal_json(http_res.text, errors.MarkUnplayedResponseBody)
|
|
out.raw_response = http_res
|
|
raise out
|
|
else:
|
|
raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
|
|
|
|
return res
|
|
|
|
|
|
|
|
def update_play_progress(self, key: str, time: float, state: str) -> operations.UpdatePlayProgressResponse:
|
|
r"""Update Media Play Progress
|
|
This API command can be used to update the play progress of a media item.
|
|
"""
|
|
hook_ctx = HookContext(operation_id='updatePlayProgress', oauth2_scopes=[], security_source=self.sdk_configuration.security)
|
|
request = operations.UpdatePlayProgressRequest(
|
|
key=key,
|
|
time=time,
|
|
state=state,
|
|
)
|
|
|
|
base_url = utils.template_url(*self.sdk_configuration.get_server_details())
|
|
|
|
url = base_url + '/:/progress'
|
|
headers = {}
|
|
query_params = utils.get_query_params(operations.UpdatePlayProgressRequest, request)
|
|
headers['Accept'] = 'application/json'
|
|
headers['user-agent'] = self.sdk_configuration.user_agent
|
|
|
|
if callable(self.sdk_configuration.security):
|
|
client = utils.configure_security_client(self.sdk_configuration.client, self.sdk_configuration.security())
|
|
else:
|
|
client = utils.configure_security_client(self.sdk_configuration.client, self.sdk_configuration.security)
|
|
|
|
|
|
try:
|
|
req = self.sdk_configuration.get_hooks().before_request(
|
|
hook_ctx,
|
|
requests_http.Request('POST', url, params=query_params, headers=headers).prepare(),
|
|
)
|
|
http_res = client.send(req)
|
|
except Exception as e:
|
|
_, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e)
|
|
raise e
|
|
|
|
if utils.match_status_codes(['400','401','4XX','5XX'], http_res.status_code):
|
|
http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None)
|
|
if e:
|
|
raise e
|
|
else:
|
|
result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res)
|
|
if isinstance(result, Exception):
|
|
raise result
|
|
http_res = result
|
|
|
|
content_type = http_res.headers.get('Content-Type')
|
|
|
|
res = operations.UpdatePlayProgressResponse(status_code=http_res.status_code, content_type=content_type, raw_response=http_res)
|
|
|
|
if http_res.status_code == 200:
|
|
pass
|
|
elif http_res.status_code == 400 or http_res.status_code >= 400 and http_res.status_code < 500 or http_res.status_code >= 500 and http_res.status_code < 600:
|
|
raise errors.SDKError('API error occurred', http_res.status_code, http_res.text, http_res)
|
|
elif http_res.status_code == 401:
|
|
if utils.match_content_type(content_type, 'application/json'):
|
|
out = utils.unmarshal_json(http_res.text, errors.UpdatePlayProgressResponseBody)
|
|
out.raw_response = http_res
|
|
raise out
|
|
else:
|
|
raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
|
|
|
|
return res
|
|
|
|
|