plex-api-client 0.6.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. plex_api/__init__.py +4 -0
  2. plex_api/_hooks/__init__.py +5 -0
  3. plex_api/_hooks/registration.py +13 -0
  4. plex_api/_hooks/sdkhooks.py +57 -0
  5. plex_api/_hooks/types.py +74 -0
  6. plex_api/activities.py +151 -0
  7. plex_api/authentication.py +146 -0
  8. plex_api/butler.py +333 -0
  9. plex_api/hubs.py +158 -0
  10. plex_api/library.py +808 -0
  11. plex_api/log.py +225 -0
  12. plex_api/media.py +210 -0
  13. plex_api/models/__init__.py +4 -0
  14. plex_api/models/components/__init__.py +5 -0
  15. plex_api/models/components/security.py +11 -0
  16. plex_api/models/errors/__init__.py +63 -0
  17. plex_api/models/errors/addplaylistcontents.py +32 -0
  18. plex_api/models/errors/applyupdates.py +32 -0
  19. plex_api/models/errors/cancelserveractivities.py +32 -0
  20. plex_api/models/errors/checkforupdates.py +32 -0
  21. plex_api/models/errors/clearplaylistcontents.py +32 -0
  22. plex_api/models/errors/createplaylist.py +32 -0
  23. plex_api/models/errors/deletelibrary.py +32 -0
  24. plex_api/models/errors/deleteplaylist.py +32 -0
  25. plex_api/models/errors/enablepapertrail.py +32 -0
  26. plex_api/models/errors/getavailableclients.py +32 -0
  27. plex_api/models/errors/getbutlertasks.py +32 -0
  28. plex_api/models/errors/getdevices.py +32 -0
  29. plex_api/models/errors/getfilehash.py +32 -0
  30. plex_api/models/errors/getglobalhubs.py +32 -0
  31. plex_api/models/errors/getlibraries.py +32 -0
  32. plex_api/models/errors/getlibrary.py +32 -0
  33. plex_api/models/errors/getlibraryhubs.py +32 -0
  34. plex_api/models/errors/getmetadata.py +32 -0
  35. plex_api/models/errors/getmetadatachildren.py +32 -0
  36. plex_api/models/errors/getmyplexaccount.py +32 -0
  37. plex_api/models/errors/getondeck.py +32 -0
  38. plex_api/models/errors/getpin.py +32 -0
  39. plex_api/models/errors/getplaylist.py +32 -0
  40. plex_api/models/errors/getplaylistcontents.py +32 -0
  41. plex_api/models/errors/getplaylists.py +32 -0
  42. plex_api/models/errors/getrecentlyadded.py +32 -0
  43. plex_api/models/errors/getresizedphoto.py +32 -0
  44. plex_api/models/errors/getsearchresults.py +32 -0
  45. plex_api/models/errors/getserveractivities.py +32 -0
  46. plex_api/models/errors/getservercapabilities.py +32 -0
  47. plex_api/models/errors/getserveridentity.py +32 -0
  48. plex_api/models/errors/getserverlist.py +32 -0
  49. plex_api/models/errors/getserverpreferences.py +32 -0
  50. plex_api/models/errors/getsessionhistory.py +32 -0
  51. plex_api/models/errors/getsessions.py +32 -0
  52. plex_api/models/errors/getsourceconnectioninformation.py +32 -0
  53. plex_api/models/errors/getstatistics.py +32 -0
  54. plex_api/models/errors/gettimeline.py +32 -0
  55. plex_api/models/errors/gettoken.py +32 -0
  56. plex_api/models/errors/gettranscodesessions.py +32 -0
  57. plex_api/models/errors/gettransienttoken.py +32 -0
  58. plex_api/models/errors/getupdatestatus.py +32 -0
  59. plex_api/models/errors/logline.py +32 -0
  60. plex_api/models/errors/logmultiline.py +32 -0
  61. plex_api/models/errors/markplayed.py +32 -0
  62. plex_api/models/errors/markunplayed.py +32 -0
  63. plex_api/models/errors/performsearch.py +32 -0
  64. plex_api/models/errors/performvoicesearch.py +32 -0
  65. plex_api/models/errors/refreshlibrary.py +32 -0
  66. plex_api/models/errors/sdkerror.py +24 -0
  67. plex_api/models/errors/startalltasks.py +32 -0
  68. plex_api/models/errors/starttask.py +32 -0
  69. plex_api/models/errors/startuniversaltranscode.py +32 -0
  70. plex_api/models/errors/stopalltasks.py +32 -0
  71. plex_api/models/errors/stoptask.py +32 -0
  72. plex_api/models/errors/stoptranscodesession.py +32 -0
  73. plex_api/models/errors/updateplaylist.py +32 -0
  74. plex_api/models/errors/updateplayprogress.py +32 -0
  75. plex_api/models/errors/uploadplaylist.py +32 -0
  76. plex_api/models/operations/__init__.py +64 -0
  77. plex_api/models/operations/addplaylistcontents.py +74 -0
  78. plex_api/models/operations/applyupdates.py +39 -0
  79. plex_api/models/operations/cancelserveractivities.py +25 -0
  80. plex_api/models/operations/checkforupdates.py +32 -0
  81. plex_api/models/operations/clearplaylistcontents.py +25 -0
  82. plex_api/models/operations/createplaylist.py +91 -0
  83. plex_api/models/operations/deletelibrary.py +25 -0
  84. plex_api/models/operations/deleteplaylist.py +25 -0
  85. plex_api/models/operations/enablepapertrail.py +17 -0
  86. plex_api/models/operations/getavailableclients.py +58 -0
  87. plex_api/models/operations/getbutlertasks.py +52 -0
  88. plex_api/models/operations/getdevices.py +53 -0
  89. plex_api/models/operations/getfilehash.py +28 -0
  90. plex_api/models/operations/getglobalhubs.py +100 -0
  91. plex_api/models/operations/getlibraries.py +79 -0
  92. plex_api/models/operations/getlibrary.py +153 -0
  93. plex_api/models/operations/getlibraryhubs.py +205 -0
  94. plex_api/models/operations/getlibraryitems.py +227 -0
  95. plex_api/models/operations/getmetadata.py +264 -0
  96. plex_api/models/operations/getmetadatachildren.py +115 -0
  97. plex_api/models/operations/getmyplexaccount.py +50 -0
  98. plex_api/models/operations/getondeck.py +166 -0
  99. plex_api/models/operations/getpin.py +86 -0
  100. plex_api/models/operations/getplaylist.py +70 -0
  101. plex_api/models/operations/getplaylistcontents.py +178 -0
  102. plex_api/models/operations/getplaylists.py +85 -0
  103. plex_api/models/operations/getrecentlyadded.py +166 -0
  104. plex_api/models/operations/getresizedphoto.py +48 -0
  105. plex_api/models/operations/getsearchresults.py +182 -0
  106. plex_api/models/operations/getserveractivities.py +63 -0
  107. plex_api/models/operations/getservercapabilities.py +99 -0
  108. plex_api/models/operations/getserveridentity.py +42 -0
  109. plex_api/models/operations/getserverlist.py +53 -0
  110. plex_api/models/operations/getserverpreferences.py +57 -0
  111. plex_api/models/operations/getsessionhistory.py +67 -0
  112. plex_api/models/operations/getsessions.py +185 -0
  113. plex_api/models/operations/getsourceconnectioninformation.py +25 -0
  114. plex_api/models/operations/getstatistics.py +93 -0
  115. plex_api/models/operations/gettimeline.py +50 -0
  116. plex_api/models/operations/gettoken.py +35 -0
  117. plex_api/models/operations/gettranscodesessions.py +71 -0
  118. plex_api/models/operations/gettransienttoken.py +36 -0
  119. plex_api/models/operations/getupdatestatus.py +57 -0
  120. plex_api/models/operations/logline.py +50 -0
  121. plex_api/models/operations/logmultiline.py +17 -0
  122. plex_api/models/operations/markplayed.py +25 -0
  123. plex_api/models/operations/markunplayed.py +25 -0
  124. plex_api/models/operations/performsearch.py +30 -0
  125. plex_api/models/operations/performvoicesearch.py +30 -0
  126. plex_api/models/operations/refreshlibrary.py +25 -0
  127. plex_api/models/operations/searchlibrary.py +96 -0
  128. plex_api/models/operations/startalltasks.py +17 -0
  129. plex_api/models/operations/starttask.py +43 -0
  130. plex_api/models/operations/startuniversaltranscode.py +56 -0
  131. plex_api/models/operations/stopalltasks.py +17 -0
  132. plex_api/models/operations/stoptask.py +43 -0
  133. plex_api/models/operations/stoptranscodesession.py +25 -0
  134. plex_api/models/operations/updateplaylist.py +30 -0
  135. plex_api/models/operations/updateplayprogress.py +29 -0
  136. plex_api/models/operations/uploadplaylist.py +47 -0
  137. plex_api/playlists.py +629 -0
  138. plex_api/plex.py +154 -0
  139. plex_api/sdk.py +180 -0
  140. plex_api/sdkconfiguration.py +52 -0
  141. plex_api/search.py +232 -0
  142. plex_api/server.py +525 -0
  143. plex_api/sessions.py +272 -0
  144. plex_api/statistics.py +86 -0
  145. plex_api/updater.py +212 -0
  146. plex_api/utils/__init__.py +4 -0
  147. plex_api/utils/retries.py +120 -0
  148. plex_api/utils/utils.py +898 -0
  149. plex_api/video.py +136 -0
  150. plex_api_client-0.6.1.dist-info/LICENSE.md +21 -0
  151. plex_api_client-0.6.1.dist-info/METADATA +397 -0
  152. plex_api_client-0.6.1.dist-info/RECORD +154 -0
  153. plex_api_client-0.6.1.dist-info/WHEEL +5 -0
  154. plex_api_client-0.6.1.dist-info/top_level.txt +1 -0
plex_api/__init__.py ADDED
@@ -0,0 +1,4 @@
1
+ """Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT."""
2
+
3
+ from .sdk import *
4
+ from .sdkconfiguration import *
@@ -0,0 +1,5 @@
1
+ """Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT."""
2
+
3
+ from .sdkhooks import *
4
+ from .types import *
5
+ from .registration import *
@@ -0,0 +1,13 @@
1
+ from .types import Hooks
2
+
3
+
4
+ # This file is only ever generated once on the first generation and then is free to be modified.
5
+ # Any hooks you wish to add should be registered in the init_hooks function. Feel free to define them
6
+ # in this file or in separate files in the hooks folder.
7
+
8
+
9
+ def init_hooks(hooks: Hooks):
10
+ # pylint: disable=unused-argument
11
+ """Add hooks by calling hooks.register{sdk_init/before_request/after_success/after_error}Hook
12
+ with an instance of a hook that implements that specific Hook interface
13
+ Hooks are registered per SDK instance, and are valid for the lifetime of the SDK instance"""
@@ -0,0 +1,57 @@
1
+ """Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT."""
2
+
3
+ import requests
4
+ from .types import SDKInitHook, BeforeRequestContext, BeforeRequestHook, AfterSuccessContext, AfterSuccessHook, AfterErrorContext, AfterErrorHook, Hooks
5
+ from .registration import init_hooks
6
+ from typing import List, Optional, Tuple
7
+
8
+
9
+ class SDKHooks(Hooks):
10
+ def __init__(self):
11
+ self.sdk_init_hooks: List[SDKInitHook] = []
12
+ self.before_request_hooks: List[BeforeRequestHook] = []
13
+ self.after_success_hooks: List[AfterSuccessHook] = []
14
+ self.after_error_hooks: List[AfterErrorHook] = []
15
+ init_hooks(self)
16
+
17
+ def register_sdk_init_hook(self, hook: SDKInitHook) -> None:
18
+ self.sdk_init_hooks.append(hook)
19
+
20
+ def register_before_request_hook(self, hook: BeforeRequestHook) -> None:
21
+ self.before_request_hooks.append(hook)
22
+
23
+ def register_after_success_hook(self, hook: AfterSuccessHook) -> None:
24
+ self.after_success_hooks.append(hook)
25
+
26
+ def register_after_error_hook(self, hook: AfterErrorHook) -> None:
27
+ self.after_error_hooks.append(hook)
28
+
29
+ def sdk_init(self, base_url: str, client: requests.Session) -> Tuple[str, requests.Session]:
30
+ for hook in self.sdk_init_hooks:
31
+ base_url, client = hook.sdk_init(base_url, client)
32
+ return base_url, client
33
+
34
+ def before_request(self, hook_ctx: BeforeRequestContext, request: requests.PreparedRequest) -> requests.PreparedRequest:
35
+ for hook in self.before_request_hooks:
36
+ out = hook.before_request(hook_ctx, request)
37
+ if isinstance(out, Exception):
38
+ raise out
39
+ request = out
40
+
41
+ return request
42
+
43
+ def after_success(self, hook_ctx: AfterSuccessContext, response: requests.Response) -> requests.Response:
44
+ for hook in self.after_success_hooks:
45
+ out = hook.after_success(hook_ctx, response)
46
+ if isinstance(out, Exception):
47
+ raise out
48
+ response = out
49
+ return response
50
+
51
+ def after_error(self, hook_ctx: AfterErrorContext, response: Optional[requests.Response], error: Optional[Exception]) -> Tuple[Optional[requests.Response], Optional[Exception]]:
52
+ for hook in self.after_error_hooks:
53
+ result = hook.after_error(hook_ctx, response, error)
54
+ if isinstance(result, Exception):
55
+ raise result
56
+ response, error = result
57
+ return response, error
@@ -0,0 +1,74 @@
1
+ """Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT."""
2
+
3
+ import requests as requests_http
4
+ from abc import ABC, abstractmethod
5
+ from typing import Any, Callable, List, Optional, Tuple, Union
6
+
7
+
8
+ class HookContext:
9
+ operation_id: str
10
+ oauth2_scopes: Optional[List[str]] = None
11
+ security_source: Optional[Union[Any, Callable[[], Any]]] = None
12
+
13
+ def __init__(self, operation_id: str, oauth2_scopes: Optional[List[str]], security_source: Optional[Union[Any, Callable[[], Any]]]):
14
+ self.operation_id = operation_id
15
+ self.oauth2_scopes = oauth2_scopes
16
+ self.security_source = security_source
17
+
18
+
19
+ class BeforeRequestContext(HookContext):
20
+ def __init__(self, hook_ctx: HookContext):
21
+ super().__init__(hook_ctx.operation_id, hook_ctx.oauth2_scopes, hook_ctx.security_source)
22
+
23
+
24
+ class AfterSuccessContext(HookContext):
25
+ def __init__(self, hook_ctx: HookContext):
26
+ super().__init__(hook_ctx.operation_id, hook_ctx.oauth2_scopes, hook_ctx.security_source)
27
+
28
+
29
+
30
+ class AfterErrorContext(HookContext):
31
+ def __init__(self, hook_ctx: HookContext):
32
+ super().__init__(hook_ctx.operation_id, hook_ctx.oauth2_scopes, hook_ctx.security_source)
33
+
34
+
35
+ class SDKInitHook(ABC):
36
+ @abstractmethod
37
+ def sdk_init(self, base_url: str, client: requests_http.Session) -> Tuple[str, requests_http.Session]:
38
+ pass
39
+
40
+
41
+ class BeforeRequestHook(ABC):
42
+ @abstractmethod
43
+ def before_request(self, hook_ctx: BeforeRequestContext, request: requests_http.PreparedRequest) -> Union[requests_http.PreparedRequest, Exception]:
44
+ pass
45
+
46
+
47
+ class AfterSuccessHook(ABC):
48
+ @abstractmethod
49
+ def after_success(self, hook_ctx: AfterSuccessContext, response: requests_http.Response) -> Union[requests_http.Response, Exception]:
50
+ pass
51
+
52
+
53
+ class AfterErrorHook(ABC):
54
+ @abstractmethod
55
+ def after_error(self, hook_ctx: AfterErrorContext, response: Optional[requests_http.Response], error: Optional[Exception]) -> Union[Tuple[Optional[requests_http.Response], Optional[Exception]], Exception]:
56
+ pass
57
+
58
+
59
+ class Hooks(ABC):
60
+ @abstractmethod
61
+ def register_sdk_init_hook(self, hook: SDKInitHook):
62
+ pass
63
+
64
+ @abstractmethod
65
+ def register_before_request_hook(self, hook: BeforeRequestHook):
66
+ pass
67
+
68
+ @abstractmethod
69
+ def register_after_success_hook(self, hook: AfterSuccessHook):
70
+ pass
71
+
72
+ @abstractmethod
73
+ def register_after_error_hook(self, hook: AfterErrorHook):
74
+ pass
plex_api/activities.py ADDED
@@ -0,0 +1,151 @@
1
+ """Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT."""
2
+
3
+ import requests as requests_http
4
+ from .sdkconfiguration import SDKConfiguration
5
+ from plex_api import utils
6
+ from plex_api._hooks import AfterErrorContext, AfterSuccessContext, BeforeRequestContext, HookContext
7
+ from plex_api.models import errors, operations
8
+ from typing import Optional
9
+
10
+ class Activities:
11
+ r"""Activities are awesome. They provide a way to monitor and control asynchronous operations on the server. In order to receive real-time updates for activities, a client would normally subscribe via either EventSource or Websocket endpoints.
12
+ Activities are associated with HTTP replies via a special `X-Plex-Activity` header which contains the UUID of the activity.
13
+ Activities are optional cancellable. If cancellable, they may be cancelled via the `DELETE` endpoint. Other details:
14
+ - They can contain a `progress` (from 0 to 100) marking the percent completion of the activity.
15
+ - They must contain an `type` which is used by clients to distinguish the specific activity.
16
+ - They may contain a `Context` object with attributes which associate the activity with various specific entities (items, libraries, etc.)
17
+ - The may contain a `Response` object which attributes which represent the result of the asynchronous operation.
18
+ """
19
+ sdk_configuration: SDKConfiguration
20
+
21
+ def __init__(self, sdk_config: SDKConfiguration) -> None:
22
+ self.sdk_configuration = sdk_config
23
+
24
+
25
+
26
+ def get_server_activities(self) -> operations.GetServerActivitiesResponse:
27
+ r"""Get Server Activities
28
+ Get Server Activities
29
+ """
30
+ hook_ctx = HookContext(operation_id='getServerActivities', oauth2_scopes=[], security_source=self.sdk_configuration.security)
31
+ base_url = utils.template_url(*self.sdk_configuration.get_server_details())
32
+
33
+ url = base_url + '/activities'
34
+
35
+ if callable(self.sdk_configuration.security):
36
+ headers, query_params = utils.get_security(self.sdk_configuration.security())
37
+ else:
38
+ headers, query_params = utils.get_security(self.sdk_configuration.security)
39
+
40
+ headers['Accept'] = 'application/json'
41
+ headers['user-agent'] = self.sdk_configuration.user_agent
42
+ client = self.sdk_configuration.client
43
+
44
+ try:
45
+ req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers))
46
+ req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req)
47
+ http_res = client.send(req)
48
+ except Exception as e:
49
+ _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e)
50
+ if e is not None:
51
+ raise e
52
+
53
+ if utils.match_status_codes(['400','401','4XX','5XX'], http_res.status_code):
54
+ result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None)
55
+ if e is not None:
56
+ raise e
57
+ if result is not None:
58
+ http_res = result
59
+ else:
60
+ http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res)
61
+
62
+
63
+
64
+ res = operations.GetServerActivitiesResponse(status_code=http_res.status_code, content_type=http_res.headers.get('Content-Type') or '', raw_response=http_res)
65
+
66
+ if http_res.status_code == 200:
67
+ if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'):
68
+ out = utils.unmarshal_json(http_res.text, Optional[operations.GetServerActivitiesResponseBody])
69
+ res.object = out
70
+ else:
71
+ content_type = http_res.headers.get('Content-Type')
72
+ raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
73
+ 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:
74
+ raise errors.SDKError('API error occurred', http_res.status_code, http_res.text, http_res)
75
+ elif http_res.status_code == 401:
76
+ if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'):
77
+ out = utils.unmarshal_json(http_res.text, errors.GetServerActivitiesResponseBody)
78
+ out.raw_response = http_res
79
+ raise out
80
+ else:
81
+ content_type = http_res.headers.get('Content-Type')
82
+ raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
83
+ else:
84
+ raise errors.SDKError('unknown status code received', http_res.status_code, http_res.text, http_res)
85
+
86
+ return res
87
+
88
+
89
+
90
+ def cancel_server_activities(self, activity_uuid: str) -> operations.CancelServerActivitiesResponse:
91
+ r"""Cancel Server Activities
92
+ Cancel Server Activities
93
+ """
94
+ hook_ctx = HookContext(operation_id='cancelServerActivities', oauth2_scopes=[], security_source=self.sdk_configuration.security)
95
+ request = operations.CancelServerActivitiesRequest(
96
+ activity_uuid=activity_uuid,
97
+ )
98
+
99
+ base_url = utils.template_url(*self.sdk_configuration.get_server_details())
100
+
101
+ url = utils.generate_url(operations.CancelServerActivitiesRequest, base_url, '/activities/{activityUUID}', request, self.sdk_configuration.globals)
102
+
103
+ if callable(self.sdk_configuration.security):
104
+ headers, query_params = utils.get_security(self.sdk_configuration.security())
105
+ else:
106
+ headers, query_params = utils.get_security(self.sdk_configuration.security)
107
+
108
+ headers['Accept'] = 'application/json'
109
+ headers['user-agent'] = self.sdk_configuration.user_agent
110
+ client = self.sdk_configuration.client
111
+
112
+ try:
113
+ req = client.prepare_request(requests_http.Request('DELETE', url, params=query_params, headers=headers))
114
+ req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req)
115
+ http_res = client.send(req)
116
+ except Exception as e:
117
+ _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e)
118
+ if e is not None:
119
+ raise e
120
+
121
+ if utils.match_status_codes(['400','401','4XX','5XX'], http_res.status_code):
122
+ result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None)
123
+ if e is not None:
124
+ raise e
125
+ if result is not None:
126
+ http_res = result
127
+ else:
128
+ http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res)
129
+
130
+
131
+
132
+ res = operations.CancelServerActivitiesResponse(status_code=http_res.status_code, content_type=http_res.headers.get('Content-Type') or '', raw_response=http_res)
133
+
134
+ if http_res.status_code == 200:
135
+ pass
136
+ 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:
137
+ raise errors.SDKError('API error occurred', http_res.status_code, http_res.text, http_res)
138
+ elif http_res.status_code == 401:
139
+ if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'):
140
+ out = utils.unmarshal_json(http_res.text, errors.CancelServerActivitiesResponseBody)
141
+ out.raw_response = http_res
142
+ raise out
143
+ else:
144
+ content_type = http_res.headers.get('Content-Type')
145
+ raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
146
+ else:
147
+ raise errors.SDKError('unknown status code received', http_res.status_code, http_res.text, http_res)
148
+
149
+ return res
150
+
151
+
@@ -0,0 +1,146 @@
1
+ """Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT."""
2
+
3
+ import requests as requests_http
4
+ from .sdkconfiguration import SDKConfiguration
5
+ from plex_api import utils
6
+ from plex_api._hooks import AfterErrorContext, AfterSuccessContext, BeforeRequestContext, HookContext
7
+ from plex_api.models import errors, operations
8
+
9
+ class Authentication:
10
+ r"""API Calls regarding authentication for Plex Media Server"""
11
+ sdk_configuration: SDKConfiguration
12
+
13
+ def __init__(self, sdk_config: SDKConfiguration) -> None:
14
+ self.sdk_configuration = sdk_config
15
+
16
+
17
+
18
+ def get_transient_token(self, type_: operations.GetTransientTokenQueryParamType, scope: operations.Scope) -> operations.GetTransientTokenResponse:
19
+ r"""Get a Transient Token.
20
+ This endpoint provides the caller with a temporary token with the same access level as the caller's token. These tokens are valid for up to 48 hours and are destroyed if the server instance is restarted.
21
+ """
22
+ hook_ctx = HookContext(operation_id='getTransientToken', oauth2_scopes=[], security_source=self.sdk_configuration.security)
23
+ request = operations.GetTransientTokenRequest(
24
+ type=type_,
25
+ scope=scope,
26
+ )
27
+
28
+ base_url = utils.template_url(*self.sdk_configuration.get_server_details())
29
+
30
+ url = base_url + '/security/token'
31
+
32
+ if callable(self.sdk_configuration.security):
33
+ headers, query_params = utils.get_security(self.sdk_configuration.security())
34
+ else:
35
+ headers, query_params = utils.get_security(self.sdk_configuration.security)
36
+
37
+ query_params = { **utils.get_query_params(operations.GetTransientTokenRequest, request, self.sdk_configuration.globals), **query_params }
38
+ headers['Accept'] = 'application/json'
39
+ headers['user-agent'] = self.sdk_configuration.user_agent
40
+ client = self.sdk_configuration.client
41
+
42
+ try:
43
+ req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers))
44
+ req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req)
45
+ http_res = client.send(req)
46
+ except Exception as e:
47
+ _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e)
48
+ if e is not None:
49
+ raise e
50
+
51
+ if utils.match_status_codes(['400','401','4XX','5XX'], http_res.status_code):
52
+ result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None)
53
+ if e is not None:
54
+ raise e
55
+ if result is not None:
56
+ http_res = result
57
+ else:
58
+ http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res)
59
+
60
+
61
+
62
+ res = operations.GetTransientTokenResponse(status_code=http_res.status_code, content_type=http_res.headers.get('Content-Type') or '', raw_response=http_res)
63
+
64
+ if http_res.status_code == 200:
65
+ pass
66
+ 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:
67
+ raise errors.SDKError('API error occurred', http_res.status_code, http_res.text, http_res)
68
+ elif http_res.status_code == 401:
69
+ if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'):
70
+ out = utils.unmarshal_json(http_res.text, errors.GetTransientTokenResponseBody)
71
+ out.raw_response = http_res
72
+ raise out
73
+ else:
74
+ content_type = http_res.headers.get('Content-Type')
75
+ raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
76
+ else:
77
+ raise errors.SDKError('unknown status code received', http_res.status_code, http_res.text, http_res)
78
+
79
+ return res
80
+
81
+
82
+
83
+ def get_source_connection_information(self, source: str) -> operations.GetSourceConnectionInformationResponse:
84
+ r"""Get Source Connection Information
85
+ If a caller requires connection details and a transient token for a source that is known to the server, for example a cloud media provider or shared PMS, then this endpoint can be called. This endpoint is only accessible with either an admin token or a valid transient token generated from an admin token.
86
+ Note: requires Plex Media Server >= 1.15.4.
87
+ """
88
+ hook_ctx = HookContext(operation_id='getSourceConnectionInformation', oauth2_scopes=[], security_source=self.sdk_configuration.security)
89
+ request = operations.GetSourceConnectionInformationRequest(
90
+ source=source,
91
+ )
92
+
93
+ base_url = utils.template_url(*self.sdk_configuration.get_server_details())
94
+
95
+ url = base_url + '/security/resources'
96
+
97
+ if callable(self.sdk_configuration.security):
98
+ headers, query_params = utils.get_security(self.sdk_configuration.security())
99
+ else:
100
+ headers, query_params = utils.get_security(self.sdk_configuration.security)
101
+
102
+ query_params = { **utils.get_query_params(operations.GetSourceConnectionInformationRequest, request, self.sdk_configuration.globals), **query_params }
103
+ headers['Accept'] = 'application/json'
104
+ headers['user-agent'] = self.sdk_configuration.user_agent
105
+ client = self.sdk_configuration.client
106
+
107
+ try:
108
+ req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers))
109
+ req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req)
110
+ http_res = client.send(req)
111
+ except Exception as e:
112
+ _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e)
113
+ if e is not None:
114
+ raise e
115
+
116
+ if utils.match_status_codes(['400','401','4XX','5XX'], http_res.status_code):
117
+ result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None)
118
+ if e is not None:
119
+ raise e
120
+ if result is not None:
121
+ http_res = result
122
+ else:
123
+ http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res)
124
+
125
+
126
+
127
+ res = operations.GetSourceConnectionInformationResponse(status_code=http_res.status_code, content_type=http_res.headers.get('Content-Type') or '', raw_response=http_res)
128
+
129
+ if http_res.status_code == 200:
130
+ pass
131
+ 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:
132
+ raise errors.SDKError('API error occurred', http_res.status_code, http_res.text, http_res)
133
+ elif http_res.status_code == 401:
134
+ if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'):
135
+ out = utils.unmarshal_json(http_res.text, errors.GetSourceConnectionInformationResponseBody)
136
+ out.raw_response = http_res
137
+ raise out
138
+ else:
139
+ content_type = http_res.headers.get('Content-Type')
140
+ raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
141
+ else:
142
+ raise errors.SDKError('unknown status code received', http_res.status_code, http_res.text, http_res)
143
+
144
+ return res
145
+
146
+