fix actions

This commit is contained in:
jxxghp
2025-02-28 11:15:24 +08:00
parent f8ed16666c
commit cf62ad5e8e
14 changed files with 174 additions and 131 deletions
+74 -62
View File
@@ -3,6 +3,7 @@ from typing import List
from pydantic import Field
from app.actions import BaseAction
from app.chain.recommend import RecommendChain
from app.schemas import ActionParams, ActionContext
from app.core.config import settings
from app.core.event import eventmanager
@@ -24,65 +25,68 @@ class FetchMediasAction(BaseAction):
获取媒体数据
"""
__inner_sources = [
{
"api_path": 'recommend/tmdb_trending',
"name": '流行趋势',
},
{
"api_path": 'recommend/douban_showing',
"name": '正在热映',
},
{
"api_path": 'bangumi/calendar',
"name": 'Bangumi每日放送',
},
{
"api_path": 'recommend/tmdb_movies',
"name": 'TMDB热门电影',
},
{
"api_path": 'recommend/tmdb_tvs?with_original_language=zh|en|ja|ko',
"name": 'TMDB热门电视剧',
},
{
"api_path": 'recommend/douban_movie_hot',
"name": '豆瓣热门电影',
},
{
"api_path": 'recommend/douban_tv_hot',
"name": '豆瓣热门电视剧',
},
{
"api_path": 'recommend/douban_tv_animation',
"name": '豆瓣热门动漫',
},
{
"api_path": 'recommend/douban_movies',
"name": '豆瓣最新电影',
},
{
"api_path": 'recommend/douban_tvs',
"name": '豆瓣最新电视剧',
},
{
"api_path": 'recommend/douban_movie_top250',
"name": '豆瓣电影TOP250',
},
{
"api_path": 'recommend/douban_tv_weekly_chinese',
"name": '豆瓣国产剧集榜',
},
{
"api_path": 'recommend/douban_tv_weekly_global',
"name": '豆瓣全球剧集榜',
}
]
__inner_sources = []
__medias = []
def __init__(self):
super().__init__()
self.__inner_sources = [
{
"func": RecommendChain().tmdb_trending,
"name": '流行趋势',
},
{
"func": RecommendChain().douban_movie_showing,
"name": '正在热映',
},
{
"func": RecommendChain().bangumi_calendar,
"name": 'Bangumi每日放送',
},
{
"func": RecommendChain().tmdb_movies,
"name": 'TMDB热门电影',
},
{
"func": RecommendChain().tmdb_tvs,
"name": 'TMDB热门电视剧',
},
{
"func": RecommendChain().douban_movie_hot,
"name": '豆瓣热门电影',
},
{
"func": RecommendChain().douban_tv_hot,
"name": '豆瓣热门电视剧',
},
{
"func": RecommendChain().douban_tv_animation,
"name": '豆瓣热门动漫',
},
{
"func": RecommendChain().douban_movies,
"name": '豆瓣最新电影',
},
{
"func": RecommendChain().douban_tvs,
"name": '豆瓣最新电视剧',
},
{
"func": RecommendChain().douban_movie_top250,
"name": '豆瓣电影TOP250',
},
{
"func": RecommendChain().douban_tv_weekly_chinese,
"name": '豆瓣国产剧集榜',
},
{
"func": RecommendChain().douban_tv_weekly_global,
"name": '豆瓣全球剧集榜',
}
]
# 广播事件,请示额外的推荐数据源支持
event_data = RecommendSourceEventData()
event = eventmanager.send_event(ChainEventType.RecommendSource, event_data)
@@ -92,16 +96,19 @@ class FetchMediasAction(BaseAction):
if event_data.extra_sources:
self.__inner_sources.extend([s.dict() for s in event_data.extra_sources])
@classmethod
@property
def name(self) -> str:
def name(cls) -> str:
return "获取媒体数据"
@classmethod
@property
def description(self) -> str:
def description(cls) -> str:
return "获取榜单等媒体数据列表"
@classmethod
@property
def data(self) -> dict:
def data(cls) -> dict:
return FetchMediasParams().dict()
@property
@@ -127,11 +134,16 @@ class FetchMediasAction(BaseAction):
if not source:
continue
logger.info(f"获取媒体数据 {source} ...")
# 调用内部API获取数据
api_url = f"http://127.0.0.1:{settings.PORT}/api/v1/{source['api_path']}?token={settings.API_TOKEN}"
res = RequestUtils(timeout=15).post_res(api_url)
if res:
results = res.json()
results = []
if source.get("func"):
results = source['func']()
else:
# 调用内部API获取数据
api_url = f"http://127.0.0.1:{settings.PORT}/api/v1/{source['api_path']}?token={settings.API_TOKEN}"
res = RequestUtils(timeout=15).post_res(api_url)
if res:
results = res.json()
if results:
logger.info(f"{name} 获取到 {len(results)} 条数据")
self.__medias.extend([MediaInfo(**r) for r in results])
else: