parsehub 2.0.17__tar.gz → 2.0.18__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.
- parsehub-2.0.18/PKG-INFO +371 -0
- parsehub-2.0.18/README.md +332 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/pyproject.toml +5 -1
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/__init__.py +23 -8
- parsehub-2.0.18/src/parsehub/cli.py +313 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/provider_api/weibo.py +2 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/provider_api/xhs.py +4 -1
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/types/result.py +2 -2
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/utils/utils.py +8 -5
- parsehub-2.0.18/src/parsehub.egg-info/PKG-INFO +371 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub.egg-info/SOURCES.txt +5 -1
- parsehub-2.0.18/src/parsehub.egg-info/entry_points.txt +3 -0
- parsehub-2.0.18/test/test_cli.py +283 -0
- parsehub-2.0.18/test/test_core_offline.py +357 -0
- parsehub-2.0.17/PKG-INFO +0 -206
- parsehub-2.0.17/README.md +0 -167
- parsehub-2.0.17/src/parsehub.egg-info/PKG-INFO +0 -206
- {parsehub-2.0.17 → parsehub-2.0.18}/LICENSE +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/setup.cfg +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/__init__.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/config/__init__.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/config/config.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/errors.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/parsers/__init__.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/parsers/base/__init__.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/parsers/base/base.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/parsers/base/ytdlp.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/parsers/parser/__init__.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/parsers/parser/bilibili.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/parsers/parser/coolapk.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/parsers/parser/douyin.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/parsers/parser/facebook.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/parsers/parser/instagram.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/parsers/parser/kuaishou.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/parsers/parser/pipix.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/parsers/parser/threads.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/parsers/parser/tieba.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/parsers/parser/tiktok.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/parsers/parser/twitter.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/parsers/parser/weibo.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/parsers/parser/weixin.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/parsers/parser/xhs.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/parsers/parser/xiaoheihe.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/parsers/parser/youtube.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/parsers/parser/zuiyou.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/provider_api/__init__.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/provider_api/bilibili.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/provider_api/coolapk.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/provider_api/douyin.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/provider_api/instagram.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/provider_api/kuaishou.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/provider_api/pipix.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/provider_api/threads.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/provider_api/tieba.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/provider_api/tiktok.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/provider_api/twitter.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/provider_api/weixin.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/provider_api/xiaoheihe.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/provider_api/zuiyou.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/types/__init__.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/types/callback.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/types/media_file.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/types/media_ref.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/types/platform.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/types/post.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/utils/downloader.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub/utils/media_info.py +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub.egg-info/dependency_links.txt +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub.egg-info/requires.txt +0 -0
- {parsehub-2.0.17 → parsehub-2.0.18}/src/parsehub.egg-info/top_level.txt +0 -0
parsehub-2.0.18/PKG-INFO
ADDED
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: parsehub
|
|
3
|
+
Version: 2.0.18
|
|
4
|
+
Summary: 轻量、异步、开箱即用的社交媒体聚合解析库
|
|
5
|
+
Author-email: 梓澪 <zilingmio@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/z-mio/parsehub
|
|
8
|
+
Project-URL: Issues, https://github.com/z-mio/parsehub/issues
|
|
9
|
+
Keywords: parser,video-downloader,social-media,crawler,parsehub
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Topic :: Multimedia :: Video
|
|
14
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
15
|
+
Requires-Python: >=3.12.0
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: aiofiles>=23.2
|
|
19
|
+
Requires-Dist: beautifulsoup4>=4.12.3
|
|
20
|
+
Requires-Dist: loguru>=0.6.0
|
|
21
|
+
Requires-Dist: pydub>=0.25.1
|
|
22
|
+
Requires-Dist: python-dotenv>=1.0.1
|
|
23
|
+
Requires-Dist: tenacity>=8.5.0
|
|
24
|
+
Requires-Dist: urlextract>=1.9.0
|
|
25
|
+
Requires-Dist: yt-dlp[default]
|
|
26
|
+
Requires-Dist: lxml>=5.3.0
|
|
27
|
+
Requires-Dist: instaloader>=4.14
|
|
28
|
+
Requires-Dist: pydantic>=1.10.19
|
|
29
|
+
Requires-Dist: markdownify>=1.1.0
|
|
30
|
+
Requires-Dist: markdown>=3.7
|
|
31
|
+
Requires-Dist: requests
|
|
32
|
+
Requires-Dist: httpx>=0.24.1
|
|
33
|
+
Requires-Dist: pillow>=12.1.0
|
|
34
|
+
Requires-Dist: python-slugify[unidecode]>=8.0.4
|
|
35
|
+
Requires-Dist: opencv-python-headless>=4.13.0.92
|
|
36
|
+
Requires-Dist: cryptography>=46.0.6
|
|
37
|
+
Requires-Dist: gmssl>=3.2.2
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
|
|
40
|
+
<div align="center">
|
|
41
|
+
|
|
42
|
+
# 🔗 ParseHub
|
|
43
|
+
|
|
44
|
+
**社交媒体聚合解析器**
|
|
45
|
+
|
|
46
|
+
[](https://pypi.org/project/parsehub/)
|
|
47
|
+
[](https://www.python.org/)
|
|
48
|
+
[](LICENSE)
|
|
49
|
+
[](https://github.com/z-mio/parsehub)
|
|
50
|
+
|
|
51
|
+
轻量、异步、开箱即用的社交媒体解析与媒体下载库,支持 17+ 平台。
|
|
52
|
+
|
|
53
|
+
[支持平台](#-支持平台) · [安装](#-安装) · [快速开始](#-快速开始) · [API](#-api-速览) · [高级用法](#-高级用法) · [TG Bot](https://github.com/z-mio/parse_hub_bot)
|
|
54
|
+
|
|
55
|
+
</div>
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## ✨ 特性
|
|
60
|
+
|
|
61
|
+
- 🌍 **广泛的平台支持** — 覆盖国内外 17+ 主流社交媒体平台
|
|
62
|
+
- 🧹 **链接清理** — 自动提取分享文案中的链接,并清除可移除的跟踪参数
|
|
63
|
+
- 🎬 **多媒体解析** — 支持视频、图文、动图、实况照片和富文本文章
|
|
64
|
+
- 📦 **同步 / 异步 API** — 同时提供 `async/await` 与 `*_sync` 调用方式
|
|
65
|
+
- 🤖 **Telegram Bot** — 基于本项目的 Bot 已上线 → [@ParseHuBot](https://t.me/ParsehuBot)
|
|
66
|
+
|
|
67
|
+
## 🌐 支持平台
|
|
68
|
+
|
|
69
|
+
| 平台 | 视频 | 图文 | 其他 |
|
|
70
|
+
|:----------------|:--:|:--:|:------|
|
|
71
|
+
| **Twitter / X** | ✅ | ✅ | |
|
|
72
|
+
| **Instagram** | ✅ | ✅ | |
|
|
73
|
+
| **YouTube** | ✅ | | 🎵 音乐 |
|
|
74
|
+
| **Facebook** | ✅ | | |
|
|
75
|
+
| **Threads** | ✅ | ✅ | |
|
|
76
|
+
| **Bilibili** | ✅ | | 📝 动态 |
|
|
77
|
+
| **抖音** | ✅ | ✅ | |
|
|
78
|
+
| **TikTok** | ✅ | ✅ | |
|
|
79
|
+
| **微博** | ✅ | ✅ | |
|
|
80
|
+
| **小红书** | ✅ | ✅ | |
|
|
81
|
+
| **贴吧** | ✅ | ✅ | |
|
|
82
|
+
| **微信公众号** | | ✅ | |
|
|
83
|
+
| **快手** | ✅ | | |
|
|
84
|
+
| **酷安** | | ✅ | |
|
|
85
|
+
| **皮皮虾** | ✅ | ✅ | |
|
|
86
|
+
| **最右** | ✅ | ✅ | |
|
|
87
|
+
| **小黑盒** | ✅ | ✅ | |
|
|
88
|
+
|
|
89
|
+
> 可通过 `ParseHub().get_platforms()` 获取当前版本实际注册的平台列表。
|
|
90
|
+
|
|
91
|
+
## 📦 安装
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# uv (推荐)
|
|
95
|
+
uv add parsehub
|
|
96
|
+
|
|
97
|
+
# pip
|
|
98
|
+
pip install parsehub
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
> 要求 Python ≥ 3.12
|
|
102
|
+
|
|
103
|
+
## 🚀 快速开始
|
|
104
|
+
|
|
105
|
+
### 同步解析
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from parsehub import ParseHub
|
|
109
|
+
|
|
110
|
+
ph = ParseHub()
|
|
111
|
+
result = ph.parse_sync("https://www.xiaoheihe.cn/app/bbs/link/174972336")
|
|
112
|
+
|
|
113
|
+
print(result.title)
|
|
114
|
+
print(result.raw_url)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### 异步解析
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
import asyncio
|
|
121
|
+
from parsehub import ParseHub
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
async def main():
|
|
125
|
+
ph = ParseHub()
|
|
126
|
+
result = await ph.parse("https://tieba.baidu.com/p/9939510114")
|
|
127
|
+
print(result)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
asyncio.run(main())
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### 下载媒体
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
from parsehub import ParseHub
|
|
137
|
+
|
|
138
|
+
ph = ParseHub()
|
|
139
|
+
result = ph.download_sync(
|
|
140
|
+
"https://www.xiaoheihe.cn/app/bbs/link/174972336",
|
|
141
|
+
path="./downloads",
|
|
142
|
+
save_metadata=True,
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
print(result.output_dir)
|
|
146
|
+
print(result.media)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
需要 Cookie 登录或解析代理时,可以直接在下载时传入解析参数:
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
from parsehub import ParseHub
|
|
153
|
+
|
|
154
|
+
ph = ParseHub()
|
|
155
|
+
downloaded = ph.download_sync(
|
|
156
|
+
"https://example.com",
|
|
157
|
+
path="./downloads",
|
|
158
|
+
parse_cookie="key1=value1; key2=value2",
|
|
159
|
+
parse_proxy="http://127.0.0.1:7890",
|
|
160
|
+
save_metadata=True,
|
|
161
|
+
)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## 🧩 API 速览
|
|
165
|
+
|
|
166
|
+
### 解析
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
await ph.parse(url, proxy=None, cookie=None)
|
|
170
|
+
ph.parse_sync(url, proxy=None, cookie=None)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
- `url`:分享文案或分享链接,支持自动提取文本中的第一个链接
|
|
174
|
+
- `proxy`:解析阶段使用的代理
|
|
175
|
+
- `cookie`:解析阶段使用的 Cookie,支持字符串、JSON 字符串或字典
|
|
176
|
+
|
|
177
|
+
### 下载
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
await ph.download(
|
|
181
|
+
url,
|
|
182
|
+
path=None,
|
|
183
|
+
callback=None,
|
|
184
|
+
callback_args=(),
|
|
185
|
+
callback_kwargs=None,
|
|
186
|
+
proxy=None,
|
|
187
|
+
parse_proxy=None,
|
|
188
|
+
parse_cookie=None,
|
|
189
|
+
save_metadata=False,
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
ph.download_sync(
|
|
193
|
+
url,
|
|
194
|
+
path=None,
|
|
195
|
+
callback=None,
|
|
196
|
+
callback_args=(),
|
|
197
|
+
callback_kwargs=None,
|
|
198
|
+
proxy=None,
|
|
199
|
+
parse_proxy=None,
|
|
200
|
+
parse_cookie=None,
|
|
201
|
+
save_metadata=False,
|
|
202
|
+
)
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
- `path`:下载保存目录,默认使用 `GlobalConfig.default_save_dir`
|
|
206
|
+
- `proxy`:下载媒体时使用的代理
|
|
207
|
+
- `parse_proxy` / `parse_cookie`:下载前解析链接时使用的代理和 Cookie
|
|
208
|
+
- `save_metadata`:是否在输出目录保存 `metadata.json`
|
|
209
|
+
|
|
210
|
+
### 工具方法
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
ph.get_platform(url)
|
|
214
|
+
ph.get_platforms()
|
|
215
|
+
await ph.get_raw_url(url, proxy=None, clean_all=True)
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
- `get_platform()`:返回匹配到的平台枚举,未匹配时返回 `None`
|
|
219
|
+
- `get_platforms()`:返回所有已注册平台的 `id`、名称和支持类型
|
|
220
|
+
- `get_raw_url()`:获取清理后的原始链接
|
|
221
|
+
|
|
222
|
+
### 解析结果
|
|
223
|
+
|
|
224
|
+
- `result.platform`:平台枚举
|
|
225
|
+
- `result.type`:内容类型,如 `video`、`image`、`multimedia`、`richtext`
|
|
226
|
+
- `result.title`:标题
|
|
227
|
+
- `result.content`:纯文本正文
|
|
228
|
+
- `result.raw_url`:清理后的原始链接
|
|
229
|
+
- `result.media`:媒体引用或媒体引用列表
|
|
230
|
+
- `result.to_dict()`:转为可序列化字典
|
|
231
|
+
- `result.download()` / `result.download_sync()`:下载当前解析结果中的媒体
|
|
232
|
+
|
|
233
|
+
## 🔑 高级用法
|
|
234
|
+
|
|
235
|
+
### 分享文案与平台识别
|
|
236
|
+
|
|
237
|
+
`url` 参数可以直接传分享文案,ParseHub 会自动提取其中的第一个链接:
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
from parsehub import ParseHub
|
|
241
|
+
|
|
242
|
+
ph = ParseHub()
|
|
243
|
+
text = "复制这条分享 https://tieba.baidu.com/p/9939510114 后打开"
|
|
244
|
+
|
|
245
|
+
print(ph.get_platform(text))
|
|
246
|
+
print(ph.parse_sync(text).raw_url)
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Cookie 登录与代理
|
|
250
|
+
|
|
251
|
+
需要登录态的平台可传 Cookie;解析入口使用 `cookie` / `proxy`,下载入口使用 `parse_cookie` / `parse_proxy` 作为解析阶段参数。
|
|
252
|
+
|
|
253
|
+
```python
|
|
254
|
+
from parsehub import ParseHub
|
|
255
|
+
|
|
256
|
+
ph = ParseHub()
|
|
257
|
+
result = ph.parse_sync(
|
|
258
|
+
"https://example.com",
|
|
259
|
+
cookie="key1=value1; key2=value2",
|
|
260
|
+
proxy="http://127.0.0.1:7890",
|
|
261
|
+
)
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Cookie 支持多种格式:
|
|
265
|
+
|
|
266
|
+
```python
|
|
267
|
+
from parsehub import ParseHub
|
|
268
|
+
|
|
269
|
+
ph = ParseHub()
|
|
270
|
+
|
|
271
|
+
# Cookie header 字符串
|
|
272
|
+
ph.parse_sync("https://example.com", cookie="key1=value1; key2=value2")
|
|
273
|
+
|
|
274
|
+
# JSON 字符串
|
|
275
|
+
ph.parse_sync("https://example.com", cookie='{"key1": "value1", "key2": "value2"}')
|
|
276
|
+
|
|
277
|
+
# 字典
|
|
278
|
+
ph.parse_sync("https://example.com", cookie={"key1": "value1", "key2": "value2"})
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
当前支持 Cookie 的平台包括:
|
|
282
|
+
|
|
283
|
+
- `Twitter / X`
|
|
284
|
+
- `Instagram`
|
|
285
|
+
- `YouTube`
|
|
286
|
+
- `Bilibili`
|
|
287
|
+
- `抖音`
|
|
288
|
+
- `TikTok`
|
|
289
|
+
- `快手`
|
|
290
|
+
|
|
291
|
+
### 下载进度回调
|
|
292
|
+
|
|
293
|
+
```python
|
|
294
|
+
from parsehub import ParseHub
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
class ProgressTracker:
|
|
298
|
+
async def __call__(self, current: int, total: int, unit: str, *args, task_name: str = "", **kwargs):
|
|
299
|
+
print(f"[{task_name}] {current}/{total} ({unit})")
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
result = ParseHub().download_sync(
|
|
303
|
+
"https://example.com",
|
|
304
|
+
path="./downloads",
|
|
305
|
+
callback=ProgressTracker(),
|
|
306
|
+
callback_args=("extra_arg",),
|
|
307
|
+
callback_kwargs={"task_name": "demo"},
|
|
308
|
+
)
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
`unit` 可能为:
|
|
312
|
+
|
|
313
|
+
- `bytes`:单文件下载时的字节进度
|
|
314
|
+
- `count`:多文件下载时的文件数量进度
|
|
315
|
+
|
|
316
|
+
### 保存 metadata.json
|
|
317
|
+
|
|
318
|
+
```python
|
|
319
|
+
from parsehub import ParseHub
|
|
320
|
+
|
|
321
|
+
result = ParseHub().download_sync(
|
|
322
|
+
"https://example.com",
|
|
323
|
+
path="./downloads",
|
|
324
|
+
save_metadata=True,
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
print(result.output_dir / "metadata.json")
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### 全局配置
|
|
331
|
+
|
|
332
|
+
```python
|
|
333
|
+
from pathlib import Path
|
|
334
|
+
from parsehub.config import GlobalConfig
|
|
335
|
+
|
|
336
|
+
GlobalConfig.default_save_dir = Path("./downloads")
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
### 错误处理
|
|
340
|
+
|
|
341
|
+
```python
|
|
342
|
+
from parsehub import ParseHub
|
|
343
|
+
from parsehub.errors import ParseError, UnknownPlatform
|
|
344
|
+
|
|
345
|
+
try:
|
|
346
|
+
result = ParseHub().parse_sync("https://example.com")
|
|
347
|
+
except UnknownPlatform:
|
|
348
|
+
print("暂不支持该平台")
|
|
349
|
+
except ParseError as exc:
|
|
350
|
+
print(f"解析失败: {exc}")
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
## 🤝 参考项目
|
|
354
|
+
|
|
355
|
+
- [Evil0ctal/Douyin_TikTok_Download_API](https://github.com/Evil0ctal/Douyin_TikTok_Download_API)
|
|
356
|
+
- [yt-dlp/yt-dlp](https://github.com/yt-dlp/yt-dlp)
|
|
357
|
+
- [instaloader/instaloader](https://github.com/instaloader/instaloader)
|
|
358
|
+
- [SocialSisterYi/bilibili-API-collect](https://github.com/SocialSisterYi/bilibili-API-collect)
|
|
359
|
+
- [Nemo2011/bilibili-api](https://github.com/Nemo2011/bilibili-api)
|
|
360
|
+
|
|
361
|
+
## 📜 开源协议
|
|
362
|
+
|
|
363
|
+
本项目基于 [MIT License](LICENSE) 开源。
|
|
364
|
+
|
|
365
|
+
---
|
|
366
|
+
|
|
367
|
+
<div align="center">
|
|
368
|
+
|
|
369
|
+
**如果这个项目对你有帮助,欢迎点个 ⭐ Star!**
|
|
370
|
+
|
|
371
|
+
</div>
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# 🔗 ParseHub
|
|
4
|
+
|
|
5
|
+
**社交媒体聚合解析器**
|
|
6
|
+
|
|
7
|
+
[](https://pypi.org/project/parsehub/)
|
|
8
|
+
[](https://www.python.org/)
|
|
9
|
+
[](LICENSE)
|
|
10
|
+
[](https://github.com/z-mio/parsehub)
|
|
11
|
+
|
|
12
|
+
轻量、异步、开箱即用的社交媒体解析与媒体下载库,支持 17+ 平台。
|
|
13
|
+
|
|
14
|
+
[支持平台](#-支持平台) · [安装](#-安装) · [快速开始](#-快速开始) · [API](#-api-速览) · [高级用法](#-高级用法) · [TG Bot](https://github.com/z-mio/parse_hub_bot)
|
|
15
|
+
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## ✨ 特性
|
|
21
|
+
|
|
22
|
+
- 🌍 **广泛的平台支持** — 覆盖国内外 17+ 主流社交媒体平台
|
|
23
|
+
- 🧹 **链接清理** — 自动提取分享文案中的链接,并清除可移除的跟踪参数
|
|
24
|
+
- 🎬 **多媒体解析** — 支持视频、图文、动图、实况照片和富文本文章
|
|
25
|
+
- 📦 **同步 / 异步 API** — 同时提供 `async/await` 与 `*_sync` 调用方式
|
|
26
|
+
- 🤖 **Telegram Bot** — 基于本项目的 Bot 已上线 → [@ParseHuBot](https://t.me/ParsehuBot)
|
|
27
|
+
|
|
28
|
+
## 🌐 支持平台
|
|
29
|
+
|
|
30
|
+
| 平台 | 视频 | 图文 | 其他 |
|
|
31
|
+
|:----------------|:--:|:--:|:------|
|
|
32
|
+
| **Twitter / X** | ✅ | ✅ | |
|
|
33
|
+
| **Instagram** | ✅ | ✅ | |
|
|
34
|
+
| **YouTube** | ✅ | | 🎵 音乐 |
|
|
35
|
+
| **Facebook** | ✅ | | |
|
|
36
|
+
| **Threads** | ✅ | ✅ | |
|
|
37
|
+
| **Bilibili** | ✅ | | 📝 动态 |
|
|
38
|
+
| **抖音** | ✅ | ✅ | |
|
|
39
|
+
| **TikTok** | ✅ | ✅ | |
|
|
40
|
+
| **微博** | ✅ | ✅ | |
|
|
41
|
+
| **小红书** | ✅ | ✅ | |
|
|
42
|
+
| **贴吧** | ✅ | ✅ | |
|
|
43
|
+
| **微信公众号** | | ✅ | |
|
|
44
|
+
| **快手** | ✅ | | |
|
|
45
|
+
| **酷安** | | ✅ | |
|
|
46
|
+
| **皮皮虾** | ✅ | ✅ | |
|
|
47
|
+
| **最右** | ✅ | ✅ | |
|
|
48
|
+
| **小黑盒** | ✅ | ✅ | |
|
|
49
|
+
|
|
50
|
+
> 可通过 `ParseHub().get_platforms()` 获取当前版本实际注册的平台列表。
|
|
51
|
+
|
|
52
|
+
## 📦 安装
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# uv (推荐)
|
|
56
|
+
uv add parsehub
|
|
57
|
+
|
|
58
|
+
# pip
|
|
59
|
+
pip install parsehub
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
> 要求 Python ≥ 3.12
|
|
63
|
+
|
|
64
|
+
## 🚀 快速开始
|
|
65
|
+
|
|
66
|
+
### 同步解析
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from parsehub import ParseHub
|
|
70
|
+
|
|
71
|
+
ph = ParseHub()
|
|
72
|
+
result = ph.parse_sync("https://www.xiaoheihe.cn/app/bbs/link/174972336")
|
|
73
|
+
|
|
74
|
+
print(result.title)
|
|
75
|
+
print(result.raw_url)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 异步解析
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
import asyncio
|
|
82
|
+
from parsehub import ParseHub
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
async def main():
|
|
86
|
+
ph = ParseHub()
|
|
87
|
+
result = await ph.parse("https://tieba.baidu.com/p/9939510114")
|
|
88
|
+
print(result)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
asyncio.run(main())
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 下载媒体
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from parsehub import ParseHub
|
|
98
|
+
|
|
99
|
+
ph = ParseHub()
|
|
100
|
+
result = ph.download_sync(
|
|
101
|
+
"https://www.xiaoheihe.cn/app/bbs/link/174972336",
|
|
102
|
+
path="./downloads",
|
|
103
|
+
save_metadata=True,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
print(result.output_dir)
|
|
107
|
+
print(result.media)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
需要 Cookie 登录或解析代理时,可以直接在下载时传入解析参数:
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from parsehub import ParseHub
|
|
114
|
+
|
|
115
|
+
ph = ParseHub()
|
|
116
|
+
downloaded = ph.download_sync(
|
|
117
|
+
"https://example.com",
|
|
118
|
+
path="./downloads",
|
|
119
|
+
parse_cookie="key1=value1; key2=value2",
|
|
120
|
+
parse_proxy="http://127.0.0.1:7890",
|
|
121
|
+
save_metadata=True,
|
|
122
|
+
)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## 🧩 API 速览
|
|
126
|
+
|
|
127
|
+
### 解析
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
await ph.parse(url, proxy=None, cookie=None)
|
|
131
|
+
ph.parse_sync(url, proxy=None, cookie=None)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
- `url`:分享文案或分享链接,支持自动提取文本中的第一个链接
|
|
135
|
+
- `proxy`:解析阶段使用的代理
|
|
136
|
+
- `cookie`:解析阶段使用的 Cookie,支持字符串、JSON 字符串或字典
|
|
137
|
+
|
|
138
|
+
### 下载
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
await ph.download(
|
|
142
|
+
url,
|
|
143
|
+
path=None,
|
|
144
|
+
callback=None,
|
|
145
|
+
callback_args=(),
|
|
146
|
+
callback_kwargs=None,
|
|
147
|
+
proxy=None,
|
|
148
|
+
parse_proxy=None,
|
|
149
|
+
parse_cookie=None,
|
|
150
|
+
save_metadata=False,
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
ph.download_sync(
|
|
154
|
+
url,
|
|
155
|
+
path=None,
|
|
156
|
+
callback=None,
|
|
157
|
+
callback_args=(),
|
|
158
|
+
callback_kwargs=None,
|
|
159
|
+
proxy=None,
|
|
160
|
+
parse_proxy=None,
|
|
161
|
+
parse_cookie=None,
|
|
162
|
+
save_metadata=False,
|
|
163
|
+
)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
- `path`:下载保存目录,默认使用 `GlobalConfig.default_save_dir`
|
|
167
|
+
- `proxy`:下载媒体时使用的代理
|
|
168
|
+
- `parse_proxy` / `parse_cookie`:下载前解析链接时使用的代理和 Cookie
|
|
169
|
+
- `save_metadata`:是否在输出目录保存 `metadata.json`
|
|
170
|
+
|
|
171
|
+
### 工具方法
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
ph.get_platform(url)
|
|
175
|
+
ph.get_platforms()
|
|
176
|
+
await ph.get_raw_url(url, proxy=None, clean_all=True)
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
- `get_platform()`:返回匹配到的平台枚举,未匹配时返回 `None`
|
|
180
|
+
- `get_platforms()`:返回所有已注册平台的 `id`、名称和支持类型
|
|
181
|
+
- `get_raw_url()`:获取清理后的原始链接
|
|
182
|
+
|
|
183
|
+
### 解析结果
|
|
184
|
+
|
|
185
|
+
- `result.platform`:平台枚举
|
|
186
|
+
- `result.type`:内容类型,如 `video`、`image`、`multimedia`、`richtext`
|
|
187
|
+
- `result.title`:标题
|
|
188
|
+
- `result.content`:纯文本正文
|
|
189
|
+
- `result.raw_url`:清理后的原始链接
|
|
190
|
+
- `result.media`:媒体引用或媒体引用列表
|
|
191
|
+
- `result.to_dict()`:转为可序列化字典
|
|
192
|
+
- `result.download()` / `result.download_sync()`:下载当前解析结果中的媒体
|
|
193
|
+
|
|
194
|
+
## 🔑 高级用法
|
|
195
|
+
|
|
196
|
+
### 分享文案与平台识别
|
|
197
|
+
|
|
198
|
+
`url` 参数可以直接传分享文案,ParseHub 会自动提取其中的第一个链接:
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
from parsehub import ParseHub
|
|
202
|
+
|
|
203
|
+
ph = ParseHub()
|
|
204
|
+
text = "复制这条分享 https://tieba.baidu.com/p/9939510114 后打开"
|
|
205
|
+
|
|
206
|
+
print(ph.get_platform(text))
|
|
207
|
+
print(ph.parse_sync(text).raw_url)
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Cookie 登录与代理
|
|
211
|
+
|
|
212
|
+
需要登录态的平台可传 Cookie;解析入口使用 `cookie` / `proxy`,下载入口使用 `parse_cookie` / `parse_proxy` 作为解析阶段参数。
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
from parsehub import ParseHub
|
|
216
|
+
|
|
217
|
+
ph = ParseHub()
|
|
218
|
+
result = ph.parse_sync(
|
|
219
|
+
"https://example.com",
|
|
220
|
+
cookie="key1=value1; key2=value2",
|
|
221
|
+
proxy="http://127.0.0.1:7890",
|
|
222
|
+
)
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Cookie 支持多种格式:
|
|
226
|
+
|
|
227
|
+
```python
|
|
228
|
+
from parsehub import ParseHub
|
|
229
|
+
|
|
230
|
+
ph = ParseHub()
|
|
231
|
+
|
|
232
|
+
# Cookie header 字符串
|
|
233
|
+
ph.parse_sync("https://example.com", cookie="key1=value1; key2=value2")
|
|
234
|
+
|
|
235
|
+
# JSON 字符串
|
|
236
|
+
ph.parse_sync("https://example.com", cookie='{"key1": "value1", "key2": "value2"}')
|
|
237
|
+
|
|
238
|
+
# 字典
|
|
239
|
+
ph.parse_sync("https://example.com", cookie={"key1": "value1", "key2": "value2"})
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
当前支持 Cookie 的平台包括:
|
|
243
|
+
|
|
244
|
+
- `Twitter / X`
|
|
245
|
+
- `Instagram`
|
|
246
|
+
- `YouTube`
|
|
247
|
+
- `Bilibili`
|
|
248
|
+
- `抖音`
|
|
249
|
+
- `TikTok`
|
|
250
|
+
- `快手`
|
|
251
|
+
|
|
252
|
+
### 下载进度回调
|
|
253
|
+
|
|
254
|
+
```python
|
|
255
|
+
from parsehub import ParseHub
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
class ProgressTracker:
|
|
259
|
+
async def __call__(self, current: int, total: int, unit: str, *args, task_name: str = "", **kwargs):
|
|
260
|
+
print(f"[{task_name}] {current}/{total} ({unit})")
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
result = ParseHub().download_sync(
|
|
264
|
+
"https://example.com",
|
|
265
|
+
path="./downloads",
|
|
266
|
+
callback=ProgressTracker(),
|
|
267
|
+
callback_args=("extra_arg",),
|
|
268
|
+
callback_kwargs={"task_name": "demo"},
|
|
269
|
+
)
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
`unit` 可能为:
|
|
273
|
+
|
|
274
|
+
- `bytes`:单文件下载时的字节进度
|
|
275
|
+
- `count`:多文件下载时的文件数量进度
|
|
276
|
+
|
|
277
|
+
### 保存 metadata.json
|
|
278
|
+
|
|
279
|
+
```python
|
|
280
|
+
from parsehub import ParseHub
|
|
281
|
+
|
|
282
|
+
result = ParseHub().download_sync(
|
|
283
|
+
"https://example.com",
|
|
284
|
+
path="./downloads",
|
|
285
|
+
save_metadata=True,
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
print(result.output_dir / "metadata.json")
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### 全局配置
|
|
292
|
+
|
|
293
|
+
```python
|
|
294
|
+
from pathlib import Path
|
|
295
|
+
from parsehub.config import GlobalConfig
|
|
296
|
+
|
|
297
|
+
GlobalConfig.default_save_dir = Path("./downloads")
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### 错误处理
|
|
301
|
+
|
|
302
|
+
```python
|
|
303
|
+
from parsehub import ParseHub
|
|
304
|
+
from parsehub.errors import ParseError, UnknownPlatform
|
|
305
|
+
|
|
306
|
+
try:
|
|
307
|
+
result = ParseHub().parse_sync("https://example.com")
|
|
308
|
+
except UnknownPlatform:
|
|
309
|
+
print("暂不支持该平台")
|
|
310
|
+
except ParseError as exc:
|
|
311
|
+
print(f"解析失败: {exc}")
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
## 🤝 参考项目
|
|
315
|
+
|
|
316
|
+
- [Evil0ctal/Douyin_TikTok_Download_API](https://github.com/Evil0ctal/Douyin_TikTok_Download_API)
|
|
317
|
+
- [yt-dlp/yt-dlp](https://github.com/yt-dlp/yt-dlp)
|
|
318
|
+
- [instaloader/instaloader](https://github.com/instaloader/instaloader)
|
|
319
|
+
- [SocialSisterYi/bilibili-API-collect](https://github.com/SocialSisterYi/bilibili-API-collect)
|
|
320
|
+
- [Nemo2011/bilibili-api](https://github.com/Nemo2011/bilibili-api)
|
|
321
|
+
|
|
322
|
+
## 📜 开源协议
|
|
323
|
+
|
|
324
|
+
本项目基于 [MIT License](LICENSE) 开源。
|
|
325
|
+
|
|
326
|
+
---
|
|
327
|
+
|
|
328
|
+
<div align="center">
|
|
329
|
+
|
|
330
|
+
**如果这个项目对你有帮助,欢迎点个 ⭐ Star!**
|
|
331
|
+
|
|
332
|
+
</div>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "parsehub"
|
|
3
|
-
version = "2.0.
|
|
3
|
+
version = "2.0.18"
|
|
4
4
|
description = "轻量、异步、开箱即用的社交媒体聚合解析库"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.12.0"
|
|
@@ -40,6 +40,10 @@ dependencies = [
|
|
|
40
40
|
"gmssl>=3.2.2",
|
|
41
41
|
]
|
|
42
42
|
|
|
43
|
+
[project.scripts]
|
|
44
|
+
parsehub = "parsehub.cli:main"
|
|
45
|
+
ph = "parsehub.cli:main"
|
|
46
|
+
|
|
43
47
|
[dependency-groups]
|
|
44
48
|
dev = [
|
|
45
49
|
"ruff>=0.14.14",
|