tikdataapi 0.1.0__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.
- tikdataapi/__init__.py +8 -0
- tikdataapi/api/__init__.py +1 -0
- tikdataapi/api/account/__init__.py +1 -0
- tikdataapi/api/account/get_me.py +144 -0
- tikdataapi/api/billing/__init__.py +1 -0
- tikdataapi/api/billing/create_checkout.py +215 -0
- tikdataapi/api/billing/list_packs.py +144 -0
- tikdataapi/api/hashtags/__init__.py +1 -0
- tikdataapi/api/hashtags/get_hashtag.py +220 -0
- tikdataapi/api/hashtags/get_hashtag_videos.py +250 -0
- tikdataapi/api/music/__init__.py +1 -0
- tikdataapi/api/music/get_music.py +234 -0
- tikdataapi/api/music/get_music_videos.py +254 -0
- tikdataapi/api/playlists/__init__.py +1 -0
- tikdataapi/api/playlists/get_playlist_videos.py +258 -0
- tikdataapi/api/search/__init__.py +1 -0
- tikdataapi/api/search/search_hashtags.py +261 -0
- tikdataapi/api/search/search_live.py +258 -0
- tikdataapi/api/search/search_music.py +260 -0
- tikdataapi/api/search/search_users.py +276 -0
- tikdataapi/api/search/search_videos.py +260 -0
- tikdataapi/api/users/__init__.py +1 -0
- tikdataapi/api/users/get_user.py +222 -0
- tikdataapi/api/users/get_user_followers.py +266 -0
- tikdataapi/api/users/get_user_following.py +266 -0
- tikdataapi/api/users/get_user_live.py +236 -0
- tikdataapi/api/users/get_user_playlists.py +276 -0
- tikdataapi/api/users/get_user_reposts.py +266 -0
- tikdataapi/api/users/get_user_videos.py +254 -0
- tikdataapi/api/users/get_users.py +247 -0
- tikdataapi/api/users/get_users_videos.py +259 -0
- tikdataapi/api/videos/__init__.py +1 -0
- tikdataapi/api/videos/get_comment_replies.py +260 -0
- tikdataapi/api/videos/get_comments.py +258 -0
- tikdataapi/api/videos/get_related_videos.py +247 -0
- tikdataapi/api/videos/get_trending_videos.py +238 -0
- tikdataapi/api/videos/get_video.py +218 -0
- tikdataapi/api/videos/get_video_transcript.py +247 -0
- tikdataapi/api/videos/get_videos.py +235 -0
- tikdataapi/client.py +268 -0
- tikdataapi/errors.py +16 -0
- tikdataapi/models/__init__.py +117 -0
- tikdataapi/models/batch_error.py +104 -0
- tikdataapi/models/batch_error_code.py +15 -0
- tikdataapi/models/batch_meta.py +127 -0
- tikdataapi/models/batch_meta_cache.py +11 -0
- tikdataapi/models/comment.py +163 -0
- tikdataapi/models/comment_author.py +97 -0
- tikdataapi/models/comment_page.py +130 -0
- tikdataapi/models/create_checkout_body.py +63 -0
- tikdataapi/models/create_checkout_body_pack.py +11 -0
- tikdataapi/models/create_checkout_response_200.py +97 -0
- tikdataapi/models/error.py +78 -0
- tikdataapi/models/error_body.py +107 -0
- tikdataapi/models/error_body_code.py +22 -0
- tikdataapi/models/get_me_response_200.py +88 -0
- tikdataapi/models/get_users_body.py +61 -0
- tikdataapi/models/get_users_videos_body.py +72 -0
- tikdataapi/models/get_videos_body.py +61 -0
- tikdataapi/models/hashtag.py +124 -0
- tikdataapi/models/hashtag_response.py +122 -0
- tikdataapi/models/hashtag_summary.py +98 -0
- tikdataapi/models/hashtag_summary_page.py +130 -0
- tikdataapi/models/list_packs_response_200.py +103 -0
- tikdataapi/models/list_packs_response_200_data_item.py +88 -0
- tikdataapi/models/list_packs_response_200_rate_limits_item.py +70 -0
- tikdataapi/models/live_room.py +142 -0
- tikdataapi/models/live_room_author.py +90 -0
- tikdataapi/models/live_room_page.py +130 -0
- tikdataapi/models/live_room_response.py +124 -0
- tikdataapi/models/meta.py +108 -0
- tikdataapi/models/meta_cache.py +10 -0
- tikdataapi/models/music.py +107 -0
- tikdataapi/models/music_detail.py +172 -0
- tikdataapi/models/music_response.py +124 -0
- tikdataapi/models/music_summary.py +137 -0
- tikdataapi/models/music_summary_page.py +130 -0
- tikdataapi/models/not_found_reason.py +12 -0
- tikdataapi/models/playlist.py +114 -0
- tikdataapi/models/playlist_author.py +86 -0
- tikdataapi/models/playlist_page.py +130 -0
- tikdataapi/models/problem.py +131 -0
- tikdataapi/models/transcript.py +128 -0
- tikdataapi/models/transcript_response.py +124 -0
- tikdataapi/models/transcript_segment.py +77 -0
- tikdataapi/models/user.py +207 -0
- tikdataapi/models/user_batch.py +145 -0
- tikdataapi/models/user_page.py +130 -0
- tikdataapi/models/user_response.py +126 -0
- tikdataapi/models/user_summary.py +152 -0
- tikdataapi/models/user_summary_page.py +130 -0
- tikdataapi/models/user_videos.py +96 -0
- tikdataapi/models/user_videos_batch.py +145 -0
- tikdataapi/models/video.py +297 -0
- tikdataapi/models/video_batch.py +145 -0
- tikdataapi/models/video_page.py +130 -0
- tikdataapi/models/video_response.py +122 -0
- tikdataapi/models/video_type.py +9 -0
- tikdataapi/py.typed +1 -0
- tikdataapi/types.py +54 -0
- tikdataapi-0.1.0.dist-info/METADATA +148 -0
- tikdataapi-0.1.0.dist-info/RECORD +103 -0
- tikdataapi-0.1.0.dist-info/WHEEL +4 -0
tikdataapi/client.py
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import ssl
|
|
2
|
+
from typing import Any, Self
|
|
3
|
+
|
|
4
|
+
import httpx
|
|
5
|
+
from attrs import define, evolve, field
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@define
|
|
9
|
+
class Client:
|
|
10
|
+
"""A class for keeping track of data related to the API
|
|
11
|
+
|
|
12
|
+
The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
|
|
13
|
+
|
|
14
|
+
``base_url``: The base URL for the API, all requests are made to a relative path to this URL
|
|
15
|
+
|
|
16
|
+
``cookies``: A dictionary of cookies to be sent with every request
|
|
17
|
+
|
|
18
|
+
``headers``: A dictionary of headers to be sent with every request
|
|
19
|
+
|
|
20
|
+
``timeout``: The maximum amount of a time a request can take. API functions will raise
|
|
21
|
+
httpx.TimeoutException if this is exceeded.
|
|
22
|
+
|
|
23
|
+
``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
|
|
24
|
+
but can be set to False for testing purposes.
|
|
25
|
+
|
|
26
|
+
``follow_redirects``: Whether or not to follow redirects. Default value is False.
|
|
27
|
+
|
|
28
|
+
``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
Attributes:
|
|
32
|
+
raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
|
|
33
|
+
status code that was not documented in the source OpenAPI document. Can also be provided as a keyword
|
|
34
|
+
argument to the constructor.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
raise_on_unexpected_status: bool = field(default=False, kw_only=True)
|
|
38
|
+
_base_url: str = field(alias="base_url")
|
|
39
|
+
_cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
|
|
40
|
+
_headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
|
|
41
|
+
_timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout")
|
|
42
|
+
_verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl")
|
|
43
|
+
_follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects")
|
|
44
|
+
_httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
|
|
45
|
+
_client: httpx.Client | None = field(default=None, init=False)
|
|
46
|
+
_async_client: httpx.AsyncClient | None = field(default=None, init=False)
|
|
47
|
+
|
|
48
|
+
def with_headers(self, headers: dict[str, str]) -> "Client":
|
|
49
|
+
"""Get a new client matching this one with additional headers"""
|
|
50
|
+
if self._client is not None:
|
|
51
|
+
self._client.headers.update(headers)
|
|
52
|
+
if self._async_client is not None:
|
|
53
|
+
self._async_client.headers.update(headers)
|
|
54
|
+
return evolve(self, headers={**self._headers, **headers})
|
|
55
|
+
|
|
56
|
+
def with_cookies(self, cookies: dict[str, str]) -> "Client":
|
|
57
|
+
"""Get a new client matching this one with additional cookies"""
|
|
58
|
+
if self._client is not None:
|
|
59
|
+
self._client.cookies.update(cookies)
|
|
60
|
+
if self._async_client is not None:
|
|
61
|
+
self._async_client.cookies.update(cookies)
|
|
62
|
+
return evolve(self, cookies={**self._cookies, **cookies})
|
|
63
|
+
|
|
64
|
+
def with_timeout(self, timeout: httpx.Timeout) -> "Client":
|
|
65
|
+
"""Get a new client matching this one with a new timeout configuration"""
|
|
66
|
+
if self._client is not None:
|
|
67
|
+
self._client.timeout = timeout
|
|
68
|
+
if self._async_client is not None:
|
|
69
|
+
self._async_client.timeout = timeout
|
|
70
|
+
return evolve(self, timeout=timeout)
|
|
71
|
+
|
|
72
|
+
def set_httpx_client(self, client: httpx.Client) -> Self:
|
|
73
|
+
"""Manually set the underlying httpx.Client
|
|
74
|
+
|
|
75
|
+
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
|
|
76
|
+
"""
|
|
77
|
+
self._client = client
|
|
78
|
+
return self
|
|
79
|
+
|
|
80
|
+
def get_httpx_client(self) -> httpx.Client:
|
|
81
|
+
"""Get the underlying httpx.Client, constructing a new one if not previously set"""
|
|
82
|
+
if self._client is None:
|
|
83
|
+
self._client = httpx.Client(
|
|
84
|
+
base_url=self._base_url,
|
|
85
|
+
cookies=self._cookies,
|
|
86
|
+
headers=self._headers,
|
|
87
|
+
timeout=self._timeout,
|
|
88
|
+
verify=self._verify_ssl,
|
|
89
|
+
follow_redirects=self._follow_redirects,
|
|
90
|
+
**self._httpx_args,
|
|
91
|
+
)
|
|
92
|
+
return self._client
|
|
93
|
+
|
|
94
|
+
def __enter__(self) -> Self:
|
|
95
|
+
"""Enter a context manager for self.client—you cannot enter twice (see httpx docs)"""
|
|
96
|
+
self.get_httpx_client().__enter__()
|
|
97
|
+
return self
|
|
98
|
+
|
|
99
|
+
def __exit__(self, *args: Any, **kwargs: Any) -> None:
|
|
100
|
+
"""Exit a context manager for internal httpx.Client (see httpx docs)"""
|
|
101
|
+
self.get_httpx_client().__exit__(*args, **kwargs)
|
|
102
|
+
|
|
103
|
+
def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> Self:
|
|
104
|
+
"""Manually set the underlying httpx.AsyncClient
|
|
105
|
+
|
|
106
|
+
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
|
|
107
|
+
"""
|
|
108
|
+
self._async_client = async_client
|
|
109
|
+
return self
|
|
110
|
+
|
|
111
|
+
def get_async_httpx_client(self) -> httpx.AsyncClient:
|
|
112
|
+
"""Get the underlying httpx.AsyncClient, constructing a new one if not previously set"""
|
|
113
|
+
if self._async_client is None:
|
|
114
|
+
self._async_client = httpx.AsyncClient(
|
|
115
|
+
base_url=self._base_url,
|
|
116
|
+
cookies=self._cookies,
|
|
117
|
+
headers=self._headers,
|
|
118
|
+
timeout=self._timeout,
|
|
119
|
+
verify=self._verify_ssl,
|
|
120
|
+
follow_redirects=self._follow_redirects,
|
|
121
|
+
**self._httpx_args,
|
|
122
|
+
)
|
|
123
|
+
return self._async_client
|
|
124
|
+
|
|
125
|
+
async def __aenter__(self) -> Self:
|
|
126
|
+
"""Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)"""
|
|
127
|
+
await self.get_async_httpx_client().__aenter__()
|
|
128
|
+
return self
|
|
129
|
+
|
|
130
|
+
async def __aexit__(self, *args: Any, **kwargs: Any) -> None:
|
|
131
|
+
"""Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
|
|
132
|
+
await self.get_async_httpx_client().__aexit__(*args, **kwargs)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
@define
|
|
136
|
+
class AuthenticatedClient:
|
|
137
|
+
"""A Client which has been authenticated for use on secured endpoints
|
|
138
|
+
|
|
139
|
+
The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
|
|
140
|
+
|
|
141
|
+
``base_url``: The base URL for the API, all requests are made to a relative path to this URL
|
|
142
|
+
|
|
143
|
+
``cookies``: A dictionary of cookies to be sent with every request
|
|
144
|
+
|
|
145
|
+
``headers``: A dictionary of headers to be sent with every request
|
|
146
|
+
|
|
147
|
+
``timeout``: The maximum amount of a time a request can take. API functions will raise
|
|
148
|
+
httpx.TimeoutException if this is exceeded.
|
|
149
|
+
|
|
150
|
+
``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
|
|
151
|
+
but can be set to False for testing purposes.
|
|
152
|
+
|
|
153
|
+
``follow_redirects``: Whether or not to follow redirects. Default value is False.
|
|
154
|
+
|
|
155
|
+
``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
Attributes:
|
|
159
|
+
raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
|
|
160
|
+
status code that was not documented in the source OpenAPI document. Can also be provided as a keyword
|
|
161
|
+
argument to the constructor.
|
|
162
|
+
token: The token to use for authentication
|
|
163
|
+
prefix: The prefix to use for the Authorization header
|
|
164
|
+
auth_header_name: The name of the Authorization header
|
|
165
|
+
"""
|
|
166
|
+
|
|
167
|
+
raise_on_unexpected_status: bool = field(default=False, kw_only=True)
|
|
168
|
+
_base_url: str = field(alias="base_url")
|
|
169
|
+
_cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
|
|
170
|
+
_headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
|
|
171
|
+
_timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout")
|
|
172
|
+
_verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl")
|
|
173
|
+
_follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects")
|
|
174
|
+
_httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
|
|
175
|
+
_client: httpx.Client | None = field(default=None, init=False)
|
|
176
|
+
_async_client: httpx.AsyncClient | None = field(default=None, init=False)
|
|
177
|
+
|
|
178
|
+
token: str
|
|
179
|
+
prefix: str = "Bearer"
|
|
180
|
+
auth_header_name: str = "Authorization"
|
|
181
|
+
|
|
182
|
+
def with_headers(self, headers: dict[str, str]) -> "AuthenticatedClient":
|
|
183
|
+
"""Get a new client matching this one with additional headers"""
|
|
184
|
+
if self._client is not None:
|
|
185
|
+
self._client.headers.update(headers)
|
|
186
|
+
if self._async_client is not None:
|
|
187
|
+
self._async_client.headers.update(headers)
|
|
188
|
+
return evolve(self, headers={**self._headers, **headers})
|
|
189
|
+
|
|
190
|
+
def with_cookies(self, cookies: dict[str, str]) -> "AuthenticatedClient":
|
|
191
|
+
"""Get a new client matching this one with additional cookies"""
|
|
192
|
+
if self._client is not None:
|
|
193
|
+
self._client.cookies.update(cookies)
|
|
194
|
+
if self._async_client is not None:
|
|
195
|
+
self._async_client.cookies.update(cookies)
|
|
196
|
+
return evolve(self, cookies={**self._cookies, **cookies})
|
|
197
|
+
|
|
198
|
+
def with_timeout(self, timeout: httpx.Timeout) -> "AuthenticatedClient":
|
|
199
|
+
"""Get a new client matching this one with a new timeout configuration"""
|
|
200
|
+
if self._client is not None:
|
|
201
|
+
self._client.timeout = timeout
|
|
202
|
+
if self._async_client is not None:
|
|
203
|
+
self._async_client.timeout = timeout
|
|
204
|
+
return evolve(self, timeout=timeout)
|
|
205
|
+
|
|
206
|
+
def set_httpx_client(self, client: httpx.Client) -> Self:
|
|
207
|
+
"""Manually set the underlying httpx.Client
|
|
208
|
+
|
|
209
|
+
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
|
|
210
|
+
"""
|
|
211
|
+
self._client = client
|
|
212
|
+
return self
|
|
213
|
+
|
|
214
|
+
def get_httpx_client(self) -> httpx.Client:
|
|
215
|
+
"""Get the underlying httpx.Client, constructing a new one if not previously set"""
|
|
216
|
+
if self._client is None:
|
|
217
|
+
self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token
|
|
218
|
+
self._client = httpx.Client(
|
|
219
|
+
base_url=self._base_url,
|
|
220
|
+
cookies=self._cookies,
|
|
221
|
+
headers=self._headers,
|
|
222
|
+
timeout=self._timeout,
|
|
223
|
+
verify=self._verify_ssl,
|
|
224
|
+
follow_redirects=self._follow_redirects,
|
|
225
|
+
**self._httpx_args,
|
|
226
|
+
)
|
|
227
|
+
return self._client
|
|
228
|
+
|
|
229
|
+
def __enter__(self) -> Self:
|
|
230
|
+
"""Enter a context manager for self.client—you cannot enter twice (see httpx docs)"""
|
|
231
|
+
self.get_httpx_client().__enter__()
|
|
232
|
+
return self
|
|
233
|
+
|
|
234
|
+
def __exit__(self, *args: Any, **kwargs: Any) -> None:
|
|
235
|
+
"""Exit a context manager for internal httpx.Client (see httpx docs)"""
|
|
236
|
+
self.get_httpx_client().__exit__(*args, **kwargs)
|
|
237
|
+
|
|
238
|
+
def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> Self:
|
|
239
|
+
"""Manually set the underlying httpx.AsyncClient
|
|
240
|
+
|
|
241
|
+
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
|
|
242
|
+
"""
|
|
243
|
+
self._async_client = async_client
|
|
244
|
+
return self
|
|
245
|
+
|
|
246
|
+
def get_async_httpx_client(self) -> httpx.AsyncClient:
|
|
247
|
+
"""Get the underlying httpx.AsyncClient, constructing a new one if not previously set"""
|
|
248
|
+
if self._async_client is None:
|
|
249
|
+
self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token
|
|
250
|
+
self._async_client = httpx.AsyncClient(
|
|
251
|
+
base_url=self._base_url,
|
|
252
|
+
cookies=self._cookies,
|
|
253
|
+
headers=self._headers,
|
|
254
|
+
timeout=self._timeout,
|
|
255
|
+
verify=self._verify_ssl,
|
|
256
|
+
follow_redirects=self._follow_redirects,
|
|
257
|
+
**self._httpx_args,
|
|
258
|
+
)
|
|
259
|
+
return self._async_client
|
|
260
|
+
|
|
261
|
+
async def __aenter__(self) -> Self:
|
|
262
|
+
"""Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)"""
|
|
263
|
+
await self.get_async_httpx_client().__aenter__()
|
|
264
|
+
return self
|
|
265
|
+
|
|
266
|
+
async def __aexit__(self, *args: Any, **kwargs: Any) -> None:
|
|
267
|
+
"""Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
|
|
268
|
+
await self.get_async_httpx_client().__aexit__(*args, **kwargs)
|
tikdataapi/errors.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Contains shared errors types that can be raised from API functions"""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class UnexpectedStatus(Exception):
|
|
5
|
+
"""Raised by api functions when the response status an undocumented status and Client.raise_on_unexpected_status is True"""
|
|
6
|
+
|
|
7
|
+
def __init__(self, status_code: int, content: bytes):
|
|
8
|
+
self.status_code = status_code
|
|
9
|
+
self.content = content
|
|
10
|
+
|
|
11
|
+
super().__init__(
|
|
12
|
+
f"Unexpected status code: {status_code}\n\nResponse content:\n{content.decode(errors='ignore')}"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
__all__ = ["UnexpectedStatus"]
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""Contains all the data models used in inputs/outputs"""
|
|
2
|
+
|
|
3
|
+
from .batch_error import BatchError
|
|
4
|
+
from .batch_error_code import BatchErrorCode
|
|
5
|
+
from .batch_meta import BatchMeta
|
|
6
|
+
from .batch_meta_cache import BatchMetaCache
|
|
7
|
+
from .comment import Comment
|
|
8
|
+
from .comment_author import CommentAuthor
|
|
9
|
+
from .comment_page import CommentPage
|
|
10
|
+
from .create_checkout_body import CreateCheckoutBody
|
|
11
|
+
from .create_checkout_body_pack import CreateCheckoutBodyPack
|
|
12
|
+
from .create_checkout_response_200 import CreateCheckoutResponse200
|
|
13
|
+
from .error import Error
|
|
14
|
+
from .error_body import ErrorBody
|
|
15
|
+
from .error_body_code import ErrorBodyCode
|
|
16
|
+
from .get_me_response_200 import GetMeResponse200
|
|
17
|
+
from .get_users_body import GetUsersBody
|
|
18
|
+
from .get_users_videos_body import GetUsersVideosBody
|
|
19
|
+
from .get_videos_body import GetVideosBody
|
|
20
|
+
from .hashtag import Hashtag
|
|
21
|
+
from .hashtag_response import HashtagResponse
|
|
22
|
+
from .hashtag_summary import HashtagSummary
|
|
23
|
+
from .hashtag_summary_page import HashtagSummaryPage
|
|
24
|
+
from .list_packs_response_200 import ListPacksResponse200
|
|
25
|
+
from .list_packs_response_200_data_item import ListPacksResponse200DataItem
|
|
26
|
+
from .list_packs_response_200_rate_limits_item import ListPacksResponse200RateLimitsItem
|
|
27
|
+
from .live_room import LiveRoom
|
|
28
|
+
from .live_room_author import LiveRoomAuthor
|
|
29
|
+
from .live_room_page import LiveRoomPage
|
|
30
|
+
from .live_room_response import LiveRoomResponse
|
|
31
|
+
from .meta import Meta
|
|
32
|
+
from .meta_cache import MetaCache
|
|
33
|
+
from .music import Music
|
|
34
|
+
from .music_detail import MusicDetail
|
|
35
|
+
from .music_response import MusicResponse
|
|
36
|
+
from .music_summary import MusicSummary
|
|
37
|
+
from .music_summary_page import MusicSummaryPage
|
|
38
|
+
from .not_found_reason import NotFoundReason
|
|
39
|
+
from .playlist import Playlist
|
|
40
|
+
from .playlist_author import PlaylistAuthor
|
|
41
|
+
from .playlist_page import PlaylistPage
|
|
42
|
+
from .problem import Problem
|
|
43
|
+
from .transcript import Transcript
|
|
44
|
+
from .transcript_response import TranscriptResponse
|
|
45
|
+
from .transcript_segment import TranscriptSegment
|
|
46
|
+
from .user import User
|
|
47
|
+
from .user_batch import UserBatch
|
|
48
|
+
from .user_page import UserPage
|
|
49
|
+
from .user_response import UserResponse
|
|
50
|
+
from .user_summary import UserSummary
|
|
51
|
+
from .user_summary_page import UserSummaryPage
|
|
52
|
+
from .user_videos import UserVideos
|
|
53
|
+
from .user_videos_batch import UserVideosBatch
|
|
54
|
+
from .video import Video
|
|
55
|
+
from .video_batch import VideoBatch
|
|
56
|
+
from .video_page import VideoPage
|
|
57
|
+
from .video_response import VideoResponse
|
|
58
|
+
from .video_type import VideoType
|
|
59
|
+
|
|
60
|
+
__all__ = (
|
|
61
|
+
"BatchError",
|
|
62
|
+
"BatchErrorCode",
|
|
63
|
+
"BatchMeta",
|
|
64
|
+
"BatchMetaCache",
|
|
65
|
+
"Comment",
|
|
66
|
+
"CommentAuthor",
|
|
67
|
+
"CommentPage",
|
|
68
|
+
"CreateCheckoutBody",
|
|
69
|
+
"CreateCheckoutBodyPack",
|
|
70
|
+
"CreateCheckoutResponse200",
|
|
71
|
+
"Error",
|
|
72
|
+
"ErrorBody",
|
|
73
|
+
"ErrorBodyCode",
|
|
74
|
+
"GetMeResponse200",
|
|
75
|
+
"GetUsersBody",
|
|
76
|
+
"GetUsersVideosBody",
|
|
77
|
+
"GetVideosBody",
|
|
78
|
+
"Hashtag",
|
|
79
|
+
"HashtagResponse",
|
|
80
|
+
"HashtagSummary",
|
|
81
|
+
"HashtagSummaryPage",
|
|
82
|
+
"ListPacksResponse200",
|
|
83
|
+
"ListPacksResponse200DataItem",
|
|
84
|
+
"ListPacksResponse200RateLimitsItem",
|
|
85
|
+
"LiveRoom",
|
|
86
|
+
"LiveRoomAuthor",
|
|
87
|
+
"LiveRoomPage",
|
|
88
|
+
"LiveRoomResponse",
|
|
89
|
+
"Meta",
|
|
90
|
+
"MetaCache",
|
|
91
|
+
"Music",
|
|
92
|
+
"MusicDetail",
|
|
93
|
+
"MusicResponse",
|
|
94
|
+
"MusicSummary",
|
|
95
|
+
"MusicSummaryPage",
|
|
96
|
+
"NotFoundReason",
|
|
97
|
+
"Playlist",
|
|
98
|
+
"PlaylistAuthor",
|
|
99
|
+
"PlaylistPage",
|
|
100
|
+
"Problem",
|
|
101
|
+
"Transcript",
|
|
102
|
+
"TranscriptResponse",
|
|
103
|
+
"TranscriptSegment",
|
|
104
|
+
"User",
|
|
105
|
+
"UserBatch",
|
|
106
|
+
"UserPage",
|
|
107
|
+
"UserResponse",
|
|
108
|
+
"UserSummary",
|
|
109
|
+
"UserSummaryPage",
|
|
110
|
+
"UserVideos",
|
|
111
|
+
"UserVideosBatch",
|
|
112
|
+
"Video",
|
|
113
|
+
"VideoBatch",
|
|
114
|
+
"VideoPage",
|
|
115
|
+
"VideoResponse",
|
|
116
|
+
"VideoType",
|
|
117
|
+
)
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
from typing import Any, TypeVar
|
|
5
|
+
|
|
6
|
+
from attrs import define as _attrs_define
|
|
7
|
+
from attrs import field as _attrs_field
|
|
8
|
+
|
|
9
|
+
from ..models.batch_error_code import BatchErrorCode
|
|
10
|
+
from ..models.not_found_reason import NotFoundReason
|
|
11
|
+
from ..types import UNSET, Unset
|
|
12
|
+
|
|
13
|
+
T = TypeVar("T", bound="BatchError")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@_attrs_define
|
|
17
|
+
class BatchError:
|
|
18
|
+
"""
|
|
19
|
+
Attributes:
|
|
20
|
+
input_ (str): The username or id: a username without `@` and in lower case, an id as sent.
|
|
21
|
+
code (BatchErrorCode):
|
|
22
|
+
message (str):
|
|
23
|
+
reason (NotFoundReason | Unset): On each `not_found`, and only there: why the object is not there.
|
|
24
|
+
`nonexistent`: no such account,
|
|
25
|
+
video, comment, hashtag or sound, or it was deleted; TikTok does not tell those two apart. `banned`: TikTok
|
|
26
|
+
banned the account. `private`: a video that only some accounts may see. `removed`: TikTok removed
|
|
27
|
+
the video for a rule of TikTok. `unavailable`: any other reason, for example a video that TikTok does
|
|
28
|
+
not show in the country of our reader, or a video with no transcript. A private account is not a `not_found`:
|
|
29
|
+
its profile comes back
|
|
30
|
+
with `private: true`.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
input_: str
|
|
34
|
+
code: BatchErrorCode
|
|
35
|
+
message: str
|
|
36
|
+
reason: NotFoundReason | Unset = UNSET
|
|
37
|
+
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
|
|
38
|
+
|
|
39
|
+
def to_dict(self) -> dict[str, Any]:
|
|
40
|
+
input_ = self.input_
|
|
41
|
+
|
|
42
|
+
code = self.code.value
|
|
43
|
+
|
|
44
|
+
message = self.message
|
|
45
|
+
|
|
46
|
+
reason: str | Unset = UNSET
|
|
47
|
+
if not isinstance(self.reason, Unset):
|
|
48
|
+
reason = self.reason.value
|
|
49
|
+
|
|
50
|
+
field_dict: dict[str, Any] = {}
|
|
51
|
+
field_dict.update(self.additional_properties)
|
|
52
|
+
field_dict.update(
|
|
53
|
+
{
|
|
54
|
+
"input": input_,
|
|
55
|
+
"code": code,
|
|
56
|
+
"message": message,
|
|
57
|
+
}
|
|
58
|
+
)
|
|
59
|
+
if reason is not UNSET:
|
|
60
|
+
field_dict["reason"] = reason
|
|
61
|
+
|
|
62
|
+
return field_dict
|
|
63
|
+
|
|
64
|
+
@classmethod
|
|
65
|
+
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
|
|
66
|
+
d = dict(src_dict)
|
|
67
|
+
input_ = d.pop("input")
|
|
68
|
+
|
|
69
|
+
code = BatchErrorCode(d.pop("code"))
|
|
70
|
+
|
|
71
|
+
message = d.pop("message")
|
|
72
|
+
|
|
73
|
+
_reason = d.pop("reason", UNSET)
|
|
74
|
+
reason: NotFoundReason | Unset
|
|
75
|
+
if isinstance(_reason, Unset):
|
|
76
|
+
reason = UNSET
|
|
77
|
+
else:
|
|
78
|
+
reason = NotFoundReason(_reason)
|
|
79
|
+
|
|
80
|
+
batch_error = cls(
|
|
81
|
+
input_=input_,
|
|
82
|
+
code=code,
|
|
83
|
+
message=message,
|
|
84
|
+
reason=reason,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
batch_error.additional_properties = d
|
|
88
|
+
return batch_error
|
|
89
|
+
|
|
90
|
+
@property
|
|
91
|
+
def additional_keys(self) -> list[str]:
|
|
92
|
+
return list(self.additional_properties.keys())
|
|
93
|
+
|
|
94
|
+
def __getitem__(self, key: str) -> Any:
|
|
95
|
+
return self.additional_properties[key]
|
|
96
|
+
|
|
97
|
+
def __setitem__(self, key: str, value: Any) -> None:
|
|
98
|
+
self.additional_properties[key] = value
|
|
99
|
+
|
|
100
|
+
def __delitem__(self, key: str) -> None:
|
|
101
|
+
del self.additional_properties[key]
|
|
102
|
+
|
|
103
|
+
def __contains__(self, key: str) -> bool:
|
|
104
|
+
return key in self.additional_properties
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from enum import StrEnum
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class BatchErrorCode(StrEnum):
|
|
5
|
+
ACCESS_DENIED = "access_denied"
|
|
6
|
+
BAD_REQUEST = "bad_request"
|
|
7
|
+
BUSY = "busy"
|
|
8
|
+
NOT_FOUND = "not_found"
|
|
9
|
+
NO_CREDITS = "no_credits"
|
|
10
|
+
REQUEST_REJECTED = "request_rejected"
|
|
11
|
+
UPSTREAM_ERROR = "upstream_error"
|
|
12
|
+
UPSTREAM_RATE_LIMITED = "upstream_rate_limited"
|
|
13
|
+
|
|
14
|
+
def __str__(self) -> str:
|
|
15
|
+
return str(self.value)
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
from typing import TYPE_CHECKING, Any, TypeVar
|
|
5
|
+
from uuid import UUID
|
|
6
|
+
|
|
7
|
+
from attrs import define as _attrs_define
|
|
8
|
+
from attrs import field as _attrs_field
|
|
9
|
+
|
|
10
|
+
from ..models.batch_meta_cache import BatchMetaCache
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from ..models.batch_error import BatchError
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
T = TypeVar("T", bound="BatchMeta")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@_attrs_define
|
|
20
|
+
class BatchMeta:
|
|
21
|
+
"""
|
|
22
|
+
Attributes:
|
|
23
|
+
errors (list[BatchError]): Inputs that returned nothing, with the reason. Never charged.
|
|
24
|
+
items (int): Objects returned. In the video lists batch: videos returned, for all accounts together.
|
|
25
|
+
credits_charged (float):
|
|
26
|
+
balance_remaining (float):
|
|
27
|
+
cache (BatchMetaCache): The mode of the found items when they all agree, else `mixed`.
|
|
28
|
+
cache_hits (int): Objects served from cache, at half price. In the video lists batch: accounts served from
|
|
29
|
+
cache.
|
|
30
|
+
request_id (UUID):
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
errors: list[BatchError]
|
|
34
|
+
items: int
|
|
35
|
+
credits_charged: float
|
|
36
|
+
balance_remaining: float
|
|
37
|
+
cache: BatchMetaCache
|
|
38
|
+
cache_hits: int
|
|
39
|
+
request_id: UUID
|
|
40
|
+
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
|
|
41
|
+
|
|
42
|
+
def to_dict(self) -> dict[str, Any]:
|
|
43
|
+
errors = []
|
|
44
|
+
for errors_item_data in self.errors:
|
|
45
|
+
errors_item = errors_item_data.to_dict()
|
|
46
|
+
errors.append(errors_item)
|
|
47
|
+
|
|
48
|
+
items = self.items
|
|
49
|
+
|
|
50
|
+
credits_charged = self.credits_charged
|
|
51
|
+
|
|
52
|
+
balance_remaining = self.balance_remaining
|
|
53
|
+
|
|
54
|
+
cache = self.cache.value
|
|
55
|
+
|
|
56
|
+
cache_hits = self.cache_hits
|
|
57
|
+
|
|
58
|
+
request_id = str(self.request_id)
|
|
59
|
+
|
|
60
|
+
field_dict: dict[str, Any] = {}
|
|
61
|
+
field_dict.update(self.additional_properties)
|
|
62
|
+
field_dict.update(
|
|
63
|
+
{
|
|
64
|
+
"errors": errors,
|
|
65
|
+
"items": items,
|
|
66
|
+
"credits_charged": credits_charged,
|
|
67
|
+
"balance_remaining": balance_remaining,
|
|
68
|
+
"cache": cache,
|
|
69
|
+
"cache_hits": cache_hits,
|
|
70
|
+
"request_id": request_id,
|
|
71
|
+
}
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
return field_dict
|
|
75
|
+
|
|
76
|
+
@classmethod
|
|
77
|
+
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
|
|
78
|
+
from ..models.batch_error import BatchError # noqa: PLC0415
|
|
79
|
+
|
|
80
|
+
d = dict(src_dict)
|
|
81
|
+
errors = []
|
|
82
|
+
_errors = d.pop("errors")
|
|
83
|
+
for errors_item_data in _errors:
|
|
84
|
+
errors_item = BatchError.from_dict(errors_item_data)
|
|
85
|
+
|
|
86
|
+
errors.append(errors_item)
|
|
87
|
+
|
|
88
|
+
items = d.pop("items")
|
|
89
|
+
|
|
90
|
+
credits_charged = d.pop("credits_charged")
|
|
91
|
+
|
|
92
|
+
balance_remaining = d.pop("balance_remaining")
|
|
93
|
+
|
|
94
|
+
cache = BatchMetaCache(d.pop("cache"))
|
|
95
|
+
|
|
96
|
+
cache_hits = d.pop("cache_hits")
|
|
97
|
+
|
|
98
|
+
request_id = UUID(d.pop("request_id"))
|
|
99
|
+
|
|
100
|
+
batch_meta = cls(
|
|
101
|
+
errors=errors,
|
|
102
|
+
items=items,
|
|
103
|
+
credits_charged=credits_charged,
|
|
104
|
+
balance_remaining=balance_remaining,
|
|
105
|
+
cache=cache,
|
|
106
|
+
cache_hits=cache_hits,
|
|
107
|
+
request_id=request_id,
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
batch_meta.additional_properties = d
|
|
111
|
+
return batch_meta
|
|
112
|
+
|
|
113
|
+
@property
|
|
114
|
+
def additional_keys(self) -> list[str]:
|
|
115
|
+
return list(self.additional_properties.keys())
|
|
116
|
+
|
|
117
|
+
def __getitem__(self, key: str) -> Any:
|
|
118
|
+
return self.additional_properties[key]
|
|
119
|
+
|
|
120
|
+
def __setitem__(self, key: str, value: Any) -> None:
|
|
121
|
+
self.additional_properties[key] = value
|
|
122
|
+
|
|
123
|
+
def __delitem__(self, key: str) -> None:
|
|
124
|
+
del self.additional_properties[key]
|
|
125
|
+
|
|
126
|
+
def __contains__(self, key: str) -> bool:
|
|
127
|
+
return key in self.additional_properties
|