aioe621 0.2.2__tar.gz → 0.3.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.
- {aioe621-0.2.2 → aioe621-0.3.0}/PKG-INFO +1 -1
- {aioe621-0.2.2 → aioe621-0.3.0}/pyproject.toml +1 -1
- {aioe621-0.2.2 → aioe621-0.3.0}/src/aioe621/client.py +23 -9
- {aioe621-0.2.2 → aioe621-0.3.0}/src/aioe621/endpoints/posts.py +27 -25
- {aioe621-0.2.2 → aioe621-0.3.0}/src/aioe621/schemas.py +78 -62
- {aioe621-0.2.2 → aioe621-0.3.0}/LICENSE +0 -0
- {aioe621-0.2.2 → aioe621-0.3.0}/README.md +0 -0
- {aioe621-0.2.2 → aioe621-0.3.0}/src/aioe621/__init__.py +0 -0
- {aioe621-0.2.2 → aioe621-0.3.0}/src/aioe621/endpoints/__init__.py +0 -0
- {aioe621-0.2.2 → aioe621-0.3.0}/src/aioe621/endpoints/endpoint.py +0 -0
- {aioe621-0.2.2 → aioe621-0.3.0}/src/aioe621/exceptions.py +0 -0
- {aioe621-0.2.2 → aioe621-0.3.0}/src/aioe621/py.typed +0 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import typing
|
|
2
|
+
from typing import overload
|
|
2
3
|
|
|
3
4
|
import httpx
|
|
4
|
-
from pydantic import BaseModel
|
|
5
|
+
from pydantic import BaseModel, TypeAdapter
|
|
5
6
|
|
|
6
7
|
from aioe621 import endpoints
|
|
7
8
|
from aioe621.exceptions import (
|
|
@@ -78,18 +79,31 @@ class Client:
|
|
|
78
79
|
raise self._find_error(response)
|
|
79
80
|
|
|
80
81
|
_MT = typing.TypeVar("_MT", bound="BaseModel")
|
|
82
|
+
_T = typing.TypeVar("_T")
|
|
83
|
+
|
|
84
|
+
@overload
|
|
85
|
+
async def _request_model(
|
|
86
|
+
self, model: TypeAdapter[_T], method: str, url: str, **kwargs
|
|
87
|
+
) -> _T: ...
|
|
88
|
+
|
|
89
|
+
@overload
|
|
90
|
+
async def _request_model(
|
|
91
|
+
self, model: type[_MT], method: str, url: str, **kwargs
|
|
92
|
+
) -> _MT: ...
|
|
81
93
|
|
|
82
94
|
async def _request_model(
|
|
83
95
|
self,
|
|
84
|
-
model: type[_MT],
|
|
96
|
+
model: type[_MT] | TypeAdapter[_T],
|
|
85
97
|
method: str,
|
|
86
98
|
url: str,
|
|
87
99
|
**kwargs,
|
|
88
|
-
) -> _MT:
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
**kwargs,
|
|
94
|
-
)
|
|
100
|
+
) -> _MT | _T:
|
|
101
|
+
json: str = await self._request(
|
|
102
|
+
method=method,
|
|
103
|
+
url=url,
|
|
104
|
+
**kwargs,
|
|
95
105
|
)
|
|
106
|
+
if isinstance(model, TypeAdapter):
|
|
107
|
+
return model.validate_json(json, strict=True)
|
|
108
|
+
else:
|
|
109
|
+
return model.model_validate_json(json, strict=True)
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
from typing import Iterable
|
|
2
2
|
|
|
3
|
+
from pydantic import TypeAdapter
|
|
4
|
+
|
|
3
5
|
from aioe621.endpoints.endpoint import Endpoint
|
|
4
|
-
from aioe621.schemas import Post
|
|
6
|
+
from aioe621.schemas import Post
|
|
5
7
|
|
|
6
8
|
|
|
7
9
|
class Posts(Endpoint):
|
|
@@ -14,16 +16,16 @@ class Posts(Endpoint):
|
|
|
14
16
|
if not isinstance(tags, str):
|
|
15
17
|
tags = " ".join(tags)
|
|
16
18
|
|
|
17
|
-
return (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
)
|
|
19
|
+
return await self._request_model(
|
|
20
|
+
TypeAdapter(tuple[Post, ...]),
|
|
21
|
+
"GET",
|
|
22
|
+
"/posts.json",
|
|
23
|
+
tags=tags,
|
|
24
|
+
limit=limit,
|
|
25
|
+
page=page,
|
|
26
|
+
v2=True,
|
|
27
|
+
mode="extended",
|
|
28
|
+
)
|
|
27
29
|
|
|
28
30
|
search = list
|
|
29
31
|
|
|
@@ -37,21 +39,21 @@ class Posts(Endpoint):
|
|
|
37
39
|
"""
|
|
38
40
|
if id <= 0:
|
|
39
41
|
raise ValueError("The post ID must not be less than or equal to zero.")
|
|
40
|
-
return (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
)
|
|
42
|
+
return await self._request_model(
|
|
43
|
+
Post,
|
|
44
|
+
"GET",
|
|
45
|
+
f"/posts/{id}.json",
|
|
46
|
+
v2=True,
|
|
47
|
+
mode="extended",
|
|
48
|
+
)
|
|
47
49
|
|
|
48
50
|
async def random(
|
|
49
51
|
self,
|
|
50
52
|
) -> Post:
|
|
51
|
-
return (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
)
|
|
53
|
+
return await self._request_model(
|
|
54
|
+
Post,
|
|
55
|
+
"GET",
|
|
56
|
+
"/posts/random.json",
|
|
57
|
+
v2=True,
|
|
58
|
+
mode="extended",
|
|
59
|
+
)
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
2
|
from enum import Enum
|
|
3
3
|
from functools import cached_property
|
|
4
|
-
from typing import Literal,
|
|
4
|
+
from typing import Literal, NamedTuple
|
|
5
5
|
|
|
6
6
|
from pydantic import BaseModel, ConfigDict, Field
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class APIModel(BaseModel):
|
|
10
|
-
model_config = ConfigDict(
|
|
10
|
+
model_config = ConfigDict(
|
|
11
|
+
frozen=True,
|
|
12
|
+
ignored_types=(cached_property,),
|
|
13
|
+
strict=True,
|
|
14
|
+
extra="forbid",
|
|
15
|
+
)
|
|
11
16
|
|
|
12
17
|
|
|
13
18
|
class Auth(NamedTuple):
|
|
@@ -15,41 +20,26 @@ class Auth(NamedTuple):
|
|
|
15
20
|
api_key: str
|
|
16
21
|
|
|
17
22
|
|
|
18
|
-
class
|
|
23
|
+
class FileDimensions(APIModel):
|
|
19
24
|
width: int
|
|
20
25
|
height: int
|
|
21
|
-
url: str | None = None # Safest to make URL optional (deleted posts hide URLs)
|
|
22
26
|
|
|
23
27
|
|
|
24
|
-
class
|
|
25
|
-
|
|
26
|
-
size: int
|
|
27
|
-
md5: str
|
|
28
|
+
class BaseFile(FileDimensions):
|
|
29
|
+
url: str | None
|
|
28
30
|
|
|
29
31
|
|
|
30
|
-
class PreviewFile(
|
|
31
|
-
|
|
32
|
+
class PreviewFile(FileDimensions):
|
|
33
|
+
jpg: str | None
|
|
34
|
+
webp: str | None
|
|
32
35
|
|
|
33
36
|
|
|
34
|
-
class
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
class FilesMeta(APIModel):
|
|
38
|
+
md5: str
|
|
39
|
+
ext: str
|
|
37
40
|
size: int
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
url: str | None = None
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
class Alternates(APIModel):
|
|
44
|
-
has: bool = False
|
|
45
|
-
original: VideoAlternate | None = None
|
|
46
|
-
variants: Mapping[str, VideoAlternate] = Field(default_factory=dict)
|
|
47
|
-
samples: Mapping[str, VideoAlternate] = Field(default_factory=dict)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
class SampleFile(PreviewFile):
|
|
51
|
-
has: bool
|
|
52
|
-
alternates: Alternates
|
|
41
|
+
duration: float | None
|
|
42
|
+
has_sample: bool
|
|
53
43
|
|
|
54
44
|
|
|
55
45
|
class PostScore(APIModel):
|
|
@@ -93,58 +83,84 @@ class PostFlags(APIModel):
|
|
|
93
83
|
deleted: bool
|
|
94
84
|
|
|
95
85
|
|
|
96
|
-
class
|
|
86
|
+
class PostRating(str, Enum):
|
|
97
87
|
SAFE = "s"
|
|
98
88
|
QUESTIONABLE = "q"
|
|
99
89
|
EXPLICIT = "e"
|
|
100
90
|
|
|
101
91
|
|
|
102
|
-
class
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
children: tuple[int, ...]
|
|
92
|
+
class VideoFile(BaseFile):
|
|
93
|
+
fps: float
|
|
94
|
+
codec: str # TODO: "vp9" or "avc1.4D401E" or ...?
|
|
95
|
+
size: int
|
|
107
96
|
|
|
108
97
|
|
|
109
|
-
class
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
98
|
+
class VideoVariants(APIModel):
|
|
99
|
+
mp4: VideoFile | None = None
|
|
100
|
+
# TODO: any more?
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class VideoSamples(APIModel):
|
|
104
|
+
p480: VideoFile | None = Field(alias="480p", default=None)
|
|
105
|
+
p720: VideoFile | None = Field(alias="720p", default=None)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class Video(APIModel):
|
|
109
|
+
has: Literal[True]
|
|
110
|
+
original: VideoFile
|
|
111
|
+
variants: VideoVariants
|
|
112
|
+
samples: VideoSamples
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
|
|
115
|
+
class PostFiles(APIModel):
|
|
116
|
+
meta: FilesMeta
|
|
117
|
+
original: BaseFile
|
|
115
118
|
preview: PreviewFile
|
|
116
|
-
sample:
|
|
119
|
+
sample: PreviewFile
|
|
120
|
+
video: Video | None = None
|
|
117
121
|
|
|
118
|
-
score: PostScore
|
|
119
|
-
tags: PostTags
|
|
120
|
-
locked_tags: tuple[str, ...]
|
|
121
|
-
change_seq: int
|
|
122
|
-
flags: PostFlags
|
|
123
|
-
rating: Rating
|
|
124
122
|
|
|
123
|
+
class PostStats(APIModel):
|
|
124
|
+
score: PostScore
|
|
125
125
|
fav_count: int
|
|
126
|
-
sources: tuple[str, ...]
|
|
127
|
-
pools: tuple[int, ...]
|
|
128
|
-
relationships: Relationships
|
|
129
|
-
|
|
130
|
-
approver_id: int | None = None
|
|
131
|
-
uploader_id: int
|
|
132
|
-
uploader_name: str
|
|
133
|
-
description: str
|
|
134
|
-
comment_count: int
|
|
135
126
|
is_favorited: bool
|
|
136
|
-
|
|
137
127
|
vote: int
|
|
138
|
-
|
|
139
|
-
|
|
128
|
+
comment_count: int
|
|
129
|
+
hotness: float
|
|
140
130
|
|
|
141
131
|
|
|
142
|
-
class
|
|
143
|
-
|
|
132
|
+
class PostHas(APIModel):
|
|
133
|
+
parent: bool
|
|
134
|
+
children: bool
|
|
135
|
+
active_children: bool
|
|
136
|
+
notes: bool
|
|
137
|
+
sample: bool
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class PostRelationships(APIModel):
|
|
141
|
+
parent_id: int | None
|
|
142
|
+
children: tuple[int, ...]
|
|
144
143
|
|
|
145
144
|
|
|
146
|
-
class
|
|
147
|
-
|
|
145
|
+
class Post(APIModel):
|
|
146
|
+
id: int
|
|
147
|
+
created_at: datetime
|
|
148
|
+
updated_at: datetime
|
|
149
|
+
change_seq: int
|
|
150
|
+
files: PostFiles
|
|
151
|
+
uploader_id: int
|
|
152
|
+
uploader_name: str
|
|
153
|
+
approver_id: int | None
|
|
154
|
+
stats: PostStats
|
|
155
|
+
flags: PostFlags
|
|
156
|
+
has: PostHas
|
|
157
|
+
relationships: PostRelationships
|
|
158
|
+
pools: tuple[int, ...]
|
|
159
|
+
rating: PostRating
|
|
160
|
+
locked_tags: tuple[str, ...]
|
|
161
|
+
sources: tuple[str, ...]
|
|
162
|
+
description: str
|
|
163
|
+
tags: PostTags
|
|
148
164
|
|
|
149
165
|
|
|
150
166
|
class _ErrorResponse(APIModel):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|