feat: 新增平台
This commit is contained in:
91
parsers/pipixia.py
Normal file
91
parsers/pipixia.py
Normal file
@@ -0,0 +1,91 @@
|
||||
from parsers.base import BaseParser
|
||||
from typing import Dict
|
||||
from urllib.parse import urlencode
|
||||
|
||||
|
||||
class PipixiaBugPKParser(BaseParser):
|
||||
"""皮皮虾解析器 - BugPK API"""
|
||||
|
||||
def parse(self, video_url: str) -> Dict:
|
||||
"""解析皮皮虾视频"""
|
||||
try:
|
||||
url = f"{self.api_url}/api/pipixia?{urlencode({'url': video_url})}"
|
||||
response = self._make_request(url)
|
||||
data = response.json()
|
||||
return self._extract_data(data)
|
||||
except Exception as e:
|
||||
raise Exception(f"皮皮虾解析失败(BugPK API): {str(e)}")
|
||||
|
||||
def _extract_data(self, data: Dict) -> Dict:
|
||||
"""提取并标准化数据
|
||||
实际返回格式:
|
||||
{
|
||||
"code": 200,
|
||||
"msg": "解析成功",
|
||||
"data": {
|
||||
"author": "作者名",
|
||||
"avatar": "头像URL",
|
||||
"title": "标题",
|
||||
"cover": "封面URL",
|
||||
"url": "视频URL"
|
||||
}
|
||||
}
|
||||
"""
|
||||
try:
|
||||
if data.get("code") == 200:
|
||||
video_data = data.get("data", {})
|
||||
|
||||
cover = video_data.get("cover", "")
|
||||
video_url = video_data.get("url", "")
|
||||
title = video_data.get("title", "")
|
||||
description = ""
|
||||
author = video_data.get("author", "")
|
||||
|
||||
return self._normalize_response(cover, video_url, title, description, author)
|
||||
else:
|
||||
raise Exception(f"解析失败: {data.get('msg', '未知错误')}")
|
||||
except Exception as e:
|
||||
raise Exception(f"数据提取失败: {str(e)}")
|
||||
|
||||
|
||||
class PipixiaUctbParser(BaseParser):
|
||||
"""皮皮虾解析器 - 优创 API"""
|
||||
|
||||
def parse(self, video_url: str) -> Dict:
|
||||
"""解析皮皮虾视频"""
|
||||
try:
|
||||
url = f"{self.api_url}/api/videojx?{urlencode({'url': video_url})}"
|
||||
response = self._make_request(url)
|
||||
data = response.json()
|
||||
return self._extract_data(data)
|
||||
except Exception as e:
|
||||
raise Exception(f"皮皮虾解析失败(优创 API): {str(e)}")
|
||||
|
||||
def _extract_data(self, data: Dict) -> Dict:
|
||||
"""提取并标准化数据
|
||||
实际返回格式:
|
||||
{
|
||||
"code": 200,
|
||||
"data": {
|
||||
"desc": null,
|
||||
"cover": "封面URL",
|
||||
"playurl": "视频URL"
|
||||
},
|
||||
"msg": "请求成功"
|
||||
}
|
||||
"""
|
||||
try:
|
||||
if data.get("code") == 200:
|
||||
video_data = data.get("data", {})
|
||||
|
||||
cover = video_data.get("cover", "")
|
||||
video_url = video_data.get("playurl", "")
|
||||
title = video_data.get("desc", "") or ""
|
||||
description = ""
|
||||
author = "" # 优创API不返回作者
|
||||
|
||||
return self._normalize_response(cover, video_url, title, description, author)
|
||||
else:
|
||||
raise Exception(f"解析失败: {data.get('msg', '未知错误')}")
|
||||
except Exception as e:
|
||||
raise Exception(f"数据提取失败: {str(e)}")
|
||||
Reference in New Issue
Block a user