parsehub 2.4.3__tar.gz → 2.4.4__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.4.3/src/parsehub.egg-info → parsehub-2.4.4}/PKG-INFO +1 -1
- {parsehub-2.4.3 → parsehub-2.4.4}/pyproject.toml +1 -1
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/__init__.py +3 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/errors.py +18 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/base/ytdlp.py +4 -2
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/bangumi.py +1 -1
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/bilibili.py +3 -2
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/coolapk.py +2 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/douban.py +4 -2
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/douyin.py +6 -4
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/instagram.py +5 -3
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/jandan.py +1 -1
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/kuaishou.py +8 -4
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/medium.py +1 -1
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/pipix.py +3 -1
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/tieba.py +15 -4
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/tiktok.py +7 -6
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/toutiao.py +1 -1
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/weixin.py +9 -2
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/wxchannels.py +3 -3
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/xhs.py +6 -4
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/xiaoheihe.py +4 -3
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/zhihu.py +2 -1
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/provider_api/bangumi.py +2 -1
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/provider_api/bilibili.py +5 -5
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/provider_api/coolapk.py +5 -3
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/provider_api/douban.py +3 -1
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/provider_api/douyin.py +15 -15
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/provider_api/instagram.py +10 -10
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/provider_api/jandan.py +1 -1
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/provider_api/kuaishou.py +2 -4
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/provider_api/medium.py +2 -2
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/provider_api/pipix.py +3 -2
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/provider_api/threads.py +4 -3
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/provider_api/tieba.py +3 -1
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/provider_api/tiktok.py +7 -7
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/provider_api/toutiao.py +2 -2
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/provider_api/twitter.py +6 -4
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/provider_api/weibo.py +3 -1
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/provider_api/weixin.py +4 -3
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/provider_api/wxchannels.py +8 -8
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/provider_api/xhs.py +4 -4
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/provider_api/xiaoheihe.py +5 -3
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/provider_api/zhihu.py +13 -8
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/provider_api/zuiyou.py +3 -1
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/types/__init__.py +6 -0
- {parsehub-2.4.3 → parsehub-2.4.4/src/parsehub.egg-info}/PKG-INFO +1 -1
- {parsehub-2.4.3 → parsehub-2.4.4}/LICENSE +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/README.md +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/setup.cfg +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/__init__.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/cli.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/cli_config.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/config/__init__.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/config/config.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/__init__.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/base/__init__.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/base/base.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/__init__.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/facebook.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/snapchat.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/threads.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/twitter.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/weibo.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/youtube.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/parsers/parser/zuiyou.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/provider_api/__init__.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/types/callback.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/types/media_file.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/types/media_ref.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/types/platform.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/types/post.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/types/result.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/utils/downloader.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/utils/fallback.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/utils/helpers.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub/utils/media_info.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub.egg-info/SOURCES.txt +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub.egg-info/dependency_links.txt +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub.egg-info/entry_points.txt +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub.egg-info/requires.txt +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/src/parsehub.egg-info/top_level.txt +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/test/test_cli.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/test/test_cli_config.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/test/test_core_offline.py +0 -0
- {parsehub-2.4.3 → parsehub-2.4.4}/test/test_downloader.py +0 -0
|
@@ -6,7 +6,10 @@ from .errors import ContentUnavailableError as ContentUnavailableError
|
|
|
6
6
|
from .errors import ContentUnavailableFallbackError as ContentUnavailableFallbackError
|
|
7
7
|
from .errors import FallbackAttempt as FallbackAttempt
|
|
8
8
|
from .errors import FallbackError as FallbackError
|
|
9
|
+
from .errors import InvalidUrlError as InvalidUrlError
|
|
10
|
+
from .errors import LoginRequiredError as LoginRequiredError
|
|
9
11
|
from .errors import ParseError, UnknownPlatform
|
|
12
|
+
from .errors import UnsupportedError as UnsupportedError
|
|
10
13
|
from .parsers.base import BaseParser
|
|
11
14
|
from .types import Platform
|
|
12
15
|
from .types.callback import ProgressCallback
|
|
@@ -33,6 +33,24 @@ class ContentUnavailableError(ParseError):
|
|
|
33
33
|
MSG = __doc__
|
|
34
34
|
|
|
35
35
|
|
|
36
|
+
class UnsupportedError(ContentUnavailableError):
|
|
37
|
+
"""不支持"""
|
|
38
|
+
|
|
39
|
+
MSG = __doc__
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class InvalidUrlError(ContentUnavailableError):
|
|
43
|
+
"""链接无效"""
|
|
44
|
+
|
|
45
|
+
MSG = __doc__
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class LoginRequiredError(ContentUnavailableError):
|
|
49
|
+
"""需要登录"""
|
|
50
|
+
|
|
51
|
+
MSG = __doc__
|
|
52
|
+
|
|
53
|
+
|
|
36
54
|
@dataclass(frozen=True)
|
|
37
55
|
class FallbackAttempt:
|
|
38
56
|
name: str
|
|
@@ -14,10 +14,12 @@ from typing import Any, cast
|
|
|
14
14
|
from loguru import logger
|
|
15
15
|
|
|
16
16
|
from ...types import (
|
|
17
|
+
ContentUnavailableError,
|
|
17
18
|
DownloadError,
|
|
18
19
|
DownloadResult,
|
|
19
20
|
ParseError,
|
|
20
21
|
ProgressCallback,
|
|
22
|
+
UnsupportedError,
|
|
21
23
|
VideoFile,
|
|
22
24
|
VideoParseResult,
|
|
23
25
|
VideoRef,
|
|
@@ -400,12 +402,12 @@ class YtParser(BaseParser, register=False):
|
|
|
400
402
|
"is_upcoming",
|
|
401
403
|
"was_live",
|
|
402
404
|
):
|
|
403
|
-
raise
|
|
405
|
+
raise UnsupportedError("直播")
|
|
404
406
|
|
|
405
407
|
if dl.get("_type") == "playlist":
|
|
406
408
|
entries = dl.get("entries") or []
|
|
407
409
|
if not entries:
|
|
408
|
-
raise
|
|
410
|
+
raise ContentUnavailableError("解析视频信息失败: playlist entries is empty")
|
|
409
411
|
dl = entries[0]
|
|
410
412
|
url = dl.get("webpage_url") or url
|
|
411
413
|
title = dl["title"]
|
|
@@ -15,7 +15,7 @@ class BangumiParser(BaseParser):
|
|
|
15
15
|
try:
|
|
16
16
|
post = await Bangumi(proxy=self.proxy).parse(raw_url)
|
|
17
17
|
except BangumiError as e:
|
|
18
|
-
raise ParseError(
|
|
18
|
+
raise ParseError(e.msg or "未知错误") from e
|
|
19
19
|
|
|
20
20
|
return RichTextParseResult(
|
|
21
21
|
title=post.title,
|
|
@@ -17,6 +17,7 @@ from ...types import (
|
|
|
17
17
|
ParseError,
|
|
18
18
|
Platform,
|
|
19
19
|
ProgressCallback,
|
|
20
|
+
UnsupportedError,
|
|
20
21
|
VideoParseResult,
|
|
21
22
|
VideoRef,
|
|
22
23
|
)
|
|
@@ -50,9 +51,9 @@ class BiliParse(BaseParser):
|
|
|
50
51
|
return await self.ytp_parse(raw_url)
|
|
51
52
|
parsed = urlparse(raw_url)
|
|
52
53
|
if parsed.hostname == "mall.bilibili.com":
|
|
53
|
-
raise
|
|
54
|
+
raise UnsupportedError("解析商品")
|
|
54
55
|
if parsed.path.startswith("/bangumi/"):
|
|
55
|
-
raise
|
|
56
|
+
raise UnsupportedError("解析番剧和影视")
|
|
56
57
|
if BiliAPI.get_music_id(raw_url):
|
|
57
58
|
return await self.bili_music_parse(raw_url)
|
|
58
59
|
if await self.is_dynamic(raw_url):
|
|
@@ -29,6 +29,8 @@ class CoolapkParser(BaseParser):
|
|
|
29
29
|
) -> Union["CoolapkImageParseResult", "CoolapkRichTextParseResult", "CoolapkMultimediaParseResult"]:
|
|
30
30
|
try:
|
|
31
31
|
coolapk = await Coolapk.parse(raw_url, proxy=self.proxy)
|
|
32
|
+
except ParseError:
|
|
33
|
+
raise
|
|
32
34
|
except Exception as e:
|
|
33
35
|
raise ParseError(str(e)) from e
|
|
34
36
|
media = [AniRef(url=i) if ".gif" in i else ImageRef(url=i) for i in coolapk.imgs or []]
|
|
@@ -28,10 +28,12 @@ class DoubanParser(BaseParser):
|
|
|
28
28
|
async def _do_parse(self, raw_url: str) -> Union["DoubanRichTextParseResult", "DoubanImageParseResult"]:
|
|
29
29
|
try:
|
|
30
30
|
topic = await Douban(proxy=self.proxy, cookie=self.cookie.get_value()).parse(raw_url)
|
|
31
|
+
except ParseError:
|
|
32
|
+
raise
|
|
31
33
|
except DoubanError as e:
|
|
32
|
-
raise ParseError(
|
|
34
|
+
raise ParseError(e.msg or "未知错误") from e
|
|
33
35
|
except Exception as e:
|
|
34
|
-
raise ParseError("
|
|
36
|
+
raise ParseError("未知错误") from e
|
|
35
37
|
|
|
36
38
|
photos = [self.to_media_ref(p) for p in topic.photos]
|
|
37
39
|
|
|
@@ -62,7 +62,7 @@ class DouyinParser(BaseParser):
|
|
|
62
62
|
def _build_video_result(result: "DouyinApiResult") -> VideoParseResult:
|
|
63
63
|
"""构建视频解析结果"""
|
|
64
64
|
if result.video is None:
|
|
65
|
-
raise
|
|
65
|
+
raise ContentUnavailableError("未获取到视频")
|
|
66
66
|
return DouyinVideoParseResult(
|
|
67
67
|
title=result.desc,
|
|
68
68
|
video=result.video,
|
|
@@ -187,8 +187,10 @@ class DouyinApiResult:
|
|
|
187
187
|
filter_detail = json_dict.get("filter_detail") or {}
|
|
188
188
|
if reason := filter_detail.get("filter_reason"):
|
|
189
189
|
detail_msg = filter_detail.get("detail_msg") or filter_detail.get("notice") or ""
|
|
190
|
-
|
|
191
|
-
|
|
190
|
+
if reason == "story_25_filter": # 移动端接口可以拿到, 需落到下一个 fallback stage
|
|
191
|
+
raise ParseError(f"{reason} {detail_msg}".strip())
|
|
192
|
+
raise ContentUnavailableError(f"{reason} {detail_msg}".strip())
|
|
193
|
+
raise ParseError("未获取到作品详情")
|
|
192
194
|
|
|
193
195
|
desc = data.get("desc", "")
|
|
194
196
|
|
|
@@ -277,7 +279,7 @@ class DouyinApiResult:
|
|
|
277
279
|
"""解析视频"""
|
|
278
280
|
video_data = data.get("video")
|
|
279
281
|
if not video_data:
|
|
280
|
-
raise ParseError("
|
|
282
|
+
raise ParseError("未获取到视频数据")
|
|
281
283
|
|
|
282
284
|
video_info = parse_video_info(video_data)
|
|
283
285
|
|
|
@@ -13,9 +13,11 @@ from ...types import (
|
|
|
13
13
|
ContentUnavailableError,
|
|
14
14
|
ImageParseResult,
|
|
15
15
|
ImageRef,
|
|
16
|
+
InvalidUrlError,
|
|
16
17
|
MultimediaParseResult,
|
|
17
18
|
ParseError,
|
|
18
19
|
Platform,
|
|
20
|
+
UnsupportedError,
|
|
19
21
|
VideoParseResult,
|
|
20
22
|
VideoRef,
|
|
21
23
|
)
|
|
@@ -33,7 +35,7 @@ class InstagramParser(BaseParser):
|
|
|
33
35
|
async def _do_parse(self, raw_url: str) -> VideoParseResult | ImageParseResult | MultimediaParseResult:
|
|
34
36
|
shortcode = self.get_short_code(raw_url)
|
|
35
37
|
if not shortcode:
|
|
36
|
-
raise
|
|
38
|
+
raise InvalidUrlError("无法提取帖子 ID")
|
|
37
39
|
|
|
38
40
|
post = await self._parse(shortcode)
|
|
39
41
|
|
|
@@ -80,7 +82,7 @@ class InstagramParser(BaseParser):
|
|
|
80
82
|
),
|
|
81
83
|
)
|
|
82
84
|
if not item.video_url:
|
|
83
|
-
raise
|
|
85
|
+
raise ContentUnavailableError("未获取到视频地址")
|
|
84
86
|
return VideoParseResult(
|
|
85
87
|
video=VideoRef(
|
|
86
88
|
url=item.video_url,
|
|
@@ -93,7 +95,7 @@ class InstagramParser(BaseParser):
|
|
|
93
95
|
content=post.caption,
|
|
94
96
|
)
|
|
95
97
|
case _:
|
|
96
|
-
raise
|
|
98
|
+
raise UnsupportedError("该类型")
|
|
97
99
|
|
|
98
100
|
async def _parse(self, shortcode: str) -> InstagramPost:
|
|
99
101
|
stages: list[FallbackStage[InstagramPost]] = [FallbackStage("匿名", lambda: self._fetch(shortcode))]
|
|
@@ -41,8 +41,12 @@ class KuaiShouParser(BaseParser):
|
|
|
41
41
|
ksp = await KuaishouParser.create(
|
|
42
42
|
raw_url, proxy=self.proxy, cookie=self.cookie.get_value() or COOKIE.get_value()
|
|
43
43
|
)
|
|
44
|
-
if ksp.page_type == "UNKNOWN"
|
|
45
|
-
|
|
44
|
+
if ksp.page_type == "UNKNOWN":
|
|
45
|
+
if ksp.error_result in (223, 20113):
|
|
46
|
+
raise ContentUnavailableError(f"{ksp.error_result} {ksp.error_msg}")
|
|
47
|
+
if "/short-video/" not in raw_url:
|
|
48
|
+
raise ParseError("未获取到页面数据")
|
|
49
|
+
# HTML 路由全挂时仍可能通过 API 拿到视频, 落到下方 fallback 兜底
|
|
46
50
|
if (
|
|
47
51
|
ksp.page_type == "VIDEO" or "/short-video/" in raw_url
|
|
48
52
|
): # 地区风控导致获取到的 page_type 可能为 ATLAS 但实际为视频
|
|
@@ -51,7 +55,7 @@ class KuaiShouParser(BaseParser):
|
|
|
51
55
|
content = ksp.get_title_content()
|
|
52
56
|
video = ksp.get_real_video_url()
|
|
53
57
|
if not video:
|
|
54
|
-
raise ParseError("
|
|
58
|
+
raise ParseError("未获取到视频")
|
|
55
59
|
cover = ksp.get_cover_photo_url()
|
|
56
60
|
|
|
57
61
|
return VideoParseResult(
|
|
@@ -94,7 +98,7 @@ class KuaiShouParser(BaseParser):
|
|
|
94
98
|
if cover:
|
|
95
99
|
return ImageParseResult(title=content, photo=[ImageRef(url=cover)])
|
|
96
100
|
|
|
97
|
-
raise
|
|
101
|
+
raise ContentUnavailableError("未获取到内容")
|
|
98
102
|
|
|
99
103
|
|
|
100
104
|
__all__ = ["KuaiShouParser"]
|
|
@@ -12,7 +12,7 @@ class MediumParser(BaseParser):
|
|
|
12
12
|
try:
|
|
13
13
|
post = await Medium(proxy=self.proxy).parse(raw_url)
|
|
14
14
|
except MediumError as e:
|
|
15
|
-
raise ParseError(
|
|
15
|
+
raise ParseError(str(e)) from e
|
|
16
16
|
|
|
17
17
|
return RichTextParseResult(
|
|
18
18
|
title=post.title,
|
|
@@ -14,8 +14,10 @@ class PipixParser(BaseParser):
|
|
|
14
14
|
async def _do_parse(self, raw_url: str) -> Union["ImageParseResult", "VideoParseResult"]:
|
|
15
15
|
try:
|
|
16
16
|
ppx = await Pipix(self.proxy).parse(raw_url)
|
|
17
|
+
except ParseError:
|
|
18
|
+
raise
|
|
17
19
|
except Exception as e:
|
|
18
|
-
raise ParseError(
|
|
20
|
+
raise ParseError(str(e)) from e
|
|
19
21
|
|
|
20
22
|
if ppx.video_url:
|
|
21
23
|
return VideoParseResult(
|
|
@@ -3,7 +3,16 @@ from typing import Union
|
|
|
3
3
|
import httpx
|
|
4
4
|
|
|
5
5
|
from ...provider_api.tieba import TieBa, TieBaError, TieBaPostType, TieBaVideo
|
|
6
|
-
from ...types import
|
|
6
|
+
from ...types import (
|
|
7
|
+
AniRef,
|
|
8
|
+
ContentUnavailableError,
|
|
9
|
+
ImageParseResult,
|
|
10
|
+
ImageRef,
|
|
11
|
+
ParseError,
|
|
12
|
+
Platform,
|
|
13
|
+
VideoParseResult,
|
|
14
|
+
VideoRef,
|
|
15
|
+
)
|
|
7
16
|
from ..base.base import BaseParser
|
|
8
17
|
|
|
9
18
|
|
|
@@ -15,15 +24,17 @@ class TieBaParser(BaseParser):
|
|
|
15
24
|
async def _do_parse(self, raw_url: str) -> Union["ImageParseResult", "VideoParseResult"]:
|
|
16
25
|
try:
|
|
17
26
|
tb = await TieBa(self.proxy).parse(raw_url)
|
|
27
|
+
except ParseError:
|
|
28
|
+
raise
|
|
18
29
|
except TieBaError as e:
|
|
19
|
-
raise ParseError(e.msg
|
|
30
|
+
raise ParseError(e.msg or "未知错误") from e
|
|
20
31
|
except Exception as e:
|
|
21
|
-
raise ParseError("
|
|
32
|
+
raise ParseError("未知错误") from e
|
|
22
33
|
|
|
23
34
|
match tb.type:
|
|
24
35
|
case TieBaPostType.VIDEO:
|
|
25
36
|
if not isinstance(tb.media, TieBaVideo):
|
|
26
|
-
raise
|
|
37
|
+
raise ContentUnavailableError("未获取到视频")
|
|
27
38
|
return VideoParseResult(
|
|
28
39
|
title=tb.title,
|
|
29
40
|
video=VideoRef(
|
|
@@ -6,6 +6,7 @@ from typing import Any, Self, Union
|
|
|
6
6
|
from ... import ProgressCallback
|
|
7
7
|
from ...provider_api.tiktok import TikTokWebCrawler
|
|
8
8
|
from ...types import (
|
|
9
|
+
ContentUnavailableError,
|
|
9
10
|
DownloadResult,
|
|
10
11
|
ImageParseResult,
|
|
11
12
|
ImageRef,
|
|
@@ -40,12 +41,12 @@ class TikTokParser(BaseParser):
|
|
|
40
41
|
except ParseError:
|
|
41
42
|
raise
|
|
42
43
|
except Exception as e:
|
|
43
|
-
raise ParseError(
|
|
44
|
+
raise ParseError(str(e)) from e
|
|
44
45
|
|
|
45
46
|
@staticmethod
|
|
46
47
|
def _build_video_result(result: "TikTokApiResult") -> VideoParseResult:
|
|
47
48
|
if result.video is None:
|
|
48
|
-
raise
|
|
49
|
+
raise ContentUnavailableError("未获取到视频")
|
|
49
50
|
return TikTokVideoParseResult(
|
|
50
51
|
title=result.desc,
|
|
51
52
|
video=result.video,
|
|
@@ -192,7 +193,7 @@ def parse_video_info(video_data: dict) -> dict:
|
|
|
192
193
|
)
|
|
193
194
|
|
|
194
195
|
if not candidates:
|
|
195
|
-
raise
|
|
196
|
+
raise ContentUnavailableError("未获取到无水印视频下载地址")
|
|
196
197
|
|
|
197
198
|
return max(candidates, key=lambda x: x["quality"])
|
|
198
199
|
|
|
@@ -212,7 +213,7 @@ class TikTokApiResult:
|
|
|
212
213
|
@classmethod
|
|
213
214
|
def parse(cls, json_dict: dict) -> Self:
|
|
214
215
|
if not json_dict:
|
|
215
|
-
raise
|
|
216
|
+
raise ContentUnavailableError("未获取到作品详情")
|
|
216
217
|
|
|
217
218
|
desc = json_dict.get("desc", "")
|
|
218
219
|
image_post_info: dict = json_dict.get("image_post_info", {}) or json_dict.get("imagePost", {})
|
|
@@ -243,7 +244,7 @@ class TikTokApiResult:
|
|
|
243
244
|
)
|
|
244
245
|
|
|
245
246
|
if not image_list:
|
|
246
|
-
raise
|
|
247
|
+
raise ContentUnavailableError("未获取到无水印图文下载地址")
|
|
247
248
|
|
|
248
249
|
return cls(
|
|
249
250
|
type=TikTokMediaType.IMAGE,
|
|
@@ -255,7 +256,7 @@ class TikTokApiResult:
|
|
|
255
256
|
def _parse_video(cls, data: dict, desc: str) -> Self:
|
|
256
257
|
video_data = data.get("video", {})
|
|
257
258
|
if not video_data:
|
|
258
|
-
raise
|
|
259
|
+
raise ContentUnavailableError("未获取到视频数据")
|
|
259
260
|
|
|
260
261
|
video_info = parse_video_info(video_data)
|
|
261
262
|
|
|
@@ -25,7 +25,7 @@ class ToutiaoParser(BaseParser):
|
|
|
25
25
|
try:
|
|
26
26
|
post = await Toutiao(proxy=self.proxy).parse(raw_url)
|
|
27
27
|
except ToutiaoError as e:
|
|
28
|
-
raise ParseError(
|
|
28
|
+
raise ParseError(str(e)) from e
|
|
29
29
|
|
|
30
30
|
if isinstance(post, ToutiaoVideoPost):
|
|
31
31
|
video = post.video
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
from ...provider_api.weixin import WX, WXItemShowType
|
|
2
|
-
from ...types import
|
|
2
|
+
from ...types import (
|
|
3
|
+
AnyParseResult,
|
|
4
|
+
ImageParseResult,
|
|
5
|
+
ImageRef,
|
|
6
|
+
Platform,
|
|
7
|
+
RichTextParseResult,
|
|
8
|
+
UnsupportedError,
|
|
9
|
+
)
|
|
3
10
|
from ..base.base import BaseParser
|
|
4
11
|
|
|
5
12
|
|
|
@@ -34,7 +41,7 @@ class WXParser(BaseParser):
|
|
|
34
41
|
content=wx.text_content,
|
|
35
42
|
)
|
|
36
43
|
case _:
|
|
37
|
-
raise
|
|
44
|
+
raise UnsupportedError(f"内容类型: {wx.item_show_type!r}")
|
|
38
45
|
|
|
39
46
|
|
|
40
47
|
__all__ = ["WXParser"]
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from ...provider_api.wxchannels import WXChannels, WXChannelsError
|
|
2
|
-
from ...types import ParseError, Platform, VideoParseResult, VideoRef
|
|
2
|
+
from ...types import LoginRequiredError, ParseError, Platform, VideoParseResult, VideoRef
|
|
3
3
|
from ..base.base import BaseParser
|
|
4
4
|
|
|
5
5
|
|
|
@@ -16,13 +16,13 @@ class WXChannelsParser(BaseParser):
|
|
|
16
16
|
async def _do_parse(self, raw_url: str) -> VideoParseResult:
|
|
17
17
|
cookie = self.cookie.get_value()
|
|
18
18
|
if not cookie:
|
|
19
|
-
raise
|
|
19
|
+
raise LoginRequiredError("配置腾讯元宝 (yuanbao.tencent.com) Cookie")
|
|
20
20
|
|
|
21
21
|
cookie_text = "; ".join(f"{key}={value}" for key, value in cookie.items())
|
|
22
22
|
try:
|
|
23
23
|
video = await WXChannels(cookie=cookie_text, proxy=self.proxy).parse(raw_url)
|
|
24
24
|
except WXChannelsError as e:
|
|
25
|
-
raise ParseError(
|
|
25
|
+
raise ParseError(str(e)) from e
|
|
26
26
|
|
|
27
27
|
return VideoParseResult(title=video.title, video=VideoRef(url=video.video_url, thumb_url=video.thumb_url))
|
|
28
28
|
|
|
@@ -7,9 +7,11 @@ from ...types import (
|
|
|
7
7
|
ImageParseResult,
|
|
8
8
|
ImageRef,
|
|
9
9
|
LivePhotoRef,
|
|
10
|
+
LoginRequiredError,
|
|
10
11
|
MultimediaParseResult,
|
|
11
12
|
ParseError,
|
|
12
13
|
Platform,
|
|
14
|
+
UnsupportedError,
|
|
13
15
|
VideoParseResult,
|
|
14
16
|
VideoRef,
|
|
15
17
|
)
|
|
@@ -26,9 +28,9 @@ class XHSParser(BaseParser):
|
|
|
26
28
|
async def get_raw_url(self, url: str, *, clean_all: bool = False, headers: dict | None = None) -> str:
|
|
27
29
|
url = await super().get_raw_url(url, clean_all=clean_all, headers=MOBILE_HEADERS)
|
|
28
30
|
if "/login" in url:
|
|
29
|
-
raise
|
|
31
|
+
raise LoginRequiredError("查看该帖子")
|
|
30
32
|
elif "/404/sec" in url:
|
|
31
|
-
raise ParseError("
|
|
33
|
+
raise ParseError("被风控拦截")
|
|
32
34
|
elif "/404" in url:
|
|
33
35
|
raise ContentUnavailableError("帖子不存在")
|
|
34
36
|
return url
|
|
@@ -61,7 +63,7 @@ class XHSParser(BaseParser):
|
|
|
61
63
|
match result.type:
|
|
62
64
|
case XHSPostType.VIDEO:
|
|
63
65
|
if not result.media:
|
|
64
|
-
raise
|
|
66
|
+
raise ContentUnavailableError("未获取到视频")
|
|
65
67
|
v: XHSMedia = result.media[0]
|
|
66
68
|
return VideoParseResult(
|
|
67
69
|
video=VideoRef(
|
|
@@ -89,7 +91,7 @@ class XHSParser(BaseParser):
|
|
|
89
91
|
content=desc,
|
|
90
92
|
)
|
|
91
93
|
case _:
|
|
92
|
-
raise
|
|
94
|
+
raise UnsupportedError("该类型")
|
|
93
95
|
|
|
94
96
|
@staticmethod
|
|
95
97
|
def hashtag_handler(desc: str | None) -> str:
|
|
@@ -3,12 +3,13 @@ from ...provider_api.xiaoheihe import XiaoHeiHeAPI, XiaoHeiHeMediaType, XiaoHeiH
|
|
|
3
3
|
from ...types import (
|
|
4
4
|
AniRef,
|
|
5
5
|
AnyParseResult,
|
|
6
|
+
ContentUnavailableError,
|
|
6
7
|
ImageParseResult,
|
|
7
8
|
ImageRef,
|
|
8
9
|
MultimediaParseResult,
|
|
9
|
-
ParseError,
|
|
10
10
|
Platform,
|
|
11
11
|
RichTextParseResult,
|
|
12
|
+
UnsupportedError,
|
|
12
13
|
VideoParseResult,
|
|
13
14
|
VideoRef,
|
|
14
15
|
)
|
|
@@ -40,12 +41,12 @@ class XiaoHeiHeParser(BaseParser):
|
|
|
40
41
|
media=self.__parse_images(xhh),
|
|
41
42
|
markdown_content=xhh.content,
|
|
42
43
|
)
|
|
43
|
-
raise
|
|
44
|
+
raise UnsupportedError("该类型")
|
|
44
45
|
|
|
45
46
|
@staticmethod
|
|
46
47
|
def __parse_video(xhh: XiaoHeiHePost) -> VideoRef:
|
|
47
48
|
if not xhh.media:
|
|
48
|
-
raise
|
|
49
|
+
raise ContentUnavailableError("未获取到视频")
|
|
49
50
|
media = xhh.media[0]
|
|
50
51
|
return VideoRef(url=media.url, thumb_url=media.thumb_url)
|
|
51
52
|
|
|
@@ -2,6 +2,7 @@ from ...provider_api.zhihu import ZhihuAPI, ZhihuPin, ZhihuPinType, ZhihuQA, Zhi
|
|
|
2
2
|
from ...types import (
|
|
3
3
|
ImageParseResult,
|
|
4
4
|
ImageRef,
|
|
5
|
+
LoginRequiredError,
|
|
5
6
|
MultimediaParseResult,
|
|
6
7
|
Platform,
|
|
7
8
|
RichTextParseResult,
|
|
@@ -20,7 +21,7 @@ class ZhihuParser(BaseParser):
|
|
|
20
21
|
self, raw_url: str
|
|
21
22
|
) -> RichTextParseResult | MultimediaParseResult | ImageParseResult | VideoParseResult:
|
|
22
23
|
if not (c := self.cookie.get_value()):
|
|
23
|
-
raise
|
|
24
|
+
raise LoginRequiredError("配置已登录的 Cookie")
|
|
24
25
|
result = await ZhihuAPI(cookie=c, proxy=self.proxy).parse(raw_url)
|
|
25
26
|
match result:
|
|
26
27
|
case ZhihuQA():
|
|
@@ -5,6 +5,7 @@ from dataclasses import dataclass, field
|
|
|
5
5
|
|
|
6
6
|
import httpx
|
|
7
7
|
|
|
8
|
+
from ..errors import UnsupportedError
|
|
8
9
|
from ..utils.helpers import UA
|
|
9
10
|
|
|
10
11
|
_TAG_RE = re.compile(
|
|
@@ -36,7 +37,7 @@ class Bangumi:
|
|
|
36
37
|
async def parse(self, url: str) -> BangumiPost:
|
|
37
38
|
match = _URL_RE.search(url)
|
|
38
39
|
if not match:
|
|
39
|
-
raise
|
|
40
|
+
raise UnsupportedError("该 Bangumi 链接")
|
|
40
41
|
|
|
41
42
|
kind = match.group(1) or match.group(2) or match.group(3)
|
|
42
43
|
topic_id = match.group(4)
|
|
@@ -12,7 +12,7 @@ from typing import Any, Self, cast
|
|
|
12
12
|
|
|
13
13
|
import httpx
|
|
14
14
|
|
|
15
|
-
from ..errors import ContentUnavailableError
|
|
15
|
+
from ..errors import ContentUnavailableError, InvalidUrlError, UnsupportedError
|
|
16
16
|
|
|
17
17
|
USER_AGENT = (
|
|
18
18
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36"
|
|
@@ -46,7 +46,7 @@ class BiliAPI:
|
|
|
46
46
|
"""获取动态信息"""
|
|
47
47
|
match = re.search(r"\b\d{18,19}\b", url)
|
|
48
48
|
if not match:
|
|
49
|
-
raise
|
|
49
|
+
raise InvalidUrlError(f"动态 {url}")
|
|
50
50
|
dyn_id = match.group(0)
|
|
51
51
|
params = {
|
|
52
52
|
"timezone_offset": "-480",
|
|
@@ -82,7 +82,7 @@ class BiliAPI:
|
|
|
82
82
|
"""获取视频详细信息"""
|
|
83
83
|
bvid = self.get_bvid(url)
|
|
84
84
|
if not bvid:
|
|
85
|
-
raise
|
|
85
|
+
raise InvalidUrlError(url)
|
|
86
86
|
response = await self._get_client().get(
|
|
87
87
|
"https://api.bilibili.com/x/web-interface/view/detail",
|
|
88
88
|
params={"bvid": bvid},
|
|
@@ -129,7 +129,7 @@ class BiliAPI:
|
|
|
129
129
|
"""获取音乐详细信息"""
|
|
130
130
|
sid = self.get_music_id(url)
|
|
131
131
|
if not sid:
|
|
132
|
-
raise
|
|
132
|
+
raise InvalidUrlError(url)
|
|
133
133
|
response = await self._get_client().get(
|
|
134
134
|
"https://www.bilibili.com/audio/music-service-c/web/song/info",
|
|
135
135
|
params={"sid": sid},
|
|
@@ -306,7 +306,7 @@ class BiliDynamic:
|
|
|
306
306
|
}
|
|
307
307
|
major_parser = major_parsers.get(MajorType(major_type), None)
|
|
308
308
|
if not major_parser:
|
|
309
|
-
raise
|
|
309
|
+
raise UnsupportedError(f"major type: {major_type}")
|
|
310
310
|
return major_parser(module_dynamic, major)
|
|
311
311
|
|
|
312
312
|
@classmethod
|
|
@@ -5,6 +5,7 @@ from bs4 import BeautifulSoup
|
|
|
5
5
|
from markdown import markdown
|
|
6
6
|
from markdownify import MarkdownConverter
|
|
7
7
|
|
|
8
|
+
from ..errors import ContentUnavailableError, InvalidUrlError
|
|
8
9
|
from ..utils.helpers import UA
|
|
9
10
|
|
|
10
11
|
|
|
@@ -19,6 +20,7 @@ class Coolapk:
|
|
|
19
20
|
async def parse(cls, url: str, proxy: str | None = None) -> "Coolapk":
|
|
20
21
|
async with httpx.AsyncClient(headers={"User-Agent": UA}, proxy=proxy) as client:
|
|
21
22
|
result = await client.get(url)
|
|
23
|
+
result.raise_for_status()
|
|
22
24
|
soup = BeautifulSoup(result.text, "lxml")
|
|
23
25
|
# 酷安网页版不加载实况照片
|
|
24
26
|
title_element = soup.find(class_="message-title")
|
|
@@ -26,8 +28,8 @@ class Coolapk:
|
|
|
26
28
|
content = soup.find(class_="feed-article-message")
|
|
27
29
|
if content is None:
|
|
28
30
|
if "s=" in url or "shareKey=" in url:
|
|
29
|
-
raise
|
|
30
|
-
raise
|
|
31
|
+
raise ContentUnavailableError("获取内容失败")
|
|
32
|
+
raise InvalidUrlError("获取内容失败, 分享时请保留 shareKey 或 s 参数")
|
|
31
33
|
markdown_content = MarkdownConverter(heading_style="ATX").convert(str(content))
|
|
32
34
|
text_content = "".join(BeautifulSoup(markdown(markdown_content), "lxml").find_all(string=True))
|
|
33
35
|
imgs = [f"https:{i['src']}" for i in content.find_all("img", {"class": "message-image"})]
|
|
@@ -39,4 +41,4 @@ class Coolapk:
|
|
|
39
41
|
imgs = [f"https:{i['src']}" for i in message_image_group.find_all("img")] if message_image_group else []
|
|
40
42
|
return cls("", "", feed_content, imgs)
|
|
41
43
|
|
|
42
|
-
raise
|
|
44
|
+
raise InvalidUrlError("获取内容失败, 分享时请保留 shareKey 或 s 参数")
|
|
@@ -7,6 +7,8 @@ from bs4 import BeautifulSoup
|
|
|
7
7
|
from markdown import markdown
|
|
8
8
|
from markdownify import MarkdownConverter
|
|
9
9
|
|
|
10
|
+
from ..errors import UnsupportedError
|
|
11
|
+
|
|
10
12
|
TOPIC_API = "https://m.douban.com/rexxar/api/v2/group/topic/{}"
|
|
11
13
|
IMAGE_REFERER = "https://www.douban.com/"
|
|
12
14
|
"""豆瓣图床有防盗链, 下载图片时必须带上 Referer"""
|
|
@@ -33,7 +35,7 @@ class Douban:
|
|
|
33
35
|
def get_topic_id(url: str) -> str:
|
|
34
36
|
if match := re.search(TOPIC_URL_RE, url):
|
|
35
37
|
return match.group(1)
|
|
36
|
-
raise
|
|
38
|
+
raise UnsupportedError("该豆瓣链接, 目前仅支持小组话题")
|
|
37
39
|
|
|
38
40
|
async def fetch_topic_data(self, url: str) -> dict[str, Any]:
|
|
39
41
|
headers = {"User-Agent": MOBILE_UA, "Referer": "https://m.douban.com/"}
|