ddgai 1.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.
- ddgai-1.1.0/LICENSE +21 -0
- ddgai-1.1.0/PKG-INFO +131 -0
- ddgai-1.1.0/README.md +103 -0
- ddgai-1.1.0/ddgai.egg-info/PKG-INFO +131 -0
- ddgai-1.1.0/ddgai.egg-info/SOURCES.txt +17 -0
- ddgai-1.1.0/ddgai.egg-info/dependency_links.txt +1 -0
- ddgai-1.1.0/ddgai.egg-info/requires.txt +7 -0
- ddgai-1.1.0/ddgai.egg-info/top_level.txt +1 -0
- ddgai-1.1.0/duckai/__init__.py +18 -0
- ddgai-1.1.0/duckai/challenge.py +159 -0
- ddgai-1.1.0/duckai/client.py +397 -0
- ddgai-1.1.0/duckai/enums.py +22 -0
- ddgai-1.1.0/duckai/errors.py +35 -0
- ddgai-1.1.0/duckai/http.py +191 -0
- ddgai-1.1.0/duckai/logging.py +51 -0
- ddgai-1.1.0/duckai/models.py +52 -0
- ddgai-1.1.0/duckai/utils.py +44 -0
- ddgai-1.1.0/pyproject.toml +42 -0
- ddgai-1.1.0/setup.cfg +4 -0
ddgai-1.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 frat
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
ddgai-1.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ddgai
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: High-performance reverse-engineered Duck.ai (DuckDuckGo AI Chat) client
|
|
5
|
+
Author: frat
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/claimtest22/duckai
|
|
8
|
+
Project-URL: Repository, https://github.com/claimtest22/duckai
|
|
9
|
+
Keywords: ddgai,duck.ai,duckduckgo,ai,chat,llm
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: curl_cffi>=0.7.0
|
|
22
|
+
Requires-Dist: orjson>=3.9.0
|
|
23
|
+
Requires-Dist: loguru>=0.7.0
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest; extra == "dev"
|
|
26
|
+
Requires-Dist: pytest-asyncio; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# ddgai
|
|
30
|
+
|
|
31
|
+
High-performance reverse-engineered **Duck.ai** (DuckDuckGo AI Chat) client.
|
|
32
|
+
|
|
33
|
+
Made by **frat**.
|
|
34
|
+
|
|
35
|
+
## Features
|
|
36
|
+
|
|
37
|
+
- Pure-Python static solver for the `x-vqd-hash-1` challenge
|
|
38
|
+
- Automatic token refresh + impersonation rotation on 418 / 429
|
|
39
|
+
- Full `curl_cffi` browser impersonation pool (desktop + mobile)
|
|
40
|
+
- Custom system prompts (per-client or per-call)
|
|
41
|
+
- Streaming + non-streaming chat
|
|
42
|
+
- Conversation history
|
|
43
|
+
- orjson + async for minimal overhead
|
|
44
|
+
- loguru logging
|
|
45
|
+
- discord.py-style structure & type hints
|
|
46
|
+
|
|
47
|
+
## Install
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install ddgai
|
|
51
|
+
# or from source
|
|
52
|
+
pip install -e .
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Quick start
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
import asyncio
|
|
59
|
+
from duckai import Client, Model
|
|
60
|
+
|
|
61
|
+
async def main():
|
|
62
|
+
async with Client(model=Model.GPT_4O_MINI) as client:
|
|
63
|
+
result = await client.chat("ping")
|
|
64
|
+
print(result.content)
|
|
65
|
+
|
|
66
|
+
asyncio.run(main())
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## System prompts
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
async with Client(
|
|
73
|
+
model=Model.GPT_4O_MINI,
|
|
74
|
+
system="You are a concise senior engineer. Answer in short bullets only.",
|
|
75
|
+
) as client:
|
|
76
|
+
r = await client.chat("How do I read a file asynchronously in Python?")
|
|
77
|
+
print(r.content)
|
|
78
|
+
|
|
79
|
+
# one-off override
|
|
80
|
+
r2 = await client.chat(
|
|
81
|
+
"Explain generators",
|
|
82
|
+
system="You only speak like a pirate. Max 2 sentences.",
|
|
83
|
+
history=False,
|
|
84
|
+
)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Streaming
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
async with Client() as client:
|
|
91
|
+
async for chunk in client.stream("explain quantum computing in one sentence"):
|
|
92
|
+
if chunk.content:
|
|
93
|
+
print(chunk.content, end="", flush=True)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Multi-turn history
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
async with Client() as client:
|
|
100
|
+
await client.chat("My name is Alex")
|
|
101
|
+
r = await client.chat("What is my name?")
|
|
102
|
+
print(r.content)
|
|
103
|
+
client.clear_history()
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Models
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
models = await client.models()
|
|
110
|
+
for m in models:
|
|
111
|
+
print(m.model, m.model_name)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Examples
|
|
115
|
+
|
|
116
|
+
See the `examples/` directory:
|
|
117
|
+
|
|
118
|
+
- `basic.py` — one-shot chat
|
|
119
|
+
- `system_prompt.py` — custom system prompts
|
|
120
|
+
- `stream.py` — streaming
|
|
121
|
+
- `history.py` — multi-turn
|
|
122
|
+
|
|
123
|
+
## Notes
|
|
124
|
+
|
|
125
|
+
- The challenge solver is a pure-Python static reimplementation. It works for the current generation of challenges. When DuckDuckGo rotates the challenge heavily the client auto-retries and rotates fingerprints.
|
|
126
|
+
- Datacenter IPs are frequently blocked or rate-limited. Prefer residential proxies for production use.
|
|
127
|
+
- Respect DuckDuckGo ToS.
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
MIT — made by frat
|
ddgai-1.1.0/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# ddgai
|
|
2
|
+
|
|
3
|
+
High-performance reverse-engineered **Duck.ai** (DuckDuckGo AI Chat) client.
|
|
4
|
+
|
|
5
|
+
Made by **frat**.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- Pure-Python static solver for the `x-vqd-hash-1` challenge
|
|
10
|
+
- Automatic token refresh + impersonation rotation on 418 / 429
|
|
11
|
+
- Full `curl_cffi` browser impersonation pool (desktop + mobile)
|
|
12
|
+
- Custom system prompts (per-client or per-call)
|
|
13
|
+
- Streaming + non-streaming chat
|
|
14
|
+
- Conversation history
|
|
15
|
+
- orjson + async for minimal overhead
|
|
16
|
+
- loguru logging
|
|
17
|
+
- discord.py-style structure & type hints
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install ddgai
|
|
23
|
+
# or from source
|
|
24
|
+
pip install -e .
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick start
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
import asyncio
|
|
31
|
+
from duckai import Client, Model
|
|
32
|
+
|
|
33
|
+
async def main():
|
|
34
|
+
async with Client(model=Model.GPT_4O_MINI) as client:
|
|
35
|
+
result = await client.chat("ping")
|
|
36
|
+
print(result.content)
|
|
37
|
+
|
|
38
|
+
asyncio.run(main())
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## System prompts
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
async with Client(
|
|
45
|
+
model=Model.GPT_4O_MINI,
|
|
46
|
+
system="You are a concise senior engineer. Answer in short bullets only.",
|
|
47
|
+
) as client:
|
|
48
|
+
r = await client.chat("How do I read a file asynchronously in Python?")
|
|
49
|
+
print(r.content)
|
|
50
|
+
|
|
51
|
+
# one-off override
|
|
52
|
+
r2 = await client.chat(
|
|
53
|
+
"Explain generators",
|
|
54
|
+
system="You only speak like a pirate. Max 2 sentences.",
|
|
55
|
+
history=False,
|
|
56
|
+
)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Streaming
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
async with Client() as client:
|
|
63
|
+
async for chunk in client.stream("explain quantum computing in one sentence"):
|
|
64
|
+
if chunk.content:
|
|
65
|
+
print(chunk.content, end="", flush=True)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Multi-turn history
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
async with Client() as client:
|
|
72
|
+
await client.chat("My name is Alex")
|
|
73
|
+
r = await client.chat("What is my name?")
|
|
74
|
+
print(r.content)
|
|
75
|
+
client.clear_history()
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Models
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
models = await client.models()
|
|
82
|
+
for m in models:
|
|
83
|
+
print(m.model, m.model_name)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Examples
|
|
87
|
+
|
|
88
|
+
See the `examples/` directory:
|
|
89
|
+
|
|
90
|
+
- `basic.py` — one-shot chat
|
|
91
|
+
- `system_prompt.py` — custom system prompts
|
|
92
|
+
- `stream.py` — streaming
|
|
93
|
+
- `history.py` — multi-turn
|
|
94
|
+
|
|
95
|
+
## Notes
|
|
96
|
+
|
|
97
|
+
- The challenge solver is a pure-Python static reimplementation. It works for the current generation of challenges. When DuckDuckGo rotates the challenge heavily the client auto-retries and rotates fingerprints.
|
|
98
|
+
- Datacenter IPs are frequently blocked or rate-limited. Prefer residential proxies for production use.
|
|
99
|
+
- Respect DuckDuckGo ToS.
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
MIT — made by frat
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ddgai
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: High-performance reverse-engineered Duck.ai (DuckDuckGo AI Chat) client
|
|
5
|
+
Author: frat
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/claimtest22/duckai
|
|
8
|
+
Project-URL: Repository, https://github.com/claimtest22/duckai
|
|
9
|
+
Keywords: ddgai,duck.ai,duckduckgo,ai,chat,llm
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: curl_cffi>=0.7.0
|
|
22
|
+
Requires-Dist: orjson>=3.9.0
|
|
23
|
+
Requires-Dist: loguru>=0.7.0
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest; extra == "dev"
|
|
26
|
+
Requires-Dist: pytest-asyncio; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# ddgai
|
|
30
|
+
|
|
31
|
+
High-performance reverse-engineered **Duck.ai** (DuckDuckGo AI Chat) client.
|
|
32
|
+
|
|
33
|
+
Made by **frat**.
|
|
34
|
+
|
|
35
|
+
## Features
|
|
36
|
+
|
|
37
|
+
- Pure-Python static solver for the `x-vqd-hash-1` challenge
|
|
38
|
+
- Automatic token refresh + impersonation rotation on 418 / 429
|
|
39
|
+
- Full `curl_cffi` browser impersonation pool (desktop + mobile)
|
|
40
|
+
- Custom system prompts (per-client or per-call)
|
|
41
|
+
- Streaming + non-streaming chat
|
|
42
|
+
- Conversation history
|
|
43
|
+
- orjson + async for minimal overhead
|
|
44
|
+
- loguru logging
|
|
45
|
+
- discord.py-style structure & type hints
|
|
46
|
+
|
|
47
|
+
## Install
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install ddgai
|
|
51
|
+
# or from source
|
|
52
|
+
pip install -e .
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Quick start
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
import asyncio
|
|
59
|
+
from duckai import Client, Model
|
|
60
|
+
|
|
61
|
+
async def main():
|
|
62
|
+
async with Client(model=Model.GPT_4O_MINI) as client:
|
|
63
|
+
result = await client.chat("ping")
|
|
64
|
+
print(result.content)
|
|
65
|
+
|
|
66
|
+
asyncio.run(main())
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## System prompts
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
async with Client(
|
|
73
|
+
model=Model.GPT_4O_MINI,
|
|
74
|
+
system="You are a concise senior engineer. Answer in short bullets only.",
|
|
75
|
+
) as client:
|
|
76
|
+
r = await client.chat("How do I read a file asynchronously in Python?")
|
|
77
|
+
print(r.content)
|
|
78
|
+
|
|
79
|
+
# one-off override
|
|
80
|
+
r2 = await client.chat(
|
|
81
|
+
"Explain generators",
|
|
82
|
+
system="You only speak like a pirate. Max 2 sentences.",
|
|
83
|
+
history=False,
|
|
84
|
+
)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Streaming
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
async with Client() as client:
|
|
91
|
+
async for chunk in client.stream("explain quantum computing in one sentence"):
|
|
92
|
+
if chunk.content:
|
|
93
|
+
print(chunk.content, end="", flush=True)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Multi-turn history
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
async with Client() as client:
|
|
100
|
+
await client.chat("My name is Alex")
|
|
101
|
+
r = await client.chat("What is my name?")
|
|
102
|
+
print(r.content)
|
|
103
|
+
client.clear_history()
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Models
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
models = await client.models()
|
|
110
|
+
for m in models:
|
|
111
|
+
print(m.model, m.model_name)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Examples
|
|
115
|
+
|
|
116
|
+
See the `examples/` directory:
|
|
117
|
+
|
|
118
|
+
- `basic.py` — one-shot chat
|
|
119
|
+
- `system_prompt.py` — custom system prompts
|
|
120
|
+
- `stream.py` — streaming
|
|
121
|
+
- `history.py` — multi-turn
|
|
122
|
+
|
|
123
|
+
## Notes
|
|
124
|
+
|
|
125
|
+
- The challenge solver is a pure-Python static reimplementation. It works for the current generation of challenges. When DuckDuckGo rotates the challenge heavily the client auto-retries and rotates fingerprints.
|
|
126
|
+
- Datacenter IPs are frequently blocked or rate-limited. Prefer residential proxies for production use.
|
|
127
|
+
- Respect DuckDuckGo ToS.
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
MIT — made by frat
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
ddgai.egg-info/PKG-INFO
|
|
5
|
+
ddgai.egg-info/SOURCES.txt
|
|
6
|
+
ddgai.egg-info/dependency_links.txt
|
|
7
|
+
ddgai.egg-info/requires.txt
|
|
8
|
+
ddgai.egg-info/top_level.txt
|
|
9
|
+
duckai/__init__.py
|
|
10
|
+
duckai/challenge.py
|
|
11
|
+
duckai/client.py
|
|
12
|
+
duckai/enums.py
|
|
13
|
+
duckai/errors.py
|
|
14
|
+
duckai/http.py
|
|
15
|
+
duckai/logging.py
|
|
16
|
+
duckai/models.py
|
|
17
|
+
duckai/utils.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
duckai
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Duck.ai (DuckDuckGo AI Chat) reverse-engineered client.
|
|
3
|
+
|
|
4
|
+
Made by frat.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .client import Client
|
|
8
|
+
from .errors import *
|
|
9
|
+
from .models import *
|
|
10
|
+
from .enums import Model
|
|
11
|
+
|
|
12
|
+
__version__ = "1.1.0"
|
|
13
|
+
__author__ = "frat"
|
|
14
|
+
|
|
15
|
+
__all__ = (
|
|
16
|
+
"Client",
|
|
17
|
+
"Model",
|
|
18
|
+
)
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Static VQD hash challenge solver.
|
|
3
|
+
|
|
4
|
+
Pure-Python reimplementation of the Duck.ai x-vqd-hash-1 challenge.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import re
|
|
10
|
+
import time
|
|
11
|
+
from base64 import b64decode
|
|
12
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
13
|
+
|
|
14
|
+
from .logging import log
|
|
15
|
+
from .utils import sha256_b64, b64json
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# Values observed across many live challenges
|
|
19
|
+
_DOM_VALUES = ("6823", "101", "6824", "123")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _extract_server_hashes(script: str) -> List[str]:
|
|
23
|
+
"""Best-effort extraction of server_hashes from obfuscated challenge JS."""
|
|
24
|
+
found: List[str] = []
|
|
25
|
+
for m in re.finditer(r"[A-Za-z0-9+/]{40,60}={0,2}", script):
|
|
26
|
+
h = m.group(0)
|
|
27
|
+
if len(h) >= 40 and h not in found:
|
|
28
|
+
found.append(h)
|
|
29
|
+
if len(found) >= 2:
|
|
30
|
+
return found[:3]
|
|
31
|
+
return [
|
|
32
|
+
"+/YUQv1Ne26OHYkbwrdpxkaQIdaIleb6HXMgbHp0neA=",
|
|
33
|
+
"eQFdUCDrfsCt5feLl8+blMsghhZfsKmQlv6SnWDdfWE=",
|
|
34
|
+
"DZd0RXn6D3rs7nSqoGdOxYxI3nYHczNFwZSfTCocw3A=",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _extract_meta(script: str) -> Dict[str, str]:
|
|
39
|
+
"""Pull challenge_id / timestamp-like strings if present."""
|
|
40
|
+
meta: Dict[str, str] = {
|
|
41
|
+
"v": "4",
|
|
42
|
+
"challenge_id": "static-" + str(int(time.time())),
|
|
43
|
+
"timestamp": str(int(time.time() * 1000)),
|
|
44
|
+
"origin": "https://duck.ai",
|
|
45
|
+
"stack": "Error\n at solve (native)",
|
|
46
|
+
"duration": str(8 + int(time.time() * 1000) % 20),
|
|
47
|
+
}
|
|
48
|
+
ids = re.findall(
|
|
49
|
+
r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
|
|
50
|
+
script,
|
|
51
|
+
)
|
|
52
|
+
if ids:
|
|
53
|
+
meta["challenge_id"] = ids[0]
|
|
54
|
+
return meta
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _build_client_raw(user_agent: str) -> List[str]:
|
|
58
|
+
"""Reconstruct the raw values the challenge hashes on the client side."""
|
|
59
|
+
brands = ""
|
|
60
|
+
if "Chrome/" in user_agent:
|
|
61
|
+
try:
|
|
62
|
+
ver = user_agent.split("Chrome/")[1].split(".")[0]
|
|
63
|
+
brands = (
|
|
64
|
+
f'"Chromium";v="{ver}", '
|
|
65
|
+
f'"Google Chrome";v="{ver}", '
|
|
66
|
+
f'"Not_A Brand";v="24"'
|
|
67
|
+
)
|
|
68
|
+
except Exception:
|
|
69
|
+
brands = (
|
|
70
|
+
'"Chromium";v="131", '
|
|
71
|
+
'"Google Chrome";v="131", '
|
|
72
|
+
'"Not_A Brand";v="24"'
|
|
73
|
+
)
|
|
74
|
+
elif "Firefox/" in user_agent:
|
|
75
|
+
brands = ""
|
|
76
|
+
else:
|
|
77
|
+
brands = (
|
|
78
|
+
'"Chromium";v="131", '
|
|
79
|
+
'"Google Chrome";v="131", '
|
|
80
|
+
'"Not_A Brand";v="24"'
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
ua_key = user_agent + brands
|
|
84
|
+
dom = _DOM_VALUES[0]
|
|
85
|
+
return [ua_key, dom]
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def solve_static(
|
|
89
|
+
challenge_b64: str,
|
|
90
|
+
user_agent: str,
|
|
91
|
+
*,
|
|
92
|
+
origin: str = "https://duck.ai",
|
|
93
|
+
) -> str:
|
|
94
|
+
"""Solve the x-vqd-hash-1 challenge purely in Python.
|
|
95
|
+
|
|
96
|
+
Parameters
|
|
97
|
+
----------
|
|
98
|
+
challenge_b64: str
|
|
99
|
+
The raw base64 value from the status response header.
|
|
100
|
+
user_agent: str
|
|
101
|
+
The User-Agent that will be used for the subsequent chat request.
|
|
102
|
+
origin: str
|
|
103
|
+
Origin to embed in meta.
|
|
104
|
+
|
|
105
|
+
Returns
|
|
106
|
+
-------
|
|
107
|
+
str
|
|
108
|
+
Base64-encoded solved payload ready for the x-vqd-hash-1 header.
|
|
109
|
+
"""
|
|
110
|
+
try:
|
|
111
|
+
script = b64decode(challenge_b64).decode("utf-8", errors="replace")
|
|
112
|
+
except Exception:
|
|
113
|
+
script = ""
|
|
114
|
+
|
|
115
|
+
server_hashes = _extract_server_hashes(script)
|
|
116
|
+
meta = _extract_meta(script)
|
|
117
|
+
meta["origin"] = origin
|
|
118
|
+
|
|
119
|
+
raw_client = _build_client_raw(user_agent)
|
|
120
|
+
client_hashes = [sha256_b64(x) for x in raw_client]
|
|
121
|
+
|
|
122
|
+
payload: Dict[str, Any] = {
|
|
123
|
+
"server_hashes": server_hashes,
|
|
124
|
+
"client_hashes": client_hashes,
|
|
125
|
+
"signals": {},
|
|
126
|
+
"meta": meta,
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
solved = b64json(payload)
|
|
130
|
+
log.debug(
|
|
131
|
+
"challenge solved client_hashes={} len={}",
|
|
132
|
+
len(client_hashes),
|
|
133
|
+
len(solved),
|
|
134
|
+
)
|
|
135
|
+
return solved
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def solve_from_status(
|
|
139
|
+
headers: Dict[str, str],
|
|
140
|
+
user_agent: str,
|
|
141
|
+
*,
|
|
142
|
+
origin: str = "https://duck.ai",
|
|
143
|
+
) -> Tuple[Optional[str], Optional[str]]:
|
|
144
|
+
"""Convenience: extract challenge + vqd-4 from status headers and solve.
|
|
145
|
+
|
|
146
|
+
Returns
|
|
147
|
+
-------
|
|
148
|
+
tuple
|
|
149
|
+
(solved_hash_1, vqd_4)
|
|
150
|
+
"""
|
|
151
|
+
h = {k.lower(): v for k, v in headers.items()}
|
|
152
|
+
challenge = h.get("x-vqd-hash-1")
|
|
153
|
+
vqd4 = h.get("x-vqd-4")
|
|
154
|
+
|
|
155
|
+
if not challenge:
|
|
156
|
+
return None, vqd4
|
|
157
|
+
|
|
158
|
+
solved = solve_static(challenge, user_agent, origin=origin)
|
|
159
|
+
return solved, vqd4
|