aioaudiobookshelf 0.1.0__tar.gz
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.
Potentially problematic release.
This version of aioaudiobookshelf might be problematic. Click here for more details.
- aioaudiobookshelf-0.1.0/LICENSE +201 -0
- aioaudiobookshelf-0.1.0/PKG-INFO +32 -0
- aioaudiobookshelf-0.1.0/README.md +2 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/__init__.py +72 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/client/__init__.py +189 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/client/_base.py +110 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/client/authors.py +34 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/client/collections_.py +28 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/client/items.py +108 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/client/libraries.py +173 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/client/me.py +103 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/client/playlists.py +29 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/client/podcasts.py +22 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/client/series.py +27 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/client/session.py +35 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/exceptions.py +13 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/helpers.py +56 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/__init__.py +14 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/audio.py +71 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/author.py +46 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/book.py +125 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/calls_authors.py +33 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/calls_collections.py +14 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/calls_items.py +53 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/calls_library.py +103 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/calls_login.py +28 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/calls_me.py +28 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/calls_playlists.py +14 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/calls_series.py +25 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/calls_session.py +17 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/collection.py +36 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/events_socket.py +46 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/file.py +22 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/folder.py +18 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/library.py +221 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/media_progress.py +42 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/playlist.py +74 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/podcast.py +129 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/series.py +45 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/series_books.py +34 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/server.py +76 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/session.py +78 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf/schema/user.py +81 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf.egg-info/PKG-INFO +32 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf.egg-info/SOURCES.txt +49 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf.egg-info/dependency_links.txt +1 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf.egg-info/not-zip-safe +1 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf.egg-info/requires.txt +17 -0
- aioaudiobookshelf-0.1.0/aioaudiobookshelf.egg-info/top_level.txt +1 -0
- aioaudiobookshelf-0.1.0/pyproject.toml +151 -0
- aioaudiobookshelf-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: aioaudiobookshelf
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Async library for Audiobookshelf
|
|
5
|
+
Author-email: Fabian Munkes <105975993+fmunkes@users.noreply.github.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Platform: any
|
|
8
|
+
Classifier: Environment :: Console
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
11
|
+
Requires-Python: >=3.12
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: aiohttp
|
|
15
|
+
Requires-Dist: mashumaro
|
|
16
|
+
Requires-Dist: python-socketio>=5.12
|
|
17
|
+
Provides-Extra: test
|
|
18
|
+
Requires-Dist: codespell==2.3.0; extra == "test"
|
|
19
|
+
Requires-Dist: isort==5.13.2; extra == "test"
|
|
20
|
+
Requires-Dist: mypy==1.13.0; extra == "test"
|
|
21
|
+
Requires-Dist: pre-commit==4.0.1; extra == "test"
|
|
22
|
+
Requires-Dist: pre-commit-hooks==5.0.0; extra == "test"
|
|
23
|
+
Requires-Dist: pytest==8.3.4; extra == "test"
|
|
24
|
+
Requires-Dist: pytest-aiohttp==1.0.5; extra == "test"
|
|
25
|
+
Requires-Dist: pytest-cov==5.0.0; extra == "test"
|
|
26
|
+
Requires-Dist: syrupy==4.8.1; extra == "test"
|
|
27
|
+
Requires-Dist: tomli==2.2.1; extra == "test"
|
|
28
|
+
Requires-Dist: ruff==0.9.2; extra == "test"
|
|
29
|
+
Requires-Dist: bumpver; extra == "test"
|
|
30
|
+
|
|
31
|
+
# aioaudiobookshelf
|
|
32
|
+
Async python library to interact with Audiobookshelf
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""Client library for Audiobookshelf."""
|
|
2
|
+
|
|
3
|
+
from aiohttp.client_exceptions import ClientResponseError, InvalidUrlClientError
|
|
4
|
+
|
|
5
|
+
from aioaudiobookshelf.client import AdminClient, SessionConfiguration, SocketClient, UserClient
|
|
6
|
+
from aioaudiobookshelf.exceptions import LoginError
|
|
7
|
+
from aioaudiobookshelf.schema.calls_login import LoginParameters, LoginResponse
|
|
8
|
+
|
|
9
|
+
__version__ = "0.1.0"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
async def _get_login_response(
|
|
13
|
+
*, session_config: SessionConfiguration, username: str, password: str
|
|
14
|
+
) -> LoginResponse:
|
|
15
|
+
login_request = LoginParameters(username=username, password=password).to_dict()
|
|
16
|
+
|
|
17
|
+
try:
|
|
18
|
+
resp = await session_config.session.post(
|
|
19
|
+
f"{session_config.url}/login",
|
|
20
|
+
json=login_request,
|
|
21
|
+
ssl=session_config.verify_ssl,
|
|
22
|
+
raise_for_status=True,
|
|
23
|
+
)
|
|
24
|
+
except (ClientResponseError, InvalidUrlClientError) as exc:
|
|
25
|
+
raise LoginError from exc
|
|
26
|
+
return LoginResponse.from_json(await resp.read())
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
async def get_user_client(
|
|
30
|
+
*,
|
|
31
|
+
session_config: SessionConfiguration,
|
|
32
|
+
username: str,
|
|
33
|
+
password: str,
|
|
34
|
+
) -> UserClient:
|
|
35
|
+
"""Get a user client."""
|
|
36
|
+
login_response = await _get_login_response(
|
|
37
|
+
session_config=session_config, username=username, password=password
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
return UserClient(session_config=session_config, login_response=login_response)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
async def get_user_and_socket_client(
|
|
44
|
+
*,
|
|
45
|
+
session_config: SessionConfiguration,
|
|
46
|
+
username: str,
|
|
47
|
+
password: str,
|
|
48
|
+
) -> tuple[UserClient, SocketClient]:
|
|
49
|
+
"""Get user and socket client."""
|
|
50
|
+
login_response = await _get_login_response(
|
|
51
|
+
session_config=session_config, username=username, password=password
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
user_client = UserClient(session_config=session_config, login_response=login_response)
|
|
55
|
+
if not session_config.token:
|
|
56
|
+
session_config.token = user_client.token
|
|
57
|
+
socket_client = SocketClient(session_config=session_config)
|
|
58
|
+
return user_client, socket_client
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
async def get_admin_client(
|
|
62
|
+
*,
|
|
63
|
+
session_config: SessionConfiguration,
|
|
64
|
+
username: str,
|
|
65
|
+
password: str,
|
|
66
|
+
) -> UserClient:
|
|
67
|
+
"""Get a admin client."""
|
|
68
|
+
login_response = await _get_login_response(
|
|
69
|
+
session_config=session_config, username=username, password=password
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
return AdminClient(session_config=session_config, login_response=login_response)
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"""Clients for Audiobookshelf."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
from collections.abc import Callable
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import socketio
|
|
9
|
+
import socketio.exceptions
|
|
10
|
+
from aiohttp import ClientSession
|
|
11
|
+
|
|
12
|
+
from aioaudiobookshelf.exceptions import BadUserError
|
|
13
|
+
from aioaudiobookshelf.schema.events_socket import (
|
|
14
|
+
LibraryItemRemoved,
|
|
15
|
+
PodcastEpisodeDownload,
|
|
16
|
+
UserItemProgressUpdatedEvent,
|
|
17
|
+
)
|
|
18
|
+
from aioaudiobookshelf.schema.library import LibraryItemExpanded
|
|
19
|
+
from aioaudiobookshelf.schema.media_progress import MediaProgress
|
|
20
|
+
from aioaudiobookshelf.schema.user import User, UserType
|
|
21
|
+
|
|
22
|
+
from .authors import AuthorsClient
|
|
23
|
+
from .collections_ import CollectionsClient
|
|
24
|
+
from .items import ItemsClient
|
|
25
|
+
from .libraries import LibrariesClient
|
|
26
|
+
from .me import MeClient
|
|
27
|
+
from .playlists import PlaylistsClient
|
|
28
|
+
from .podcasts import PodcastsClient
|
|
29
|
+
from .series import SeriesClient
|
|
30
|
+
from .session import SessionClient
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass(kw_only=True)
|
|
34
|
+
class SessionConfiguration:
|
|
35
|
+
"""Session configuration for abs client."""
|
|
36
|
+
|
|
37
|
+
session: ClientSession
|
|
38
|
+
url: str
|
|
39
|
+
verify_ssl: bool = True
|
|
40
|
+
token: str = ""
|
|
41
|
+
pagination_items_per_page: int = 10
|
|
42
|
+
logger: logging.Logger | None = None
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
def headers(self) -> dict[str, str]:
|
|
46
|
+
"""Session headers."""
|
|
47
|
+
if self.token is None:
|
|
48
|
+
raise RuntimeError("Token not set.")
|
|
49
|
+
return {"Authorization": f"Bearer {self.token}"}
|
|
50
|
+
|
|
51
|
+
def __post_init__(self) -> None:
|
|
52
|
+
"""Post init."""
|
|
53
|
+
self.url = self.url.rstrip("/")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class UserClient(
|
|
57
|
+
LibrariesClient,
|
|
58
|
+
ItemsClient,
|
|
59
|
+
CollectionsClient,
|
|
60
|
+
PlaylistsClient,
|
|
61
|
+
MeClient,
|
|
62
|
+
AuthorsClient,
|
|
63
|
+
SeriesClient,
|
|
64
|
+
SessionClient,
|
|
65
|
+
PodcastsClient,
|
|
66
|
+
):
|
|
67
|
+
"""Client which uses endpoints accessible to a user."""
|
|
68
|
+
|
|
69
|
+
def _verify_user(self) -> None:
|
|
70
|
+
if self.user.type_ not in [UserType.ADMIN, UserType.ROOT, UserType.USER]:
|
|
71
|
+
raise BadUserError
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class AdminClient(UserClient):
|
|
75
|
+
"""Client which uses endpoints accessible to users and admins."""
|
|
76
|
+
|
|
77
|
+
def _verify_user(self) -> None:
|
|
78
|
+
if self.user.type_ not in [UserType.ADMIN, UserType.ROOT]:
|
|
79
|
+
raise BadUserError
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class SocketClient:
|
|
83
|
+
"""Client for connecting to abs' socket."""
|
|
84
|
+
|
|
85
|
+
def __init__(self, session_config: SessionConfiguration) -> None:
|
|
86
|
+
"""Init SocketClient."""
|
|
87
|
+
self.session_config = session_config
|
|
88
|
+
|
|
89
|
+
self.client = socketio.AsyncClient(
|
|
90
|
+
reconnection=True,
|
|
91
|
+
reconnection_attempts=0,
|
|
92
|
+
handle_sigint=False,
|
|
93
|
+
ssl_verify=self.session_config.verify_ssl,
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
self.set_item_callbacks()
|
|
97
|
+
self.set_user_callbacks()
|
|
98
|
+
self.set_podcast_episode_download_callbacks()
|
|
99
|
+
|
|
100
|
+
def set_item_callbacks(
|
|
101
|
+
self,
|
|
102
|
+
*,
|
|
103
|
+
on_item_added: Callable[[LibraryItemExpanded], Any] | None = None,
|
|
104
|
+
on_item_updated: Callable[[LibraryItemExpanded], Any] | None = None,
|
|
105
|
+
on_item_removed: Callable[[LibraryItemRemoved], Any] | None = None,
|
|
106
|
+
on_items_added: Callable[[list[LibraryItemExpanded]], Any] | None = None,
|
|
107
|
+
on_items_updated: Callable[[list[LibraryItemExpanded]], Any] | None = None,
|
|
108
|
+
) -> None:
|
|
109
|
+
"""Set item callbacks."""
|
|
110
|
+
self.on_item_added = on_item_added
|
|
111
|
+
self.on_item_updated = on_item_updated
|
|
112
|
+
self.on_item_removed = on_item_removed
|
|
113
|
+
self.on_items_added = on_items_added
|
|
114
|
+
self.on_items_updated = on_items_updated
|
|
115
|
+
|
|
116
|
+
def set_user_callbacks(
|
|
117
|
+
self,
|
|
118
|
+
*,
|
|
119
|
+
on_user_updated: Callable[[User], Any] | None = None,
|
|
120
|
+
on_user_item_progress_updated: Callable[[str, MediaProgress], Any] | None = None,
|
|
121
|
+
) -> None:
|
|
122
|
+
"""Set user callbacks."""
|
|
123
|
+
self.on_user_updated = on_user_updated
|
|
124
|
+
self.on_user_item_progress_updated = on_user_item_progress_updated
|
|
125
|
+
|
|
126
|
+
def set_podcast_episode_download_callbacks(
|
|
127
|
+
self, *, on_episode_download_finished: Callable[[PodcastEpisodeDownload], Any] | None = None
|
|
128
|
+
) -> None:
|
|
129
|
+
"""Set podcast episode download callbacks."""
|
|
130
|
+
self.on_episode_download_finished = on_episode_download_finished
|
|
131
|
+
|
|
132
|
+
async def init_client(self) -> None:
|
|
133
|
+
"""Initialize the client."""
|
|
134
|
+
self.client.on("connect", handler=self._on_connect)
|
|
135
|
+
|
|
136
|
+
self.client.on("user_updated", handler=self._on_user_updated)
|
|
137
|
+
self.client.on("user_item_progress_updated", handler=self._on_user_item_progress_updated)
|
|
138
|
+
|
|
139
|
+
self.client.on("item_added", handler=self._on_item_added)
|
|
140
|
+
self.client.on("item_updated", handler=self._on_item_updated)
|
|
141
|
+
self.client.on("item_removed", handler=self._on_item_removed)
|
|
142
|
+
self.client.on("items_added", handler=self._on_items_added)
|
|
143
|
+
self.client.on("items_updated", handler=self._on_items_updated)
|
|
144
|
+
|
|
145
|
+
self.client.on("episode_download_finished", handler=self._on_episode_download_finished)
|
|
146
|
+
|
|
147
|
+
await self.client.connect(url=self.session_config.url)
|
|
148
|
+
|
|
149
|
+
async def shutdown(self) -> None:
|
|
150
|
+
"""Shutdown client (disconnect, or stop reconnect attempt)."""
|
|
151
|
+
await self.client.shutdown()
|
|
152
|
+
|
|
153
|
+
logout = shutdown
|
|
154
|
+
|
|
155
|
+
async def _on_connect(self) -> None:
|
|
156
|
+
await self.client.emit(event="auth", data=self.session_config.token)
|
|
157
|
+
|
|
158
|
+
async def _on_user_updated(self, data: dict[str, Any]) -> None:
|
|
159
|
+
if self.on_user_updated is not None:
|
|
160
|
+
await self.on_user_updated(User.from_dict(data))
|
|
161
|
+
|
|
162
|
+
async def _on_user_item_progress_updated(self, data: dict[str, Any]) -> None:
|
|
163
|
+
if self.on_user_item_progress_updated is not None:
|
|
164
|
+
event = UserItemProgressUpdatedEvent.from_dict(data)
|
|
165
|
+
await self.on_user_item_progress_updated(event.id_, event.data)
|
|
166
|
+
|
|
167
|
+
async def _on_item_added(self, data: dict[str, Any]) -> None:
|
|
168
|
+
if self.on_item_added is not None:
|
|
169
|
+
await self.on_item_added(LibraryItemExpanded.from_dict(data))
|
|
170
|
+
|
|
171
|
+
async def _on_item_updated(self, data: dict[str, Any]) -> None:
|
|
172
|
+
if self.on_item_updated is not None:
|
|
173
|
+
await self.on_item_updated(LibraryItemExpanded.from_dict(data))
|
|
174
|
+
|
|
175
|
+
async def _on_item_removed(self, data: dict[str, Any]) -> None:
|
|
176
|
+
if self.on_item_removed is not None:
|
|
177
|
+
await self.on_item_removed(LibraryItemRemoved.from_dict(data))
|
|
178
|
+
|
|
179
|
+
async def _on_items_added(self, data: list[dict[str, Any]]) -> None:
|
|
180
|
+
if self.on_items_added is not None:
|
|
181
|
+
await self.on_items_added([LibraryItemExpanded.from_dict(x) for x in data])
|
|
182
|
+
|
|
183
|
+
async def _on_items_updated(self, data: list[dict[str, Any]]) -> None:
|
|
184
|
+
if self.on_items_updated is not None:
|
|
185
|
+
await self.on_items_updated([LibraryItemExpanded.from_dict(x) for x in data])
|
|
186
|
+
|
|
187
|
+
async def _on_episode_download_finished(self, data: dict[str, Any]) -> None:
|
|
188
|
+
if self.on_episode_download_finished is not None:
|
|
189
|
+
await self.on_episode_download_finished(PodcastEpisodeDownload.from_dict(data))
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""BaseClient."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
from abc import abstractmethod
|
|
5
|
+
from typing import TYPE_CHECKING, Any
|
|
6
|
+
|
|
7
|
+
from aiohttp.client_exceptions import ClientResponseError
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from aioaudiobookshelf.client import SessionConfiguration
|
|
11
|
+
from aioaudiobookshelf.exceptions import ApiError
|
|
12
|
+
from aioaudiobookshelf.schema.calls_login import LoginResponse
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class BaseClient:
|
|
16
|
+
"""Base for clients."""
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self, session_config: "SessionConfiguration", login_response: LoginResponse
|
|
20
|
+
) -> None:
|
|
21
|
+
self.session_config = session_config
|
|
22
|
+
self.user = login_response.user
|
|
23
|
+
if not self.session_config.token:
|
|
24
|
+
self.session_config.token = login_response.user.token
|
|
25
|
+
self._token = self.session_config.token
|
|
26
|
+
|
|
27
|
+
if self.session_config.logger is None:
|
|
28
|
+
self.logger = logging.getLogger(__name__)
|
|
29
|
+
logging.basicConfig()
|
|
30
|
+
self.logger.setLevel(logging.DEBUG)
|
|
31
|
+
else:
|
|
32
|
+
self.logger = self.session_config.logger
|
|
33
|
+
|
|
34
|
+
self.logger.debug(
|
|
35
|
+
"Initialized client %s, token: %s",
|
|
36
|
+
self.__class__.__name__,
|
|
37
|
+
self._token,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
self._verify_user()
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def token(self) -> str:
|
|
44
|
+
return self._token
|
|
45
|
+
|
|
46
|
+
@abstractmethod
|
|
47
|
+
def _verify_user(self) -> None:
|
|
48
|
+
"""Verify if user has enough permissions for endpoints in use."""
|
|
49
|
+
|
|
50
|
+
async def _post(
|
|
51
|
+
self,
|
|
52
|
+
endpoint: str,
|
|
53
|
+
data: dict[str, Any] | None = None,
|
|
54
|
+
) -> bytes:
|
|
55
|
+
"""POST request to abs api."""
|
|
56
|
+
try:
|
|
57
|
+
response = await self.session_config.session.post(
|
|
58
|
+
f"{self.session_config.url}/{endpoint}",
|
|
59
|
+
json=data,
|
|
60
|
+
ssl=self.session_config.verify_ssl,
|
|
61
|
+
headers=self.session_config.headers,
|
|
62
|
+
raise_for_status=True,
|
|
63
|
+
)
|
|
64
|
+
except ClientResponseError as exc:
|
|
65
|
+
raise ApiError(f"API POST call to {endpoint} failed.") from exc
|
|
66
|
+
return await response.read()
|
|
67
|
+
|
|
68
|
+
async def _get(self, endpoint: str, params: dict[str, str | int] | None = None) -> bytes:
|
|
69
|
+
"""GET request to abs api."""
|
|
70
|
+
response = await self.session_config.session.get(
|
|
71
|
+
f"{self.session_config.url}/{endpoint}",
|
|
72
|
+
params=params,
|
|
73
|
+
ssl=self.session_config.verify_ssl,
|
|
74
|
+
headers=self.session_config.headers,
|
|
75
|
+
)
|
|
76
|
+
status = response.status
|
|
77
|
+
if response.content_type == "application/json" and status == 200:
|
|
78
|
+
return await response.read()
|
|
79
|
+
if status == 404:
|
|
80
|
+
return b""
|
|
81
|
+
raise ApiError(f"API GET call to {endpoint} failed.")
|
|
82
|
+
|
|
83
|
+
async def _patch(self, endpoint: str, data: dict[str, Any] | None = None) -> None:
|
|
84
|
+
"""PATCH request to abs api."""
|
|
85
|
+
try:
|
|
86
|
+
await self.session_config.session.patch(
|
|
87
|
+
f"{self.session_config.url}/{endpoint}",
|
|
88
|
+
json=data,
|
|
89
|
+
ssl=self.session_config.verify_ssl,
|
|
90
|
+
headers=self.session_config.headers,
|
|
91
|
+
raise_for_status=True,
|
|
92
|
+
)
|
|
93
|
+
except ClientResponseError as exc:
|
|
94
|
+
raise ApiError(f"API PATCH call to {endpoint} failed.") from exc
|
|
95
|
+
|
|
96
|
+
async def _delete(self, endpoint: str) -> None:
|
|
97
|
+
"""DELETE request to abs api."""
|
|
98
|
+
try:
|
|
99
|
+
await self.session_config.session.delete(
|
|
100
|
+
endpoint,
|
|
101
|
+
ssl=self.session_config.verify_ssl,
|
|
102
|
+
headers=self.session_config.headers,
|
|
103
|
+
raise_for_status=True,
|
|
104
|
+
)
|
|
105
|
+
except ClientResponseError as exc:
|
|
106
|
+
raise ApiError(f"API DELETE call to {endpoint} failed.") from exc
|
|
107
|
+
|
|
108
|
+
async def logout(self) -> None:
|
|
109
|
+
"""Logout client."""
|
|
110
|
+
await self._post("logout")
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Calls to /api/authors."""
|
|
2
|
+
|
|
3
|
+
from aioaudiobookshelf.client._base import BaseClient
|
|
4
|
+
from aioaudiobookshelf.schema.author import Author
|
|
5
|
+
from aioaudiobookshelf.schema.calls_authors import AuthorWithItems, AuthorWithItemsAndSeries
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class AuthorsClient(BaseClient):
|
|
9
|
+
"""AuthorsClient."""
|
|
10
|
+
|
|
11
|
+
async def get_author(
|
|
12
|
+
self, *, author_id: str, include_items: bool = False, include_series: bool = False
|
|
13
|
+
) -> Author | AuthorWithItems | AuthorWithItemsAndSeries:
|
|
14
|
+
"""Get an author.
|
|
15
|
+
|
|
16
|
+
Include series always includes items.
|
|
17
|
+
"""
|
|
18
|
+
response_cls: type[Author | AuthorWithItems | AuthorWithItemsAndSeries] = Author
|
|
19
|
+
if include_series:
|
|
20
|
+
include_items = True
|
|
21
|
+
endpoint = f"/api/authors/{author_id}"
|
|
22
|
+
if include_items:
|
|
23
|
+
endpoint += "?include=items"
|
|
24
|
+
response_cls = AuthorWithItems
|
|
25
|
+
if include_series:
|
|
26
|
+
endpoint += ",series"
|
|
27
|
+
response_cls = AuthorWithItemsAndSeries
|
|
28
|
+
|
|
29
|
+
response = await self._get(endpoint)
|
|
30
|
+
return response_cls.from_json(response)
|
|
31
|
+
|
|
32
|
+
# update author
|
|
33
|
+
# match author
|
|
34
|
+
# get author image
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Calls to /api/collections."""
|
|
2
|
+
|
|
3
|
+
from aioaudiobookshelf.schema.calls_collections import AllCollectionsResponse
|
|
4
|
+
from aioaudiobookshelf.schema.collection import CollectionExpanded
|
|
5
|
+
|
|
6
|
+
from ._base import BaseClient
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class CollectionsClient(BaseClient):
|
|
10
|
+
"""CollectionsClient."""
|
|
11
|
+
|
|
12
|
+
# create collection
|
|
13
|
+
|
|
14
|
+
async def get_all_collections(self) -> list[CollectionExpanded]:
|
|
15
|
+
"""Get all collections accessible to user."""
|
|
16
|
+
data = await self._get(endpoint="/api/collections")
|
|
17
|
+
return AllCollectionsResponse.from_json(data).collections
|
|
18
|
+
|
|
19
|
+
async def get_collection(self, *, collection_id: str) -> CollectionExpanded:
|
|
20
|
+
"""Get a collection."""
|
|
21
|
+
data = await self._get(endpoint=f"/api/collections/{collection_id}")
|
|
22
|
+
return CollectionExpanded.from_json(data)
|
|
23
|
+
|
|
24
|
+
# update
|
|
25
|
+
# delete
|
|
26
|
+
# add book
|
|
27
|
+
# remove book
|
|
28
|
+
# batch add + remove
|