mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 07:27:15 +08:00
Merge pull request #3598 from InfinityPacer/feature/recommend
This commit is contained in:
+18
-2
@@ -1,3 +1,4 @@
|
|||||||
|
import inspect
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from typing import Any, Callable
|
from typing import Any, Callable
|
||||||
|
|
||||||
@@ -29,8 +30,18 @@ def cached_with_empty_check(func: Callable):
|
|||||||
|
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
|
signature = inspect.signature(func)
|
||||||
|
resolved_kwargs = {}
|
||||||
|
# 获取默认值并结合传递的参数(如果有)
|
||||||
|
for param, value in signature.parameters.items():
|
||||||
|
if param in kwargs:
|
||||||
|
# 使用显式传递的参数
|
||||||
|
resolved_kwargs[param] = kwargs[param]
|
||||||
|
elif value.default is not inspect.Parameter.empty:
|
||||||
|
# 没有传递参数时使用默认值
|
||||||
|
resolved_kwargs[param] = value.default
|
||||||
# 使用 cachetools 缓存,构造缓存键
|
# 使用 cachetools 缓存,构造缓存键
|
||||||
cache_key = hashkey(*args, **kwargs)
|
cache_key = f"{func.__name__}_{hashkey(*args, **resolved_kwargs)}"
|
||||||
if cache_key in recommend_cache:
|
if cache_key in recommend_cache:
|
||||||
return recommend_cache[cache_key]
|
return recommend_cache[cache_key]
|
||||||
result = func(*args, **kwargs)
|
result = func(*args, **kwargs)
|
||||||
@@ -58,10 +69,14 @@ class RecommendChain(ChainBase, metaclass=Singleton):
|
|||||||
"""
|
"""
|
||||||
刷新推荐
|
刷新推荐
|
||||||
"""
|
"""
|
||||||
|
logger.debug("Starting to refresh Recommend data.")
|
||||||
|
recommend_cache.clear()
|
||||||
|
logger.debug("Recommend Cache has been cleared.")
|
||||||
self.tmdb_movies()
|
self.tmdb_movies()
|
||||||
self.tmdb_tvs()
|
self.tmdb_tvs()
|
||||||
self.tmdb_trending()
|
self.tmdb_trending()
|
||||||
self.bangumi_calendar()
|
self.bangumi_calendar()
|
||||||
|
self.douban_movie_showing()
|
||||||
self.douban_movies()
|
self.douban_movies()
|
||||||
self.douban_tvs()
|
self.douban_tvs()
|
||||||
self.douban_movie_top250()
|
self.douban_movie_top250()
|
||||||
@@ -70,6 +85,7 @@ class RecommendChain(ChainBase, metaclass=Singleton):
|
|||||||
self.douban_tv_animation()
|
self.douban_tv_animation()
|
||||||
self.douban_movie_hot()
|
self.douban_movie_hot()
|
||||||
self.douban_tv_hot()
|
self.douban_tv_hot()
|
||||||
|
logger.debug("Recommend data refresh completed.")
|
||||||
|
|
||||||
@log_execution_time(logger=logger)
|
@log_execution_time(logger=logger)
|
||||||
@cached_with_empty_check
|
@cached_with_empty_check
|
||||||
@@ -88,7 +104,7 @@ class RecommendChain(ChainBase, metaclass=Singleton):
|
|||||||
@log_execution_time(logger=logger)
|
@log_execution_time(logger=logger)
|
||||||
@cached_with_empty_check
|
@cached_with_empty_check
|
||||||
def tmdb_tvs(self, sort_by: str = "popularity.desc", with_genres: str = "",
|
def tmdb_tvs(self, sort_by: str = "popularity.desc", with_genres: str = "",
|
||||||
with_original_language: str = "", page: int = 1) -> Any:
|
with_original_language: str = "zh|en|ja|ko", page: int = 1) -> Any:
|
||||||
"""
|
"""
|
||||||
TMDB热门电视剧
|
TMDB热门电视剧
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ from apscheduler.schedulers.background import BackgroundScheduler
|
|||||||
from app import schemas
|
from app import schemas
|
||||||
from app.chain import ChainBase
|
from app.chain import ChainBase
|
||||||
from app.chain.mediaserver import MediaServerChain
|
from app.chain.mediaserver import MediaServerChain
|
||||||
|
from app.chain.recommend import RecommendChain
|
||||||
from app.chain.site import SiteChain
|
from app.chain.site import SiteChain
|
||||||
from app.chain.subscribe import SubscribeChain
|
from app.chain.subscribe import SubscribeChain
|
||||||
from app.chain.tmdb import TmdbChain
|
from app.chain.tmdb import TmdbChain
|
||||||
@@ -121,6 +122,11 @@ class Scheduler(metaclass=Singleton):
|
|||||||
"name": "站点数据刷新",
|
"name": "站点数据刷新",
|
||||||
"func": SiteChain().refresh_userdatas,
|
"func": SiteChain().refresh_userdatas,
|
||||||
"running": False,
|
"running": False,
|
||||||
|
},
|
||||||
|
"recommend_refresh": {
|
||||||
|
"name": "推荐缓存",
|
||||||
|
"func": RecommendChain().refresh_recommend,
|
||||||
|
"running": False,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,6 +316,19 @@ class Scheduler(metaclass=Singleton):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# 推荐缓存
|
||||||
|
self._scheduler.add_job(
|
||||||
|
self.start,
|
||||||
|
"interval",
|
||||||
|
id="recommend_refresh",
|
||||||
|
name="推荐缓存",
|
||||||
|
hours=6,
|
||||||
|
next_run_time=datetime.now(pytz.timezone(settings.TZ)) + timedelta(seconds=3),
|
||||||
|
kwargs={
|
||||||
|
'job_id': 'recommend_refresh'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
self.init_plugin_jobs()
|
self.init_plugin_jobs()
|
||||||
|
|
||||||
# 打印服务
|
# 打印服务
|
||||||
|
|||||||
Reference in New Issue
Block a user