mirror of
https://github.com/ucmao/media-parser.git
synced 2026-11-20 08:04:56 +08:00
fix(皮皮搞笑): 提取帖子图集,补齐 imgs.urls 原图直链
This commit is contained in:
@@ -7,9 +7,10 @@
|
||||
## 1. 平台特征与支持能力
|
||||
|
||||
* **平台标识**:`皮皮搞笑`
|
||||
* **支持媒体类型**:无水印视频 (MP4) / 帖子标题 / 封面
|
||||
* **支持媒体类型**:无水印视频 (MP4) / 图集 / 帖子文案 / 封面 / 作者
|
||||
* **常见链接形态**:
|
||||
* 移动分享页:`https://h5.pipigx.com/pp/post/815491325984?pid=815491325984&type=post`
|
||||
* 空间/新版分享页:`https://h5.ippzone.com/spacey/post/897800342766?pid=897800342766&type=post`
|
||||
* **Cookie 依赖**:无需 Cookie。
|
||||
|
||||
---
|
||||
@@ -17,13 +18,21 @@
|
||||
## 2. 核心逆向流程
|
||||
|
||||
1. **ID 提取**:从 Query 参数或 Path 中提取 `pid` / `post_id`。
|
||||
2. **H5 数据接口**:
|
||||
* 接口:`POST https://api.pipigx.com/ppapi/cell/detail`
|
||||
* 或直接在 H5 落地页 HTML 中提取内嵌 JSON。
|
||||
3. **视频直链提取**:从 `post.video.video_download_url` 或 `post.video.video_url` 中提取 MP4 直链。
|
||||
2. **H5 分享接口**:
|
||||
* 接口:`POST https://h5.pipigx.com/ppapi/share/fetch_content`
|
||||
* 请求体:`{"mid": null, "pid": <pid>, "type": "post"}`(JSON,表单方式会返回"请求参数错误")
|
||||
* 响应:`data.post`,其中 `content` 为文案、`imgs` 为图片/视频素材、`videos` 为视频直链映射。
|
||||
3. **视频直链提取**:`post.videos[str(imgs[0].id)].url`。
|
||||
4. **图集提取**:`post.imgs` 中 `video` 不为真的条目即配图,直链取
|
||||
`imgs[i].urls.origin.urls[0]`(原图),缺失时依次回落到 `540` / `360` 变体,
|
||||
最后回落 `https://file.ippzone.com/img/view/id/{imgs[i].id}`。
|
||||
该 URL 目录下没有文件名,是按图片 ID 动态返回的。
|
||||
|
||||
> 视频帖的 `imgs[0]` 是视频本身(`video: 1`,且没有 `urls`),不要当成配图返回。
|
||||
|
||||
---
|
||||
|
||||
## 3. 测试与验证
|
||||
|
||||
* **单元测试**:`python -m unittest tests/test_pipigaoxiao_parser.py`
|
||||
* **样本验证**:`python tests/manual_verify_parsers.py --platform 皮皮搞笑`
|
||||
|
||||
@@ -64,6 +64,33 @@ class PipigaoxiaoParser(BaseParser):
|
||||
logger.warning(f"Failed to parse Pipigaoxiao description: {e}")
|
||||
return None
|
||||
|
||||
def get_image_list(self):
|
||||
"""提取帖子图集;imgs 里 video=1 的是视频本身,不是配图。"""
|
||||
try:
|
||||
if not self.data: return []
|
||||
imgs = self.data.get('data', {}).get('post', {}).get('imgs') or []
|
||||
|
||||
image_list = []
|
||||
for img in imgs:
|
||||
if not isinstance(img, dict) or img.get('video'):
|
||||
continue
|
||||
|
||||
# 优先原图,其次 540/360 压缩图,最后回落到按图片 ID 拼的地址
|
||||
urls = img.get('urls') or {}
|
||||
candidates = []
|
||||
for key in ('origin', '540', '360'):
|
||||
variant = urls.get(key) or {}
|
||||
candidates.extend(variant.get('urls') or [])
|
||||
url = next((u for u in candidates if u), None)
|
||||
if not url and img.get('id'):
|
||||
url = f"https://file.ippzone.com/img/view/id/{img['id']}"
|
||||
if url:
|
||||
image_list.append(url)
|
||||
return image_list
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to parse Pipigaoxiao image list: {e}")
|
||||
return []
|
||||
|
||||
def get_cover_photo_url(self):
|
||||
try:
|
||||
if not self.data: return ""
|
||||
|
||||
@@ -580,6 +580,20 @@
|
||||
"note": "2026-08-28 已验证",
|
||||
"pattern": "基础标准样例"
|
||||
},
|
||||
{
|
||||
"platform": "皮皮搞笑",
|
||||
"url": "https://h5.ippzone.com/spacey/post/897800342766?pid=897800342766&type=post",
|
||||
"media_types": [
|
||||
"images"
|
||||
],
|
||||
"expected_fields": [
|
||||
"images",
|
||||
"cover",
|
||||
"author"
|
||||
],
|
||||
"note": "2026-09-19 用户反馈修复: 空间/新版分享页 8 图图集",
|
||||
"pattern": "spacey 图集"
|
||||
},
|
||||
{
|
||||
"platform": "皮皮虾",
|
||||
"url": "https://h5.pipix.com/s/lggjR-ynbpI/",
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from src.parsers.pipigaoxiao_parser import PipigaoxiaoParser
|
||||
|
||||
|
||||
def _image_node(img_id, video=0, live=0, origin=True):
|
||||
node = {
|
||||
"id": img_id,
|
||||
"w": 1080,
|
||||
"h": 1441,
|
||||
"video": video,
|
||||
"live": live,
|
||||
"urls": {},
|
||||
}
|
||||
if origin:
|
||||
node["urls"] = {
|
||||
"origin": {"urls": [f"http://bd-file.ippzone.com/img/view/id/{img_id}/sz/src",
|
||||
f"http://file.ippzone.com/img/view/id/{img_id}/sz/src"]},
|
||||
"540": {"urls": [f"http://file.ippzone.com/img/view/id/{img_id}/sz/540"]},
|
||||
}
|
||||
return node
|
||||
|
||||
|
||||
class PipigaoxiaoParserTest(unittest.TestCase):
|
||||
def _parser_with(self, post):
|
||||
with patch.object(PipigaoxiaoParser, "fetch_html_data", return_value={"data": {"post": post}}):
|
||||
return PipigaoxiaoParser("https://h5.ippzone.com/spacey/post/897800342766")
|
||||
|
||||
def test_image_post_returns_all_origin_images(self):
|
||||
parser = self._parser_with({
|
||||
"content": "",
|
||||
"videos": None,
|
||||
"imgs": [_image_node(2538988134), _image_node(2538988128), _image_node(2538988129)],
|
||||
})
|
||||
|
||||
self.assertEqual(parser.get_image_list(), [
|
||||
"http://bd-file.ippzone.com/img/view/id/2538988134/sz/src",
|
||||
"http://bd-file.ippzone.com/img/view/id/2538988128/sz/src",
|
||||
"http://bd-file.ippzone.com/img/view/id/2538988129/sz/src",
|
||||
])
|
||||
self.assertIsNone(parser.get_real_video_url())
|
||||
|
||||
def test_video_post_does_not_report_images(self):
|
||||
parser = self._parser_with({
|
||||
"content": "350。。。小钱钱。。晚上继续喝",
|
||||
"videos": {"2405682288": {"url": "http://video01.szsttkj.com/a/b/c"}},
|
||||
"imgs": [_image_node(2405682288, video=1, origin=False)],
|
||||
})
|
||||
|
||||
self.assertEqual(parser.get_image_list(), [])
|
||||
self.assertEqual(parser.get_real_video_url(), "http://video01.szsttkj.com/a/b/c")
|
||||
|
||||
def test_falls_back_to_id_url_when_variants_missing(self):
|
||||
parser = self._parser_with({"imgs": [_image_node(2538988134, origin=False)]})
|
||||
|
||||
self.assertEqual(parser.get_image_list(),
|
||||
["https://file.ippzone.com/img/view/id/2538988134"])
|
||||
|
||||
def test_empty_data_is_safe(self):
|
||||
parser = self._parser_with({})
|
||||
self.assertEqual(parser.get_image_list(), [])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user