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.log import logger
|
||||
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
|
||||
|
||||
|
||||
@ -84,13 +84,28 @@ class ChainBase(AbstractSingleton, metaclass=Singleton):
|
||||
"""
|
||||
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: 识别的媒体信息
|
||||
: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]:
|
||||
"""
|
||||
|
@ -31,7 +31,7 @@ class MediaChain(ChainBase):
|
||||
return Context(meta=metainfo)
|
||||
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)
|
||||
|
||||
|
@ -61,7 +61,7 @@ class SubscribeChain(ChainBase):
|
||||
logger.warn(f'未识别到媒体信息,标题:{title},tmdbid:{tmdbid}')
|
||||
return False
|
||||
# 更新媒体图片
|
||||
self.obtain_image(mediainfo=mediainfo)
|
||||
self.obtain_images(mediainfo=mediainfo)
|
||||
# 总集数
|
||||
if mediainfo.type == MediaType.TV:
|
||||
if not season:
|
||||
|
@ -116,7 +116,7 @@ class TransferChain(ChainBase):
|
||||
mediainfo = arg_mediainfo
|
||||
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)
|
||||
if not transferinfo or not transferinfo.target_path:
|
||||
|
@ -3,7 +3,7 @@ from typing import Any
|
||||
|
||||
from app.chain import ChainBase
|
||||
from app.utils.http import WebUtils
|
||||
from app.schemas.types import EventType
|
||||
from app.schemas.types import EventType, MediaImageType, MediaType
|
||||
|
||||
|
||||
class WebhookChain(ChainBase):
|
||||
@ -69,14 +69,27 @@ class WebhookChain(ChainBase):
|
||||
message_texts.append(f"剧情:{event_info.get('overview')}")
|
||||
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)
|
||||
|
||||
# 消息图片
|
||||
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)
|
||||
|
Reference in New Issue
Block a user