douyin\bilibili\kuaishou 视频播放量
This commit is contained in:
parent
23539014ca
commit
422c0135d1
@ -207,10 +207,10 @@ def _extract_calculation_params_b2(data: UserValuationCreate) -> Dict[str, Any]:
|
||||
# 活态传承系数B21 县官参数
|
||||
inheritor_level_coefficient = data.inheritor_level # 传承人等级
|
||||
offline_sessions = int(data.offline_activities) #线下传习次数
|
||||
# 以下调用API
|
||||
douyin_views = "抖音播放量"
|
||||
kuaishou_views= "快手播放量"
|
||||
bilibili_views= "B站播放量"
|
||||
# 以下调用API douyin\bilibili\kuaishou
|
||||
douyin_views = universal_api.video_views("douyin",video_id="视频id未知")
|
||||
kuaishou_views= universal_api.video_views("kuaishou",video_id="视频id未知")
|
||||
bilibili_views= universal_api.video_views("bilibili",video_id="视频id未知")
|
||||
# 跨界合作深度 品牌联名0.3,科技载体0.5,国家外交礼品1.0
|
||||
cross_border_depth = float(data.cooperation_depth)
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ from pathlib import Path
|
||||
|
||||
class APIConfig:
|
||||
"""API配置管理器"""
|
||||
|
||||
|
||||
def __init__(self, config_file: str = None):
|
||||
"""
|
||||
初始化配置管理器
|
||||
@ -23,7 +23,7 @@ class APIConfig:
|
||||
"""
|
||||
self.config_file = config_file or os.path.join(os.path.dirname(__file__), 'api_config.json')
|
||||
self.config = self._load_config()
|
||||
|
||||
|
||||
def _load_config(self) -> Dict[str, Any]:
|
||||
"""加载配置"""
|
||||
# 默认配置
|
||||
@ -55,45 +55,188 @@ class APIConfig:
|
||||
}
|
||||
}
|
||||
},
|
||||
<<<<<<< HEAD
|
||||
|
||||
"justoneapi": {
|
||||
"api_key": os.getenv("JUSTONEAPI_TOKEN", "YNSbIjdU"),
|
||||
"base_url": "https://api.justoneapi.com",
|
||||
"timeout": 30,
|
||||
"retries": 3,
|
||||
"endpoints": {
|
||||
=======
|
||||
"xiaohongshu": {
|
||||
"api_key": os.getenv("XIAOHONGSHU_TOKEN", "YNSbIjdU"),
|
||||
"api_key": os.getenv("JUSTONEAPI_TOKEN", "YNSbIjdU"),
|
||||
"base_url": "https://api.justoneapi.com",
|
||||
"timeout": 30,
|
||||
"retries": 3,
|
||||
"endpoints": {
|
||||
>>>>>>> b46c1a349b8413b2daf4a02b862ddcfde1953d76
|
||||
"xiaohongshu_note_detail": {
|
||||
"path": "/api/xiaohongshu/get-note-detail/v7",
|
||||
"method": "GET",
|
||||
"description": "小红书笔记详情查询",
|
||||
"required_params": ["noteId"],
|
||||
"optional_params": ["token"]
|
||||
"xiaohongshu": {
|
||||
"api_key": os.getenv("XIAOHONGSHU_TOKEN", "YNSbIjdU"),
|
||||
"base_url": "https://api.justoneapi.com",
|
||||
"timeout": 30,
|
||||
"retries": 3,
|
||||
"endpoints": {
|
||||
"xiaohongshu_note_detail": {
|
||||
"path": "/api/xiaohongshu/get-note-detail/v7",
|
||||
"method": "GET",
|
||||
"description": "小红书笔记详情查询",
|
||||
"required_params": ["noteId"],
|
||||
"optional_params": ["token"]
|
||||
},
|
||||
"xiaohongshu_user_info": {
|
||||
"path": "/api/xiaohongshu/get-user-info/v7",
|
||||
"method": "GET",
|
||||
"description": "小红书用户信息查询",
|
||||
"required_params": ["userId"],
|
||||
"optional_params": ["token"]
|
||||
},
|
||||
"xiaohongshu_search_notes": {
|
||||
"path": "/api/xiaohongshu/search-notes/v7",
|
||||
"method": "GET",
|
||||
"description": "小红书笔记搜索",
|
||||
"required_params": ["keyword"],
|
||||
"optional_params": ["page", "size", "token"]
|
||||
},
|
||||
"weibo_user_detail": {
|
||||
"path": "/api/weibo/get-user-detail/v1", # 微博只有粉丝数接口
|
||||
"method": "GET",
|
||||
"description": "获取用户信息 包括昵称、头像、用户ID、粉丝数、关注数、简介、认证状态等公开信息",
|
||||
"required_params": ["token", "uid"],
|
||||
"optional_params": ["token", "uid"]
|
||||
},
|
||||
"weixin_user_detail": {
|
||||
"path": "/api/weixin/get-user-post/v1",
|
||||
"method": "GET",
|
||||
"description": "公众号发布的文章内容,包括标题、作者、发布时间、内容摘要以及阅读数、点赞数与转发数等互动数据",
|
||||
"required_params": ["token", "wxid"],
|
||||
"optional_params": ["token", "wxid"]
|
||||
},
|
||||
"douyin_video_detail": {
|
||||
"path": "/api/douyin/get-video-detail/v2",
|
||||
"method": "GET",
|
||||
"description": "该接口用于获取指定抖音视频的详细信息,包括视频地址、描述文案、作者信息、发布时间、播放量、点赞数、评论数与分享数等",
|
||||
"required_params": ["token", "videoId"],
|
||||
"optional_params": ["token", "videoId"]
|
||||
},
|
||||
"kuaishou_video_detail": {
|
||||
"path": "/api/kuaishou/get-video-detail/v2",
|
||||
"method": "GET",
|
||||
"description": "该接口用于获取指定抖音视频的详细信息,包括视频地址、描述文案、作者信息、发布时间、播放量、点赞数、评论数与分享数等",
|
||||
"required_params": ["token", "videoId"],
|
||||
"optional_params": ["token", "videoId"]
|
||||
},
|
||||
"bilibili_video_detail": {
|
||||
"path": "/api/bilibili/get-video-detail/v2",
|
||||
"method": "GET",
|
||||
"description": "该接口用于获取指定抖音视频的详细信息,包括视频地址、描述文案、作者信息、发布时间、播放量、点赞数、评论数与分享数等",
|
||||
"required_params": ["token", "bvid"],
|
||||
"optional_params": ["token", "bvid"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"xiaohongshu_user_info": {
|
||||
"path": "/api/xiaohongshu/get-user-info/v7",
|
||||
"method": "GET",
|
||||
"description": "小红书用户信息查询",
|
||||
"required_params": ["userId"],
|
||||
"optional_params": ["token"]
|
||||
"weibo": {
|
||||
"api_key": os.getenv("XIAOHONGSHU_TOKEN", "YNSbIjdU"),
|
||||
"base_url": "https://api.justoneapi.com",
|
||||
"timeout": 30,
|
||||
"retries": 3,
|
||||
"endpoints": {
|
||||
"weibo_user_detail": {
|
||||
"path": "/api/weibo/get-user-detail/v1", # 微博只有粉丝数接口
|
||||
"method": "GET",
|
||||
"description": "获取用户信息 包括昵称、头像、用户ID、粉丝数、关注数、简介、认证状态等公开信息",
|
||||
"required_params": ["token", "uid"],
|
||||
"optional_params": ["token", "uid"]
|
||||
},
|
||||
|
||||
}
|
||||
},
|
||||
"xiaohongshu_search_notes": {
|
||||
"path": "/api/xiaohongshu/search-notes/v7",
|
||||
"method": "GET",
|
||||
"description": "小红书笔记搜索",
|
||||
"required_params": ["keyword"],
|
||||
"optional_params": ["page", "size", "token"]
|
||||
"weixin": {
|
||||
"api_key": os.getenv("XIAOHONGSHU_TOKEN", "YNSbIjdU"),
|
||||
"base_url": "https://api.justoneapi.com",
|
||||
"timeout": 30,
|
||||
"retries": 3,
|
||||
"endpoints": {
|
||||
"weixin_user_detail": {
|
||||
"path": "/api/weixin/get-user-post/v1",
|
||||
"method": "GET",
|
||||
"description": "公众号发布的文章内容,包括标题、作者、发布时间、内容摘要以及阅读数、点赞数与转发数等互动数据",
|
||||
"required_params": ["token", "wxid"],
|
||||
"optional_params": ["token", "wxid"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"douyin": {
|
||||
"api_key": os.getenv("XIAOHONGSHU_TOKEN", "YNSbIjdU"),
|
||||
"base_url": "https://api.justoneapi.com",
|
||||
"timeout": 30,
|
||||
"retries": 3,
|
||||
"endpoints": {
|
||||
"douyin_video_detail": {
|
||||
"path": "/api/douyin/get-video-detail/v2",
|
||||
"method": "GET",
|
||||
"description": "该接口用于获取指定抖音视频的详细信息,包括视频地址、描述文案、作者信息、发布时间、播放量、点赞数、评论数与分享数等",
|
||||
"required_params": ["token", "videoId"],
|
||||
"optional_params": ["token", "videoId"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"bilibili": {
|
||||
"api_key": os.getenv("XIAOHONGSHU_TOKEN", "YNSbIjdU"),
|
||||
"base_url": "https://api.justoneapi.com",
|
||||
"timeout": 30,
|
||||
"retries": 3,
|
||||
"endpoints": {
|
||||
"bilibili_video_detail": {
|
||||
"path": "/api/bilibili/get-video-detail/v2",
|
||||
"method": "GET",
|
||||
"description": "该接口用于获取指定抖音视频的详细信息,包括视频地址、描述文案、作者信息、发布时间、播放量、点赞数、评论数与分享数等",
|
||||
"required_params": ["token", "bvid"],
|
||||
"optional_params": ["token", "bvid"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"kuaishou": {
|
||||
"api_key": os.getenv("XIAOHONGSHU_TOKEN", "YNSbIjdU"),
|
||||
"base_url": "https://api.justoneapi.com",
|
||||
"timeout": 30,
|
||||
"retries": 3,
|
||||
"endpoints": {
|
||||
"kuaishou_video_detail": {
|
||||
"path": "/api/kuaishou/get-video-detail/v2",
|
||||
"method": "GET",
|
||||
"description": "该接口用于获取指定抖音视频的详细信息,包括视频地址、描述文案、作者信息、发布时间、播放量、点赞数、评论数与分享数等",
|
||||
"required_params": ["token", "videoId"],
|
||||
"optional_params": ["token", "videoId"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"other_apis": {
|
||||
"jizhiliao": {
|
||||
"api_key": os.getenv("JIZHILIAO_API_KEY", "JZL089ef0b7d0315d96"),
|
||||
"base_url": "https://api.justoneapi.com",
|
||||
"timeout": 30,
|
||||
"retries": 3,
|
||||
"verifycode": os.getenv("JIZHILIAO_VERIFYCODE", ""),
|
||||
"endpoints": {
|
||||
"index_search": {
|
||||
"path": "/fbmain/monitor/v3/web_search",
|
||||
"method": "POST",
|
||||
"description": "极致聊指数搜索",
|
||||
"required_params": ["keyword", "mode", "BusinessType", "sub_search_type"],
|
||||
"optional_params": ["key", "verifycode"]
|
||||
},
|
||||
|
||||
}
|
||||
},
|
||||
"other": {
|
||||
# 可以添加其他第三方API配置
|
||||
|
||||
"example_api": {
|
||||
"api_key": os.getenv("EXAMPLE_API_KEY", ""),
|
||||
"base_url": "https://api.example.com",
|
||||
"endpoints": {}
|
||||
}
|
||||
},
|
||||
"common_settings": {
|
||||
"timeout": 60,
|
||||
"retries": 3,
|
||||
"sign_prefix": "634xz"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
<<<<<<< HEAD
|
||||
# 微信指数
|
||||
"dajiala": {
|
||||
"api_key": "",
|
||||
@ -101,50 +244,17 @@ class APIConfig:
|
||||
"timeout": 30,
|
||||
"retries": 3,
|
||||
"endpoints": {
|
||||
"web_search":{
|
||||
"web_search": {
|
||||
"path": "/fbmain/monitor/v3/web_search",
|
||||
"method": "POST",
|
||||
"description": "获取微信指数",
|
||||
"required_params": ["keyword","key"],
|
||||
"required_params": ["keyword", "key"],
|
||||
"optional_params": []
|
||||
}
|
||||
}
|
||||
},
|
||||
"other_apis": {
|
||||
=======
|
||||
"jizhiliao": {
|
||||
"api_key": os.getenv("JIZHILIAO_API_KEY", "JZL089ef0b7d0315d96"),
|
||||
"base_url": "https://www.dajiala.com",
|
||||
"timeout": 30,
|
||||
"retries": 3,
|
||||
"verifycode": os.getenv("JIZHILIAO_VERIFYCODE", ""),
|
||||
"endpoints": {
|
||||
"index_search": {
|
||||
"path": "/fbmain/monitor/v3/web_search",
|
||||
"method": "POST",
|
||||
"description": "极致聊指数搜索",
|
||||
"required_params": ["keyword", "mode", "BusinessType", "sub_search_type"],
|
||||
"optional_params": ["key", "verifycode"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"other": {
|
||||
>>>>>>> b46c1a349b8413b2daf4a02b862ddcfde1953d76
|
||||
# 可以添加其他第三方API配置
|
||||
|
||||
"example_api": {
|
||||
"api_key": os.getenv("EXAMPLE_API_KEY", ""),
|
||||
"base_url": "https://api.example.com",
|
||||
"endpoints": {}
|
||||
}
|
||||
},
|
||||
"common_settings": {
|
||||
"timeout": 60,
|
||||
"retries": 3,
|
||||
"sign_prefix": "634xz"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# 尝试从文件加载配置
|
||||
if os.path.exists(self.config_file):
|
||||
try:
|
||||
@ -154,9 +264,9 @@ class APIConfig:
|
||||
self._merge_config(default_config, file_config)
|
||||
except Exception as e:
|
||||
print(f"加载配置文件失败: {e}")
|
||||
|
||||
|
||||
return default_config
|
||||
|
||||
|
||||
def _merge_config(self, default: Dict[str, Any], custom: Dict[str, Any]) -> None:
|
||||
"""递归合并配置"""
|
||||
for key, value in custom.items():
|
||||
@ -164,7 +274,7 @@ class APIConfig:
|
||||
self._merge_config(default[key], value)
|
||||
else:
|
||||
default[key] = value
|
||||
|
||||
|
||||
def get_api_config(self, provider: str) -> Optional[Dict[str, Any]]:
|
||||
"""
|
||||
获取指定提供商的API配置
|
||||
@ -176,7 +286,7 @@ class APIConfig:
|
||||
Optional[Dict[str, Any]]: API配置信息
|
||||
"""
|
||||
return self.config.get(provider)
|
||||
|
||||
|
||||
def get_endpoint_config(self, provider: str, endpoint: str) -> Optional[Dict[str, Any]]:
|
||||
"""
|
||||
获取指定端点的配置
|
||||
@ -192,7 +302,7 @@ class APIConfig:
|
||||
if api_config and 'endpoints' in api_config:
|
||||
return api_config['endpoints'].get(endpoint)
|
||||
return None
|
||||
|
||||
|
||||
def get_api_key(self, provider: str) -> Optional[str]:
|
||||
"""
|
||||
获取API密钥
|
||||
@ -205,7 +315,7 @@ class APIConfig:
|
||||
"""
|
||||
api_config = self.get_api_config(provider)
|
||||
return api_config.get('api_key') if api_config else None
|
||||
|
||||
|
||||
def get_base_url(self, provider: str) -> Optional[str]:
|
||||
"""
|
||||
获取基础URL
|
||||
@ -218,7 +328,7 @@ class APIConfig:
|
||||
"""
|
||||
api_config = self.get_api_config(provider)
|
||||
return api_config.get('base_url') if api_config else None
|
||||
|
||||
|
||||
def set_api_key(self, provider: str, api_key: str) -> None:
|
||||
"""
|
||||
设置API密钥
|
||||
@ -230,15 +340,15 @@ class APIConfig:
|
||||
if provider not in self.config:
|
||||
self.config[provider] = {}
|
||||
self.config[provider]['api_key'] = api_key
|
||||
|
||||
def add_endpoint(self,
|
||||
provider: str,
|
||||
endpoint_name: str,
|
||||
path: str,
|
||||
method: str = 'POST',
|
||||
description: str = '',
|
||||
required_params: list = None,
|
||||
optional_params: list = None) -> None:
|
||||
|
||||
def add_endpoint(self,
|
||||
provider: str,
|
||||
endpoint_name: str,
|
||||
path: str,
|
||||
method: str = 'POST',
|
||||
description: str = '',
|
||||
required_params: list = None,
|
||||
optional_params: list = None) -> None:
|
||||
"""
|
||||
添加新的API端点
|
||||
|
||||
@ -253,10 +363,10 @@ class APIConfig:
|
||||
"""
|
||||
if provider not in self.config:
|
||||
self.config[provider] = {'endpoints': {}}
|
||||
|
||||
|
||||
if 'endpoints' not in self.config[provider]:
|
||||
self.config[provider]['endpoints'] = {}
|
||||
|
||||
|
||||
self.config[provider]['endpoints'][endpoint_name] = {
|
||||
'path': path,
|
||||
'method': method.upper(),
|
||||
@ -264,27 +374,27 @@ class APIConfig:
|
||||
'required_params': required_params or [],
|
||||
'optional_params': optional_params or []
|
||||
}
|
||||
|
||||
|
||||
def save_config(self) -> None:
|
||||
"""保存配置到文件"""
|
||||
try:
|
||||
# 创建目录(如果不存在)
|
||||
os.makedirs(os.path.dirname(self.config_file), exist_ok=True)
|
||||
|
||||
|
||||
with open(self.config_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(self.config, f, indent=2, ensure_ascii=False)
|
||||
print(f"配置已保存到: {self.config_file}")
|
||||
except Exception as e:
|
||||
print(f"保存配置失败: {e}")
|
||||
|
||||
|
||||
def get_common_settings(self) -> Dict[str, Any]:
|
||||
"""获取通用设置"""
|
||||
return self.config.get('common_settings', {})
|
||||
|
||||
|
||||
def list_providers(self) -> list:
|
||||
"""列出所有API提供商"""
|
||||
return [key for key in self.config.keys() if key != 'common_settings']
|
||||
|
||||
|
||||
def list_endpoints(self, provider: str) -> list:
|
||||
"""
|
||||
列出指定提供商的所有端点
|
||||
@ -302,4 +412,4 @@ class APIConfig:
|
||||
|
||||
|
||||
# 创建全局配置实例
|
||||
api_config = APIConfig()
|
||||
api_config = APIConfig()
|
||||
|
||||
@ -153,13 +153,13 @@ class UniversalAPIManager:
|
||||
if api_key:
|
||||
prepared_params['token'] = api_key
|
||||
|
||||
<<<<<<< HEAD
|
||||
elif provider == 'dajiala':
|
||||
# 微信指数
|
||||
# JustOneAPI需要token参数
|
||||
api_key = provider_config.get('api_key')
|
||||
if api_key:
|
||||
prepared_params['key'] = api_key
|
||||
=======
|
||||
|
||||
elif provider == 'jizhiliao':
|
||||
# 极致聊接口需要 key,默认从配置读取
|
||||
if 'key' not in prepared_params or not prepared_params['key']:
|
||||
@ -170,7 +170,7 @@ class UniversalAPIManager:
|
||||
default_verifycode = provider_config.get('verifycode')
|
||||
if default_verifycode is not None:
|
||||
prepared_params['verifycode'] = default_verifycode
|
||||
>>>>>>> b46c1a349b8413b2daf4a02b862ddcfde1953d76
|
||||
|
||||
|
||||
return prepared_params
|
||||
|
||||
@ -257,6 +257,23 @@ class UniversalAPIManager:
|
||||
}
|
||||
return self.make_request('dajiala', 'web_search', data)
|
||||
|
||||
def video_views(self,platform_type,video_id):
|
||||
"""
|
||||
平台视频播放量
|
||||
args:
|
||||
platform_type: douyin\bilibili\kuaishou
|
||||
"""
|
||||
if platform_type == 'bilibili':
|
||||
params = {
|
||||
"bvid": video_id
|
||||
}
|
||||
else:
|
||||
params = {
|
||||
"videoId": video_id
|
||||
}
|
||||
|
||||
return self.make_request('justoneapi', 'platform_type', params)
|
||||
|
||||
|
||||
# 站长之家API的便捷方法
|
||||
def query_copyright_software(self, company_name: str, chinaz_ver: str = "1") -> Dict[str, Any]:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user