mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-06 07:56:52 +08:00
fix #4276
This commit is contained in:
@@ -11,7 +11,7 @@ from app.chain.mediaserver import MediaServerChain
|
|||||||
from app.core import security
|
from app.core import security
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.helper.sites import SitesHelper
|
from app.helper.sites import SitesHelper
|
||||||
from app.utils.web import WebUtils
|
from app.helper.wallpaper import WallpaperHelper
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@@ -55,11 +55,11 @@ def wallpaper() -> Any:
|
|||||||
获取登录页面电影海报
|
获取登录页面电影海报
|
||||||
"""
|
"""
|
||||||
if settings.WALLPAPER == "bing":
|
if settings.WALLPAPER == "bing":
|
||||||
url = WebUtils.get_bing_wallpaper()
|
url = WallpaperHelper().get_bing_wallpaper()
|
||||||
elif settings.WALLPAPER == "mediaserver":
|
elif settings.WALLPAPER == "mediaserver":
|
||||||
url = MediaServerChain().get_latest_wallpaper()
|
url = MediaServerChain().get_latest_wallpaper()
|
||||||
elif settings.WALLPAPER == "customize":
|
elif settings.WALLPAPER == "customize":
|
||||||
url = WebUtils.get_customize_wallpapers()[0]
|
url = WallpaperHelper().get_customize_wallpaper()
|
||||||
else:
|
else:
|
||||||
url = TmdbChain().get_random_wallpager()
|
url = TmdbChain().get_random_wallpager()
|
||||||
if url:
|
if url:
|
||||||
@@ -76,12 +76,12 @@ def wallpapers() -> Any:
|
|||||||
获取登录页面电影海报
|
获取登录页面电影海报
|
||||||
"""
|
"""
|
||||||
if settings.WALLPAPER == "bing":
|
if settings.WALLPAPER == "bing":
|
||||||
return WebUtils.get_bing_wallpapers()
|
return WallpaperHelper().get_bing_wallpapers()
|
||||||
elif settings.WALLPAPER == "mediaserver":
|
elif settings.WALLPAPER == "mediaserver":
|
||||||
return MediaServerChain().get_latest_wallpapers()
|
return MediaServerChain().get_latest_wallpapers()
|
||||||
elif settings.WALLPAPER == "tmdb":
|
elif settings.WALLPAPER == "tmdb":
|
||||||
return TmdbChain().get_trending_wallpapers()
|
return TmdbChain().get_trending_wallpapers()
|
||||||
elif settings.WALLPAPER == "customize":
|
elif settings.WALLPAPER == "customize":
|
||||||
return WebUtils.get_customize_wallpapers()
|
return WallpaperHelper().get_customize_wallpapers()
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|||||||
+3
-2
@@ -89,6 +89,8 @@ class ConfigModel(BaseModel):
|
|||||||
PROXY_HOST: Optional[str] = None
|
PROXY_HOST: Optional[str] = None
|
||||||
# 登录页面电影海报,tmdb/bing/mediaserver
|
# 登录页面电影海报,tmdb/bing/mediaserver
|
||||||
WALLPAPER: str = "tmdb"
|
WALLPAPER: str = "tmdb"
|
||||||
|
# 自定义壁纸api地址
|
||||||
|
CUSTOMIZE_WALLPAPER_API_URL: Optional[str] = None
|
||||||
# 媒体搜索来源 themoviedb/douban/bangumi,多个用,分隔
|
# 媒体搜索来源 themoviedb/douban/bangumi,多个用,分隔
|
||||||
SEARCH_SOURCE: str = "themoviedb,douban,bangumi"
|
SEARCH_SOURCE: str = "themoviedb,douban,bangumi"
|
||||||
# 媒体识别来源 themoviedb/douban
|
# 媒体识别来源 themoviedb/douban
|
||||||
@@ -268,8 +270,7 @@ class ConfigModel(BaseModel):
|
|||||||
TOKENIZED_SEARCH: bool = False
|
TOKENIZED_SEARCH: bool = False
|
||||||
# 为指定默认字幕添加.default后缀
|
# 为指定默认字幕添加.default后缀
|
||||||
DEFAULT_SUB: Optional[str] = "zh-cn"
|
DEFAULT_SUB: Optional[str] = "zh-cn"
|
||||||
# 自定义壁纸api地址
|
|
||||||
CUSTOMIZE_WALLPAPER_API_URL: Optional[str] = None
|
|
||||||
|
|
||||||
class Settings(BaseSettings, ConfigModel, LogConfigModel):
|
class Settings(BaseSettings, ConfigModel, LogConfigModel):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
from typing import Optional, List
|
||||||
|
|
||||||
|
from app.core.cache import cached
|
||||||
|
from app.core.config import settings
|
||||||
|
from app.utils.http import RequestUtils
|
||||||
|
from app.utils.singleton import Singleton
|
||||||
|
|
||||||
|
|
||||||
|
class WallpaperHelper(metaclass=Singleton):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.req = RequestUtils(timeout=5)
|
||||||
|
|
||||||
|
@cached(maxsize=1, ttl=3600)
|
||||||
|
def get_bing_wallpaper(self) -> Optional[str]:
|
||||||
|
"""
|
||||||
|
获取Bing每日壁纸
|
||||||
|
"""
|
||||||
|
url = "https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1"
|
||||||
|
resp = self.req.get_res(url)
|
||||||
|
if resp and resp.status_code == 200:
|
||||||
|
try:
|
||||||
|
result = resp.json()
|
||||||
|
if isinstance(result, dict):
|
||||||
|
for image in result.get('images') or []:
|
||||||
|
return f"https://cn.bing.com{image.get('url')}" if 'url' in image else ''
|
||||||
|
except Exception as err:
|
||||||
|
print(str(err))
|
||||||
|
return None
|
||||||
|
|
||||||
|
@cached(maxsize=1, ttl=3600)
|
||||||
|
def get_bing_wallpapers(self, num: int = 7) -> List[str]:
|
||||||
|
"""
|
||||||
|
获取7天的Bing每日壁纸
|
||||||
|
"""
|
||||||
|
url = f"https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n={num}"
|
||||||
|
resp = self.req.get_res(url)
|
||||||
|
if resp and resp.status_code == 200:
|
||||||
|
try:
|
||||||
|
result = resp.json()
|
||||||
|
if isinstance(result, dict):
|
||||||
|
return [f"https://cn.bing.com{image.get('url')}" for image in result.get('images') or []]
|
||||||
|
except Exception as err:
|
||||||
|
print(str(err))
|
||||||
|
return []
|
||||||
|
|
||||||
|
@cached(maxsize=1, ttl=3600)
|
||||||
|
def get_customize_wallpaper(self) -> Optional[str]:
|
||||||
|
"""
|
||||||
|
获取自定义壁纸api壁纸
|
||||||
|
"""
|
||||||
|
wallpaper_list = self.get_customize_wallpapers()
|
||||||
|
if wallpaper_list:
|
||||||
|
return wallpaper_list[0]
|
||||||
|
return None
|
||||||
|
|
||||||
|
@cached(maxsize=1, ttl=3600)
|
||||||
|
def get_customize_wallpapers(self) -> List[str]:
|
||||||
|
"""
|
||||||
|
获取自定义壁纸api壁纸
|
||||||
|
"""
|
||||||
|
|
||||||
|
def find_files_with_suffixes(obj, suffixes: List[str]) -> List[str]:
|
||||||
|
"""
|
||||||
|
递归查找对象中所有包含特定后缀的文件,返回匹配的字符串列表
|
||||||
|
支持输入:字典、列表、字符串
|
||||||
|
"""
|
||||||
|
_result = []
|
||||||
|
|
||||||
|
# 处理字符串
|
||||||
|
if isinstance(obj, str):
|
||||||
|
if obj.endswith(tuple(suffixes)):
|
||||||
|
_result.append(obj)
|
||||||
|
|
||||||
|
# 处理字典
|
||||||
|
elif isinstance(obj, dict):
|
||||||
|
for value in obj.values():
|
||||||
|
_result.extend(find_files_with_suffixes(value, suffixes))
|
||||||
|
|
||||||
|
# 处理列表
|
||||||
|
elif isinstance(obj, list):
|
||||||
|
for item in obj:
|
||||||
|
_result.extend(find_files_with_suffixes(item, suffixes))
|
||||||
|
|
||||||
|
return _result
|
||||||
|
|
||||||
|
# 判断是否存在自定义壁纸api
|
||||||
|
if settings.CUSTOMIZE_WALLPAPER_API_URL:
|
||||||
|
wallpaper_list = []
|
||||||
|
resp = self.req.get_res(settings.CUSTOMIZE_WALLPAPER_API_URL)
|
||||||
|
if resp and resp.status_code == 200:
|
||||||
|
try:
|
||||||
|
result = resp.json()
|
||||||
|
if isinstance(result, list) or isinstance(result, dict) or isinstance(result, str):
|
||||||
|
wallpaper_list = find_files_with_suffixes(result, settings.SECURITY_IMAGE_SUFFIXES)
|
||||||
|
except Exception as err:
|
||||||
|
print(str(err))
|
||||||
|
return wallpaper_list
|
||||||
|
else:
|
||||||
|
return []
|
||||||
@@ -1,7 +1,3 @@
|
|||||||
from typing import Optional, List
|
|
||||||
|
|
||||||
from app.core.cache import cached
|
|
||||||
from app.core.config import settings
|
|
||||||
from app.utils.http import RequestUtils
|
from app.utils.http import RequestUtils
|
||||||
|
|
||||||
|
|
||||||
@@ -73,87 +69,3 @@ class WebUtils:
|
|||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(str(err))
|
print(str(err))
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
@cached(maxsize=1, ttl=3600)
|
|
||||||
def get_bing_wallpaper() -> Optional[str]:
|
|
||||||
"""
|
|
||||||
获取Bing每日壁纸
|
|
||||||
"""
|
|
||||||
url = "https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1"
|
|
||||||
resp = RequestUtils(timeout=5).get_res(url)
|
|
||||||
if resp and resp.status_code == 200:
|
|
||||||
try:
|
|
||||||
result = resp.json()
|
|
||||||
if isinstance(result, dict):
|
|
||||||
for image in result.get('images') or []:
|
|
||||||
return f"https://cn.bing.com{image.get('url')}" if 'url' in image else ''
|
|
||||||
except Exception as err:
|
|
||||||
print(str(err))
|
|
||||||
return None
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
@cached(maxsize=1, ttl=3600)
|
|
||||||
def get_bing_wallpapers(num: int = 7) -> List[str]:
|
|
||||||
"""
|
|
||||||
获取7天的Bing每日壁纸
|
|
||||||
"""
|
|
||||||
url = f"https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n={num}"
|
|
||||||
resp = RequestUtils(timeout=5).get_res(url)
|
|
||||||
if resp and resp.status_code == 200:
|
|
||||||
try:
|
|
||||||
result = resp.json()
|
|
||||||
if isinstance(result, dict):
|
|
||||||
return [f"https://cn.bing.com{image.get('url')}" for image in result.get('images') or []]
|
|
||||||
except Exception as err:
|
|
||||||
print(str(err))
|
|
||||||
return []
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
@cached(maxsize=1, ttl=3600)
|
|
||||||
def get_customize_wallpapers() -> List[str]:
|
|
||||||
"""
|
|
||||||
递归查找对象中所有包含特定后缀的文件或URL,返回匹配的字符串列表
|
|
||||||
支持输入:字典、列表、字符串(普通文件路径或URL)
|
|
||||||
"""
|
|
||||||
def find_files_with_suffixes(obj, suffixes: list[str]) -> list[str]:
|
|
||||||
"""
|
|
||||||
递归查找对象中所有包含特定后缀的文件,返回匹配的字符串列表
|
|
||||||
支持输入:字典、列表、字符串
|
|
||||||
"""
|
|
||||||
result = []
|
|
||||||
|
|
||||||
# 处理字符串
|
|
||||||
if isinstance(obj, str):
|
|
||||||
if obj.endswith(tuple(suffixes)):
|
|
||||||
result.append(obj)
|
|
||||||
|
|
||||||
# 处理字典
|
|
||||||
elif isinstance(obj, dict):
|
|
||||||
for value in obj.values():
|
|
||||||
result.extend(find_files_with_suffixes(value, suffixes))
|
|
||||||
|
|
||||||
# 处理列表
|
|
||||||
elif isinstance(obj, list):
|
|
||||||
for item in obj:
|
|
||||||
result.extend(find_files_with_suffixes(item, suffixes))
|
|
||||||
|
|
||||||
return result
|
|
||||||
"""
|
|
||||||
获取自定义壁纸api壁纸
|
|
||||||
"""
|
|
||||||
# 判断是否存在自定义壁纸api
|
|
||||||
if settings.CUSTOMIZE_WALLPAPER_API_URL is not None and len(settings.CUSTOMIZE_WALLPAPER_API_URL) > 0:
|
|
||||||
url = settings.CUSTOMIZE_WALLPAPER_API_URL
|
|
||||||
wallpaper_list = []
|
|
||||||
resp = RequestUtils(timeout=5).get_res(url)
|
|
||||||
if resp and resp.status_code == 200:
|
|
||||||
try:
|
|
||||||
result = resp.json()
|
|
||||||
if isinstance(result, list) or isinstance(result, dict) or isinstance(result, str):
|
|
||||||
wallpaper_list = find_files_with_suffixes(result, settings.SECURITY_IMAGE_SUFFIXES)
|
|
||||||
except Exception as err:
|
|
||||||
print(str(err))
|
|
||||||
return wallpaper_list
|
|
||||||
else:
|
|
||||||
return []
|
|
||||||
Reference in New Issue
Block a user