fix webhook image
This commit is contained in:
@ -11,7 +11,7 @@ from app.core.meta import MetaBase
|
|||||||
from app.core.module import ModuleManager
|
from app.core.module import ModuleManager
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
from app.schemas import TransferInfo, TransferTorrent, ExistMediaInfo, DownloadingTorrent
|
from app.schemas import TransferInfo, TransferTorrent, ExistMediaInfo, DownloadingTorrent
|
||||||
from app.schemas.types import TorrentStatus, MediaType
|
from app.schemas.types import TorrentStatus, MediaType, MediaImageType
|
||||||
from app.utils.singleton import AbstractSingleton, Singleton
|
from app.utils.singleton import AbstractSingleton, Singleton
|
||||||
|
|
||||||
|
|
||||||
@ -84,13 +84,28 @@ class ChainBase(AbstractSingleton, metaclass=Singleton):
|
|||||||
"""
|
"""
|
||||||
return self.run_module("recognize_media", meta=meta, mtype=mtype, tmdbid=tmdbid)
|
return self.run_module("recognize_media", meta=meta, mtype=mtype, tmdbid=tmdbid)
|
||||||
|
|
||||||
def obtain_image(self, mediainfo: MediaInfo) -> Optional[MediaInfo]:
|
def obtain_images(self, mediainfo: MediaInfo) -> Optional[MediaInfo]:
|
||||||
"""
|
"""
|
||||||
获取图片
|
补充抓取媒体信息图片
|
||||||
:param mediainfo: 识别的媒体信息
|
:param mediainfo: 识别的媒体信息
|
||||||
:return: 更新后的媒体信息
|
:return: 更新后的媒体信息
|
||||||
"""
|
"""
|
||||||
return self.run_module("obtain_image", mediainfo=mediainfo)
|
return self.run_module("obtain_images", mediainfo=mediainfo)
|
||||||
|
|
||||||
|
def obtain_specific_image(self, mediaid: Union[str, int], mtype: MediaType,
|
||||||
|
image_type: MediaImageType, image_prefix: str = None,
|
||||||
|
season: int = None, episode: int = None) -> Optional[str]:
|
||||||
|
"""
|
||||||
|
获取指定媒体信息图片,返回图片地址
|
||||||
|
:param mediaid: 媒体ID
|
||||||
|
:param mtype: 媒体类型
|
||||||
|
:param image_type: 图片类型
|
||||||
|
:param image_prefix: 图片前缀
|
||||||
|
:param season: 季
|
||||||
|
:param episode: 集
|
||||||
|
"""
|
||||||
|
return self.run_module("obtain_specific_image", mediaid=mediaid, mtype=mtype,
|
||||||
|
image_type=image_type, season=season, episode=episode)
|
||||||
|
|
||||||
def douban_info(self, doubanid: str) -> Optional[dict]:
|
def douban_info(self, doubanid: str) -> Optional[dict]:
|
||||||
"""
|
"""
|
||||||
|
@ -31,7 +31,7 @@ class MediaChain(ChainBase):
|
|||||||
return Context(meta=metainfo)
|
return Context(meta=metainfo)
|
||||||
logger.info(f'{title} 识别到媒体信息:{mediainfo.type.value} {mediainfo.title_year}')
|
logger.info(f'{title} 识别到媒体信息:{mediainfo.type.value} {mediainfo.title_year}')
|
||||||
# 更新媒体图片
|
# 更新媒体图片
|
||||||
self.obtain_image(mediainfo=mediainfo)
|
self.obtain_images(mediainfo=mediainfo)
|
||||||
# 返回上下文
|
# 返回上下文
|
||||||
return Context(meta=metainfo, mediainfo=mediainfo, title=title, subtitle=subtitle)
|
return Context(meta=metainfo, mediainfo=mediainfo, title=title, subtitle=subtitle)
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ class SubscribeChain(ChainBase):
|
|||||||
logger.warn(f'未识别到媒体信息,标题:{title},tmdbid:{tmdbid}')
|
logger.warn(f'未识别到媒体信息,标题:{title},tmdbid:{tmdbid}')
|
||||||
return False
|
return False
|
||||||
# 更新媒体图片
|
# 更新媒体图片
|
||||||
self.obtain_image(mediainfo=mediainfo)
|
self.obtain_images(mediainfo=mediainfo)
|
||||||
# 总集数
|
# 总集数
|
||||||
if mediainfo.type == MediaType.TV:
|
if mediainfo.type == MediaType.TV:
|
||||||
if not season:
|
if not season:
|
||||||
|
@ -116,7 +116,7 @@ class TransferChain(ChainBase):
|
|||||||
mediainfo = arg_mediainfo
|
mediainfo = arg_mediainfo
|
||||||
logger.info(f"{torrent.title} 识别为:{mediainfo.type.value} {mediainfo.title_year}")
|
logger.info(f"{torrent.title} 识别为:{mediainfo.type.value} {mediainfo.title_year}")
|
||||||
# 更新媒体图片
|
# 更新媒体图片
|
||||||
self.obtain_image(mediainfo=mediainfo)
|
self.obtain_images(mediainfo=mediainfo)
|
||||||
# 转移
|
# 转移
|
||||||
transferinfo: TransferInfo = self.transfer(mediainfo=mediainfo, path=torrent.path)
|
transferinfo: TransferInfo = self.transfer(mediainfo=mediainfo, path=torrent.path)
|
||||||
if not transferinfo or not transferinfo.target_path:
|
if not transferinfo or not transferinfo.target_path:
|
||||||
|
@ -3,7 +3,7 @@ from typing import Any
|
|||||||
|
|
||||||
from app.chain import ChainBase
|
from app.chain import ChainBase
|
||||||
from app.utils.http import WebUtils
|
from app.utils.http import WebUtils
|
||||||
from app.schemas.types import EventType
|
from app.schemas.types import EventType, MediaImageType, MediaType
|
||||||
|
|
||||||
|
|
||||||
class WebhookChain(ChainBase):
|
class WebhookChain(ChainBase):
|
||||||
@ -69,14 +69,27 @@ class WebhookChain(ChainBase):
|
|||||||
message_texts.append(f"剧情:{event_info.get('overview')}")
|
message_texts.append(f"剧情:{event_info.get('overview')}")
|
||||||
message_texts.append(f"时间:{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))}")
|
message_texts.append(f"时间:{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))}")
|
||||||
|
|
||||||
# 消息图片
|
|
||||||
if not event_info.get("image_url"):
|
|
||||||
image_url = _webhook_images.get(event_info.get("channel"))
|
|
||||||
else:
|
|
||||||
image_url = event_info.get("image_url")
|
|
||||||
|
|
||||||
# 消息内容
|
# 消息内容
|
||||||
message_content = "\n".join(message_texts)
|
message_content = "\n".join(message_texts)
|
||||||
|
|
||||||
|
# 消息图片
|
||||||
|
image_url = event_info.get("image_url")
|
||||||
|
# 查询剧集图片
|
||||||
|
if event_info.get("tmdb_id") \
|
||||||
|
and event_info.get("season_id"):
|
||||||
|
mtype = MediaType.TV if event_info.get("item_type") == "TV" else MediaType.MOVIE
|
||||||
|
specific_image = self.obtain_specific_image(
|
||||||
|
mediaid=event_info.get("tmdb_id"),
|
||||||
|
mtype=mtype,
|
||||||
|
image_type=MediaImageType.Backdrop,
|
||||||
|
season=event_info.get("season_id"),
|
||||||
|
episode=event_info.get("episode_id")
|
||||||
|
)
|
||||||
|
if specific_image:
|
||||||
|
image_url = specific_image
|
||||||
|
# 使用默认图片
|
||||||
|
if not image_url:
|
||||||
|
image_url = _webhook_images.get(event_info.get("channel"))
|
||||||
|
|
||||||
# 发送消息
|
# 发送消息
|
||||||
self.post_message(title=message_title, text=message_content, image=image_url)
|
self.post_message(title=message_title, text=message_content, image=image_url)
|
||||||
|
@ -27,7 +27,7 @@ class FanartModule(_ModuleBase):
|
|||||||
def init_setting(self) -> Tuple[str, Union[str, bool]]:
|
def init_setting(self) -> Tuple[str, Union[str, bool]]:
|
||||||
return "FANART_API_KEY", True
|
return "FANART_API_KEY", True
|
||||||
|
|
||||||
def obtain_image(self, mediainfo: MediaInfo) -> Optional[MediaInfo]:
|
def obtain_images(self, mediainfo: MediaInfo) -> Optional[MediaInfo]:
|
||||||
"""
|
"""
|
||||||
获取图片
|
获取图片
|
||||||
:param mediainfo: 识别的媒体信息
|
:param mediainfo: 识别的媒体信息
|
||||||
@ -69,7 +69,7 @@ class FanartModule(_ModuleBase):
|
|||||||
else:
|
else:
|
||||||
image_url = cls._tv_url % queryid
|
image_url = cls._tv_url % queryid
|
||||||
try:
|
try:
|
||||||
ret = RequestUtils(proxies=cls._proxies, timeout=5).get_res(image_url)
|
ret = RequestUtils(proxies=cls._proxies, timeout=10).get_res(image_url)
|
||||||
if ret:
|
if ret:
|
||||||
return ret.json()
|
return ret.json()
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -15,7 +15,7 @@ from app.modules.themoviedb.tmdb_cache import TmdbCache
|
|||||||
from app.utils.dom import DomUtils
|
from app.utils.dom import DomUtils
|
||||||
from app.utils.http import RequestUtils
|
from app.utils.http import RequestUtils
|
||||||
from app.utils.system import SystemUtils
|
from app.utils.system import SystemUtils
|
||||||
from app.schemas.types import MediaType
|
from app.schemas.types import MediaType, MediaImageType
|
||||||
|
|
||||||
|
|
||||||
class TheMovieDbModule(_ModuleBase):
|
class TheMovieDbModule(_ModuleBase):
|
||||||
@ -563,3 +563,37 @@ class TheMovieDbModule(_ModuleBase):
|
|||||||
定时任务,每10分钟调用一次
|
定时任务,每10分钟调用一次
|
||||||
"""
|
"""
|
||||||
self.cache.save()
|
self.cache.save()
|
||||||
|
|
||||||
|
def obtain_specific_image(self, mediaid: Union[str, int], mtype: MediaType,
|
||||||
|
image_type: MediaImageType, image_prefix: str = "w500",
|
||||||
|
season: int = None, episode: int = None) -> Optional[str]:
|
||||||
|
"""
|
||||||
|
获取指定媒体信息图片,返回图片地址
|
||||||
|
:param mediaid: 媒体ID
|
||||||
|
:param mtype: 媒体类型
|
||||||
|
:param image_type: 图片类型
|
||||||
|
:param image_prefix: 图片前缀
|
||||||
|
:param season: 季
|
||||||
|
:param episode: 集
|
||||||
|
"""
|
||||||
|
if not str(mediaid).isdigit():
|
||||||
|
return None
|
||||||
|
# 图片相对路径
|
||||||
|
image_path = None
|
||||||
|
image_prefix = image_prefix or "w500"
|
||||||
|
if not season and not episode:
|
||||||
|
tmdbinfo = self.tmdb.get_info(mtype=mtype, tmdbid=int(mediaid))
|
||||||
|
if tmdbinfo:
|
||||||
|
image_path = tmdbinfo.get(image_type.value)
|
||||||
|
elif season and episode:
|
||||||
|
episodeinfo = self.tmdb.get_tv_episode_detail(tmdbid=int(mediaid), season=season, episode=episode)
|
||||||
|
if episodeinfo:
|
||||||
|
image_path = episodeinfo.get("still_path")
|
||||||
|
elif season:
|
||||||
|
seasoninfo = self.tmdb.get_tv_season_detail(tmdbid=int(mediaid), season=season)
|
||||||
|
if seasoninfo:
|
||||||
|
image_path = seasoninfo.get(image_type.value)
|
||||||
|
|
||||||
|
if image_path:
|
||||||
|
return f"https://image.tmdb.org/t/p/{image_prefix}{image_path}"
|
||||||
|
return None
|
||||||
|
@ -57,3 +57,9 @@ class ProgressKey(Enum):
|
|||||||
Search = "search"
|
Search = "search"
|
||||||
# 转移
|
# 转移
|
||||||
FileTransfer = "filetransfer"
|
FileTransfer = "filetransfer"
|
||||||
|
|
||||||
|
|
||||||
|
# 媒体图片类型
|
||||||
|
class MediaImageType(Enum):
|
||||||
|
Poster = "poster"
|
||||||
|
Backdrop = "backdrop"
|
||||||
|
Reference in New Issue
Block a user