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/sessions.py ADDED
@@ -0,0 +1,272 @@
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 Sessions:
11
+ r"""API Calls that perform search operations with Plex Media Server Sessions"""
12
+ sdk_configuration: SDKConfiguration
13
+
14
+ def __init__(self, sdk_config: SDKConfiguration) -> None:
15
+ self.sdk_configuration = sdk_config
16
+
17
+
18
+
19
+ def get_sessions(self) -> operations.GetSessionsResponse:
20
+ r"""Get Active Sessions
21
+ This will retrieve the \"Now Playing\" Information of the PMS.
22
+ """
23
+ hook_ctx = HookContext(operation_id='getSessions', oauth2_scopes=[], security_source=self.sdk_configuration.security)
24
+ base_url = utils.template_url(*self.sdk_configuration.get_server_details())
25
+
26
+ url = base_url + '/status/sessions'
27
+
28
+ if callable(self.sdk_configuration.security):
29
+ headers, query_params = utils.get_security(self.sdk_configuration.security())
30
+ else:
31
+ headers, query_params = utils.get_security(self.sdk_configuration.security)
32
+
33
+ headers['Accept'] = 'application/json'
34
+ headers['user-agent'] = self.sdk_configuration.user_agent
35
+ client = self.sdk_configuration.client
36
+
37
+ try:
38
+ req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers))
39
+ req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req)
40
+ http_res = client.send(req)
41
+ except Exception as e:
42
+ _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e)
43
+ if e is not None:
44
+ raise e
45
+
46
+ if utils.match_status_codes(['400','401','4XX','5XX'], http_res.status_code):
47
+ result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None)
48
+ if e is not None:
49
+ raise e
50
+ if result is not None:
51
+ http_res = result
52
+ else:
53
+ http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res)
54
+
55
+
56
+
57
+ res = operations.GetSessionsResponse(status_code=http_res.status_code, content_type=http_res.headers.get('Content-Type') or '', raw_response=http_res)
58
+
59
+ if http_res.status_code == 200:
60
+ if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'):
61
+ out = utils.unmarshal_json(http_res.text, Optional[operations.GetSessionsResponseBody])
62
+ res.object = out
63
+ else:
64
+ content_type = http_res.headers.get('Content-Type')
65
+ raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
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.GetSessionsResponseBody)
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_session_history(self) -> operations.GetSessionHistoryResponse:
84
+ r"""Get Session History
85
+ This will Retrieve a listing of all history views.
86
+ """
87
+ hook_ctx = HookContext(operation_id='getSessionHistory', oauth2_scopes=[], security_source=self.sdk_configuration.security)
88
+ base_url = utils.template_url(*self.sdk_configuration.get_server_details())
89
+
90
+ url = base_url + '/status/sessions/history/all'
91
+
92
+ if callable(self.sdk_configuration.security):
93
+ headers, query_params = utils.get_security(self.sdk_configuration.security())
94
+ else:
95
+ headers, query_params = utils.get_security(self.sdk_configuration.security)
96
+
97
+ headers['Accept'] = 'application/json'
98
+ headers['user-agent'] = self.sdk_configuration.user_agent
99
+ client = self.sdk_configuration.client
100
+
101
+ try:
102
+ req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers))
103
+ req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req)
104
+ http_res = client.send(req)
105
+ except Exception as e:
106
+ _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e)
107
+ if e is not None:
108
+ raise e
109
+
110
+ if utils.match_status_codes(['400','401','4XX','5XX'], http_res.status_code):
111
+ result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None)
112
+ if e is not None:
113
+ raise e
114
+ if result is not None:
115
+ http_res = result
116
+ else:
117
+ http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res)
118
+
119
+
120
+
121
+ res = operations.GetSessionHistoryResponse(status_code=http_res.status_code, content_type=http_res.headers.get('Content-Type') or '', raw_response=http_res)
122
+
123
+ if http_res.status_code == 200:
124
+ if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'):
125
+ out = utils.unmarshal_json(http_res.text, Optional[operations.GetSessionHistoryResponseBody])
126
+ res.object = out
127
+ else:
128
+ content_type = http_res.headers.get('Content-Type')
129
+ raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
130
+ 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:
131
+ raise errors.SDKError('API error occurred', http_res.status_code, http_res.text, http_res)
132
+ elif http_res.status_code == 401:
133
+ if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'):
134
+ out = utils.unmarshal_json(http_res.text, errors.GetSessionHistoryResponseBody)
135
+ out.raw_response = http_res
136
+ raise out
137
+ else:
138
+ content_type = http_res.headers.get('Content-Type')
139
+ raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
140
+ else:
141
+ raise errors.SDKError('unknown status code received', http_res.status_code, http_res.text, http_res)
142
+
143
+ return res
144
+
145
+
146
+
147
+ def get_transcode_sessions(self) -> operations.GetTranscodeSessionsResponse:
148
+ r"""Get Transcode Sessions
149
+ Get Transcode Sessions
150
+ """
151
+ hook_ctx = HookContext(operation_id='getTranscodeSessions', oauth2_scopes=[], security_source=self.sdk_configuration.security)
152
+ base_url = utils.template_url(*self.sdk_configuration.get_server_details())
153
+
154
+ url = base_url + '/transcode/sessions'
155
+
156
+ if callable(self.sdk_configuration.security):
157
+ headers, query_params = utils.get_security(self.sdk_configuration.security())
158
+ else:
159
+ headers, query_params = utils.get_security(self.sdk_configuration.security)
160
+
161
+ headers['Accept'] = 'application/json'
162
+ headers['user-agent'] = self.sdk_configuration.user_agent
163
+ client = self.sdk_configuration.client
164
+
165
+ try:
166
+ req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers))
167
+ req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req)
168
+ http_res = client.send(req)
169
+ except Exception as e:
170
+ _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e)
171
+ if e is not None:
172
+ raise e
173
+
174
+ if utils.match_status_codes(['400','401','4XX','5XX'], http_res.status_code):
175
+ result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None)
176
+ if e is not None:
177
+ raise e
178
+ if result is not None:
179
+ http_res = result
180
+ else:
181
+ http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res)
182
+
183
+
184
+
185
+ res = operations.GetTranscodeSessionsResponse(status_code=http_res.status_code, content_type=http_res.headers.get('Content-Type') or '', raw_response=http_res)
186
+
187
+ if http_res.status_code == 200:
188
+ if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'):
189
+ out = utils.unmarshal_json(http_res.text, Optional[operations.GetTranscodeSessionsResponseBody])
190
+ res.object = out
191
+ else:
192
+ content_type = http_res.headers.get('Content-Type')
193
+ raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
194
+ 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:
195
+ raise errors.SDKError('API error occurred', http_res.status_code, http_res.text, http_res)
196
+ elif http_res.status_code == 401:
197
+ if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'):
198
+ out = utils.unmarshal_json(http_res.text, errors.GetTranscodeSessionsResponseBody)
199
+ out.raw_response = http_res
200
+ raise out
201
+ else:
202
+ content_type = http_res.headers.get('Content-Type')
203
+ raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
204
+ else:
205
+ raise errors.SDKError('unknown status code received', http_res.status_code, http_res.text, http_res)
206
+
207
+ return res
208
+
209
+
210
+
211
+ def stop_transcode_session(self, session_key: str) -> operations.StopTranscodeSessionResponse:
212
+ r"""Stop a Transcode Session
213
+ Stop a Transcode Session
214
+ """
215
+ hook_ctx = HookContext(operation_id='stopTranscodeSession', oauth2_scopes=[], security_source=self.sdk_configuration.security)
216
+ request = operations.StopTranscodeSessionRequest(
217
+ session_key=session_key,
218
+ )
219
+
220
+ base_url = utils.template_url(*self.sdk_configuration.get_server_details())
221
+
222
+ url = utils.generate_url(operations.StopTranscodeSessionRequest, base_url, '/transcode/sessions/{sessionKey}', request, self.sdk_configuration.globals)
223
+
224
+ if callable(self.sdk_configuration.security):
225
+ headers, query_params = utils.get_security(self.sdk_configuration.security())
226
+ else:
227
+ headers, query_params = utils.get_security(self.sdk_configuration.security)
228
+
229
+ headers['Accept'] = 'application/json'
230
+ headers['user-agent'] = self.sdk_configuration.user_agent
231
+ client = self.sdk_configuration.client
232
+
233
+ try:
234
+ req = client.prepare_request(requests_http.Request('DELETE', url, params=query_params, headers=headers))
235
+ req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req)
236
+ http_res = client.send(req)
237
+ except Exception as e:
238
+ _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e)
239
+ if e is not None:
240
+ raise e
241
+
242
+ if utils.match_status_codes(['400','401','4XX','5XX'], http_res.status_code):
243
+ result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None)
244
+ if e is not None:
245
+ raise e
246
+ if result is not None:
247
+ http_res = result
248
+ else:
249
+ http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res)
250
+
251
+
252
+
253
+ res = operations.StopTranscodeSessionResponse(status_code=http_res.status_code, content_type=http_res.headers.get('Content-Type') or '', raw_response=http_res)
254
+
255
+ if http_res.status_code == 204:
256
+ pass
257
+ 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:
258
+ raise errors.SDKError('API error occurred', http_res.status_code, http_res.text, http_res)
259
+ elif http_res.status_code == 401:
260
+ if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'):
261
+ out = utils.unmarshal_json(http_res.text, errors.StopTranscodeSessionResponseBody)
262
+ out.raw_response = http_res
263
+ raise out
264
+ else:
265
+ content_type = http_res.headers.get('Content-Type')
266
+ raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
267
+ else:
268
+ raise errors.SDKError('unknown status code received', http_res.status_code, http_res.text, http_res)
269
+
270
+ return res
271
+
272
+
plex_api/statistics.py ADDED
@@ -0,0 +1,86 @@
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 Statistics:
11
+ r"""API Calls that perform operations with Plex Media Server Statistics"""
12
+ sdk_configuration: SDKConfiguration
13
+
14
+ def __init__(self, sdk_config: SDKConfiguration) -> None:
15
+ self.sdk_configuration = sdk_config
16
+
17
+
18
+
19
+ def get_statistics(self, timespan: Optional[int] = None) -> operations.GetStatisticsResponse:
20
+ r"""Get Media Statistics
21
+ This will return the media statistics for the server
22
+ """
23
+ hook_ctx = HookContext(operation_id='getStatistics', oauth2_scopes=[], security_source=self.sdk_configuration.security)
24
+ request = operations.GetStatisticsRequest(
25
+ timespan=timespan,
26
+ )
27
+
28
+ base_url = utils.template_url(*self.sdk_configuration.get_server_details())
29
+
30
+ url = base_url + '/statistics/media'
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.GetStatisticsRequest, 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.GetStatisticsResponse(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
+ if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'):
66
+ out = utils.unmarshal_json(http_res.text, Optional[operations.GetStatisticsResponseBody])
67
+ res.object = out
68
+ else:
69
+ content_type = http_res.headers.get('Content-Type')
70
+ raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
71
+ 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:
72
+ raise errors.SDKError('API error occurred', http_res.status_code, http_res.text, http_res)
73
+ elif http_res.status_code == 401:
74
+ if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'):
75
+ out = utils.unmarshal_json(http_res.text, errors.GetStatisticsResponseBody)
76
+ out.raw_response = http_res
77
+ raise out
78
+ else:
79
+ content_type = http_res.headers.get('Content-Type')
80
+ raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
81
+ else:
82
+ raise errors.SDKError('unknown status code received', http_res.status_code, http_res.text, http_res)
83
+
84
+ return res
85
+
86
+
plex_api/updater.py ADDED
@@ -0,0 +1,212 @@
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 Updater:
11
+ r"""This describes the API for searching and applying updates to the Plex Media Server.
12
+ Updates to the status can be observed via the Event API.
13
+ """
14
+ sdk_configuration: SDKConfiguration
15
+
16
+ def __init__(self, sdk_config: SDKConfiguration) -> None:
17
+ self.sdk_configuration = sdk_config
18
+
19
+
20
+
21
+ def get_update_status(self) -> operations.GetUpdateStatusResponse:
22
+ r"""Querying status of updates
23
+ Querying status of updates
24
+ """
25
+ hook_ctx = HookContext(operation_id='getUpdateStatus', oauth2_scopes=[], security_source=self.sdk_configuration.security)
26
+ base_url = utils.template_url(*self.sdk_configuration.get_server_details())
27
+
28
+ url = base_url + '/updater/status'
29
+
30
+ if callable(self.sdk_configuration.security):
31
+ headers, query_params = utils.get_security(self.sdk_configuration.security())
32
+ else:
33
+ headers, query_params = utils.get_security(self.sdk_configuration.security)
34
+
35
+ headers['Accept'] = 'application/json'
36
+ headers['user-agent'] = self.sdk_configuration.user_agent
37
+ client = self.sdk_configuration.client
38
+
39
+ try:
40
+ req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers))
41
+ req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req)
42
+ http_res = client.send(req)
43
+ except Exception as e:
44
+ _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e)
45
+ if e is not None:
46
+ raise e
47
+
48
+ if utils.match_status_codes(['400','401','4XX','5XX'], http_res.status_code):
49
+ result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None)
50
+ if e is not None:
51
+ raise e
52
+ if result is not None:
53
+ http_res = result
54
+ else:
55
+ http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res)
56
+
57
+
58
+
59
+ res = operations.GetUpdateStatusResponse(status_code=http_res.status_code, content_type=http_res.headers.get('Content-Type') or '', raw_response=http_res)
60
+
61
+ if http_res.status_code == 200:
62
+ if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'):
63
+ out = utils.unmarshal_json(http_res.text, Optional[operations.GetUpdateStatusResponseBody])
64
+ res.object = out
65
+ else:
66
+ content_type = http_res.headers.get('Content-Type')
67
+ raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
68
+ 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:
69
+ raise errors.SDKError('API error occurred', http_res.status_code, http_res.text, http_res)
70
+ elif http_res.status_code == 401:
71
+ if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'):
72
+ out = utils.unmarshal_json(http_res.text, errors.GetUpdateStatusResponseBody)
73
+ out.raw_response = http_res
74
+ raise out
75
+ else:
76
+ content_type = http_res.headers.get('Content-Type')
77
+ raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
78
+ else:
79
+ raise errors.SDKError('unknown status code received', http_res.status_code, http_res.text, http_res)
80
+
81
+ return res
82
+
83
+
84
+
85
+ def check_for_updates(self, download: Optional[operations.Download] = None) -> operations.CheckForUpdatesResponse:
86
+ r"""Checking for updates
87
+ Checking for updates
88
+ """
89
+ hook_ctx = HookContext(operation_id='checkForUpdates', oauth2_scopes=[], security_source=self.sdk_configuration.security)
90
+ request = operations.CheckForUpdatesRequest(
91
+ download=download,
92
+ )
93
+
94
+ base_url = utils.template_url(*self.sdk_configuration.get_server_details())
95
+
96
+ url = base_url + '/updater/check'
97
+
98
+ if callable(self.sdk_configuration.security):
99
+ headers, query_params = utils.get_security(self.sdk_configuration.security())
100
+ else:
101
+ headers, query_params = utils.get_security(self.sdk_configuration.security)
102
+
103
+ query_params = { **utils.get_query_params(operations.CheckForUpdatesRequest, request, self.sdk_configuration.globals), **query_params }
104
+ headers['Accept'] = 'application/json'
105
+ headers['user-agent'] = self.sdk_configuration.user_agent
106
+ client = self.sdk_configuration.client
107
+
108
+ try:
109
+ req = client.prepare_request(requests_http.Request('PUT', url, params=query_params, headers=headers))
110
+ req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req)
111
+ http_res = client.send(req)
112
+ except Exception as e:
113
+ _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e)
114
+ if e is not None:
115
+ raise e
116
+
117
+ if utils.match_status_codes(['400','401','4XX','5XX'], http_res.status_code):
118
+ result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None)
119
+ if e is not None:
120
+ raise e
121
+ if result is not None:
122
+ http_res = result
123
+ else:
124
+ http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res)
125
+
126
+
127
+
128
+ res = operations.CheckForUpdatesResponse(status_code=http_res.status_code, content_type=http_res.headers.get('Content-Type') or '', raw_response=http_res)
129
+
130
+ if http_res.status_code == 200:
131
+ pass
132
+ 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:
133
+ raise errors.SDKError('API error occurred', http_res.status_code, http_res.text, http_res)
134
+ elif http_res.status_code == 401:
135
+ if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'):
136
+ out = utils.unmarshal_json(http_res.text, errors.CheckForUpdatesResponseBody)
137
+ out.raw_response = http_res
138
+ raise out
139
+ else:
140
+ content_type = http_res.headers.get('Content-Type')
141
+ raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
142
+ else:
143
+ raise errors.SDKError('unknown status code received', http_res.status_code, http_res.text, http_res)
144
+
145
+ return res
146
+
147
+
148
+
149
+ def apply_updates(self, tonight: Optional[operations.Tonight] = None, skip: Optional[operations.Skip] = None) -> operations.ApplyUpdatesResponse:
150
+ r"""Apply Updates
151
+ Note that these two parameters are effectively mutually exclusive. The `tonight` parameter takes precedence and `skip` will be ignored if `tonight` is also passed
152
+ """
153
+ hook_ctx = HookContext(operation_id='applyUpdates', oauth2_scopes=[], security_source=self.sdk_configuration.security)
154
+ request = operations.ApplyUpdatesRequest(
155
+ tonight=tonight,
156
+ skip=skip,
157
+ )
158
+
159
+ base_url = utils.template_url(*self.sdk_configuration.get_server_details())
160
+
161
+ url = base_url + '/updater/apply'
162
+
163
+ if callable(self.sdk_configuration.security):
164
+ headers, query_params = utils.get_security(self.sdk_configuration.security())
165
+ else:
166
+ headers, query_params = utils.get_security(self.sdk_configuration.security)
167
+
168
+ query_params = { **utils.get_query_params(operations.ApplyUpdatesRequest, request, self.sdk_configuration.globals), **query_params }
169
+ headers['Accept'] = 'application/json'
170
+ headers['user-agent'] = self.sdk_configuration.user_agent
171
+ client = self.sdk_configuration.client
172
+
173
+ try:
174
+ req = client.prepare_request(requests_http.Request('PUT', url, params=query_params, headers=headers))
175
+ req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req)
176
+ http_res = client.send(req)
177
+ except Exception as e:
178
+ _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e)
179
+ if e is not None:
180
+ raise e
181
+
182
+ if utils.match_status_codes(['400','401','4XX','500','5XX'], http_res.status_code):
183
+ result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None)
184
+ if e is not None:
185
+ raise e
186
+ if result is not None:
187
+ http_res = result
188
+ else:
189
+ http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res)
190
+
191
+
192
+
193
+ res = operations.ApplyUpdatesResponse(status_code=http_res.status_code, content_type=http_res.headers.get('Content-Type') or '', raw_response=http_res)
194
+
195
+ if http_res.status_code == 200:
196
+ pass
197
+ elif http_res.status_code == 400 or http_res.status_code >= 400 and http_res.status_code < 500 or http_res.status_code == 500 or http_res.status_code >= 500 and http_res.status_code < 600:
198
+ raise errors.SDKError('API error occurred', http_res.status_code, http_res.text, http_res)
199
+ elif http_res.status_code == 401:
200
+ if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'):
201
+ out = utils.unmarshal_json(http_res.text, errors.ApplyUpdatesResponseBody)
202
+ out.raw_response = http_res
203
+ raise out
204
+ else:
205
+ content_type = http_res.headers.get('Content-Type')
206
+ raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res)
207
+ else:
208
+ raise errors.SDKError('unknown status code received', http_res.status_code, http_res.text, http_res)
209
+
210
+ return res
211
+
212
+
@@ -0,0 +1,4 @@
1
+ """Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT."""
2
+
3
+ from .retries import *
4
+ from .utils import *