feat: Add comprehensive Zhihu URL support
- Add zhuanlan article support (zhuanlan.zhihu.com/p/{id})
- Add organization page support (zhihu.com/org/{name})
- Add organization subpages: answers, zvideos, asks, posts, pins
- Add zvideo support (zhihu.com/zvideo/{id})
- Improve URL pattern matching for various Zhihu content types
This commit is contained in:
@@ -50,6 +50,15 @@ class LinkParser:
|
|||||||
ZHIHAU_USER_PATTERN = re.compile(r'https?://(?:www\.)?zhihu\.com/people/([a-zA-Z0-9_-]+)')
|
ZHIHAU_USER_PATTERN = re.compile(r'https?://(?:www\.)?zhihu\.com/people/([a-zA-Z0-9_-]+)')
|
||||||
ZHIHAU_COLUMN_PATTERN = re.compile(r'https?://(?:www\.)?zhihu\.com/column/([a-zA-Z0-9_-]+)')
|
ZHIHAU_COLUMN_PATTERN = re.compile(r'https?://(?:www\.)?zhihu\.com/column/([a-zA-Z0-9_-]+)')
|
||||||
ZHIHAU_COLLECTION_PATTERN = re.compile(r'https?://(?:www\.)?zhihu\.com/collection/(\d+)')
|
ZHIHAU_COLLECTION_PATTERN = re.compile(r'https?://(?:www\.)?zhihu\.com/collection/(\d+)')
|
||||||
|
# Additional Zhihu patterns
|
||||||
|
ZHIHAU_ZHUANLAN_PATTERN = re.compile(r'https?://zhuanlan\.zhihu\.com/p/(\d+)')
|
||||||
|
ZHIHAU_ORG_PATTERN = re.compile(r'https?://(?:www\.)?zhihu\.com/org/([a-zA-Z0-9_-]+)')
|
||||||
|
ZHIHAU_ORG_ANSWERS_PATTERN = re.compile(r'https?://(?:www\.)?zhihu\.com/org/[a-zA-Z0-9_-]+/answers')
|
||||||
|
ZHIHAU_ORG_VIDEOS_PATTERN = re.compile(r'https?://(?:www\.)?zhihu\.com/org/[a-zA-Z0-9_-]+/zvideos')
|
||||||
|
ZHIHAU_ORG_ASKS_PATTERN = re.compile(r'https?://(?:www\.)?zhihu\.com/org/[a-zA-Z0-9_-]+/asks')
|
||||||
|
ZHIHAU_ORG_POSTS_PATTERN = re.compile(r'https?://(?:www\.)?zhihu\.com/org/[a-zA-Z0-9_-]+/posts')
|
||||||
|
ZHIHAU_ORG_PINS_PATTERN = re.compile(r'https?://(?:www\.)?zhihu\.com/org/[a-zA-Z0-9_-]+/pins')
|
||||||
|
ZHIHAU_ZVIDEO_PATTERN = re.compile(r'https?://(?:www\.)?zhihu\.com/zvideo/(\d+)')
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.shortlink_resolver = ShortLinkResolver()
|
self.shortlink_resolver = ShortLinkResolver()
|
||||||
@@ -273,6 +282,83 @@ class LinkParser:
|
|||||||
"id": match.group(1)
|
"id": match.group(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Try zhuanlan article (专栏文章)
|
||||||
|
match = self.ZHIHAU_ZHUANLAN_PATTERN.match(url)
|
||||||
|
if match:
|
||||||
|
return {
|
||||||
|
"platform": "zhihu",
|
||||||
|
"type": "zhuanlan",
|
||||||
|
"id": match.group(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Try org page (机构页面)
|
||||||
|
match = self.ZHIHAU_ORG_PATTERN.match(url)
|
||||||
|
if match:
|
||||||
|
return {
|
||||||
|
"platform": "zhihu",
|
||||||
|
"type": "org",
|
||||||
|
"id": match.group(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Try org answers (机构回答)
|
||||||
|
if self.ZHIHAU_ORG_ANSWERS_PATTERN.match(url):
|
||||||
|
match = self.ZHIHAU_ORG_PATTERN.match(url)
|
||||||
|
if match:
|
||||||
|
return {
|
||||||
|
"platform": "zhihu",
|
||||||
|
"type": "org_answers",
|
||||||
|
"id": match.group(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Try org zvideos (机构视频)
|
||||||
|
if self.ZHIHAU_ORG_VIDEOS_PATTERN.match(url):
|
||||||
|
match = self.ZHIHAU_ORG_PATTERN.match(url)
|
||||||
|
if match:
|
||||||
|
return {
|
||||||
|
"platform": "zhihu",
|
||||||
|
"type": "org_zvideos",
|
||||||
|
"id": match.group(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Try org asks (机构提问)
|
||||||
|
if self.ZHIHAU_ORG_ASKS_PATTERN.match(url):
|
||||||
|
match = self.ZHIHAU_ORG_PATTERN.match(url)
|
||||||
|
if match:
|
||||||
|
return {
|
||||||
|
"platform": "zhihu",
|
||||||
|
"type": "org_asks",
|
||||||
|
"id": match.group(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Try org posts (机构文章)
|
||||||
|
if self.ZHIHAU_ORG_POSTS_PATTERN.match(url):
|
||||||
|
match = self.ZHIHAU_ORG_PATTERN.match(url)
|
||||||
|
if match:
|
||||||
|
return {
|
||||||
|
"platform": "zhihu",
|
||||||
|
"type": "org_posts",
|
||||||
|
"id": match.group(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Try org pins (机构想法)
|
||||||
|
if self.ZHIHAU_ORG_PINS_PATTERN.match(url):
|
||||||
|
match = self.ZHIHAU_ORG_PATTERN.match(url)
|
||||||
|
if match:
|
||||||
|
return {
|
||||||
|
"platform": "zhihu",
|
||||||
|
"type": "org_pins",
|
||||||
|
"id": match.group(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Try zvideo (知乎视频)
|
||||||
|
match = self.ZHIHAU_ZVIDEO_PATTERN.match(url)
|
||||||
|
if match:
|
||||||
|
return {
|
||||||
|
"platform": "zhihu",
|
||||||
|
"type": "zvideo",
|
||||||
|
"id": match.group(1)
|
||||||
|
}
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def parse(self, url: str) -> Dict[str, Any]:
|
def parse(self, url: str) -> Dict[str, Any]:
|
||||||
|
|||||||
Reference in New Issue
Block a user