From b01621049b3e64d1b63f30d6ca380c93f950b45d Mon Sep 17 00:00:00 2001 From: thsrite Date: Thu, 7 Sep 2023 10:55:01 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=96=B0=E5=A2=9E=E5=B7=B2=E5=85=A5?= =?UTF-8?q?=E5=BA=93=E5=AA=92=E4=BD=93=E6=98=AF=E5=90=A6=E8=B7=9F=E9=9A=8F?= =?UTF-8?q?TMDB=E4=BF=A1=E6=81=AF=E5=8F=98=E5=8C=96=E5=BC=80=E5=85=B3?= =?UTF-8?q?=EF=BC=8C=E5=85=B3=E9=97=AD=E5=88=99=E5=BB=B6=E7=94=A8=E5=AA=92?= =?UTF-8?q?=E4=BD=93=E5=BA=93=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + app/chain/transfer.py | 5 + app/core/config.py | 2 + app/plugins/dirmonitor/__init__.py | 292 +++++++++++++------------ app/plugins/libraryscraper/__init__.py | 8 + 5 files changed, 165 insertions(+), 143 deletions(-) diff --git a/README.md b/README.md index 149d1e3d..11117996 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ docker pull jxxghp/moviepilot:latest - **DOWNLOAD_SUBTITLE:** 下载站点字幕,`true`/`false`,默认`true` - **REFRESH_MEDIASERVER:** 入库刷新媒体库,`true`/`false`,默认`true` - **SCRAP_METADATA:** 刮削入库的媒体文件,`true`/`false`,默认`true` +- **SCRAP_FOLLOW_TMDB:** 新增已入库媒体是否跟随TMDB信息变化,`true`/`false`,默认`true` - **TORRENT_TAG:** 种子标签,默认为`MOVIEPILOT`,设置后只有MoviePilot添加的下载才会处理,留空所有下载器中的任务均会处理 - **LIBRARY_PATH:** 媒体库目录,多个目录使用`,`分隔 - **LIBRARY_MOVIE_NAME:** 电影媒体库目录名,默认`电影` diff --git a/app/chain/transfer.py b/app/chain/transfer.py index d841b666..868409a7 100644 --- a/app/chain/transfer.py +++ b/app/chain/transfer.py @@ -351,6 +351,11 @@ class TransferChain(ChainBase): # 媒体目录 if transfer_info.target_path.is_file(): transfer_info.target_path = transfer_info.target_path.parent + # 如果未开启新增已入库媒体是否跟随TMDB信息变化则根据tmdbid查询之前的title + if not settings.SCRAP_FOLLOW_TMDB: + transfer_historys = self.transferhis.get_by(tmdbid=str(mediainfo.tmdb_id)) + if not transfer_historys: + mediainfo.title = transfer_historys[0].title # 刮削 self.scrape_metadata(path=transfer_info.target_path, mediainfo=media) # 刷新媒体库,根目录或季目录 diff --git a/app/core/config.py b/app/core/config.py index debf69c0..5833aebb 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -39,6 +39,8 @@ class Settings(BaseSettings): SEARCH_SOURCE: str = "themoviedb" # 刮削入库的媒体文件 SCRAP_METADATA: bool = True + # 新增已入库媒体是否跟随TMDB信息变化 + SCRAP_FOLLOW_TMDB: bool = True # 刮削来源 SCRAP_SOURCE: str = "themoviedb" # TMDB图片地址 diff --git a/app/plugins/dirmonitor/__init__.py b/app/plugins/dirmonitor/__init__.py index 70be7087..4fa70664 100644 --- a/app/plugins/dirmonitor/__init__.py +++ b/app/plugins/dirmonitor/__init__.py @@ -308,6 +308,12 @@ class DirMonitor(_PluginBase): transferinfo=transferinfo ) + # 如果未开启新增已入库媒体是否跟随TMDB信息变化则根据tmdbid查询之前的title + if not settings.SCRAP_FOLLOW_TMDB: + transfer_historys = self.transferhis.get_by(tmdbid=str(mediainfo.tmdb_id)) + if not transfer_historys: + mediainfo.title = transfer_historys[0].title + # 刮削元数据,根目录或季目录 self.chain.scrape_metadata(path=transferinfo.target_path.parent, mediainfo=mediainfo) @@ -478,149 +484,149 @@ class DirMonitor(_PluginBase): def get_form(self) -> Tuple[List[dict], Dict[str, Any]]: return [ - { - 'component': 'VForm', - 'content': [ - { - 'component': 'VRow', - 'content': [ - { - 'component': 'VCol', - 'props': { - 'cols': 12, - 'md': 6 - }, - 'content': [ - { - 'component': 'VSwitch', - 'props': { - 'model': 'enabled', - 'label': '启用插件', - } - } - ] - }, - { - 'component': 'VCol', - 'props': { - 'cols': 12, - 'md': 6 - }, - 'content': [ - { - 'component': 'VSwitch', - 'props': { - 'model': 'notify', - 'label': '发送通知', - } - } - ] - } - ] - }, - { - 'component': 'VRow', - 'content': [ - { - 'component': 'VCol', - 'props': { - 'cols': 12, - 'md': 6 - }, - 'content': [ - { - 'component': 'VSelect', - 'props': { - 'model': 'mode', - 'label': '监控模式', - 'items': [ - {'title': '兼容模式', 'value': 'compatibility'}, - {'title': '性能模式', 'value': 'fast'} - ] - } - } - ] - }, - { - 'component': 'VCol', - 'props': { - 'cols': 12, - 'md': 6 - }, - 'content': [ - { - 'component': 'VSelect', - 'props': { - 'model': 'transfer_type', - 'label': '转移方式', - 'items': [ - {'title': '移动', 'value': 'move'}, - {'title': '复制', 'value': 'copy'}, - {'title': '硬链接', 'value': 'link'}, - {'title': '软链接', 'value': 'softlink'} - ] - } - } - ] - } - ] - }, - { - 'component': 'VRow', - 'content': [ - { - 'component': 'VCol', - 'props': { - 'cols': 12 - }, - 'content': [ - { - 'component': 'VTextarea', - 'props': { - 'model': 'monitor_dirs', - 'label': '监控目录', - 'rows': 5, - 'placeholder': '每一行一个目录,支持两种配置方式:\n' - '监控目录\n' - '监控目录:转移目的目录' - } - } - ] - } - ] - }, - { - 'component': 'VRow', - 'content': [ - { - 'component': 'VCol', - 'props': { - 'cols': 12 - }, - 'content': [ - { - 'component': 'VTextarea', - 'props': { - 'model': 'exclude_keywords', - 'label': '排除关键词', - 'rows': 2, - 'placeholder': '每一行一个关键词' - } - } - ] - } - ] - } - ] - } - ], { - "enabled": False, - "notify": False, - "mode": "fast", - "transfer_type": settings.TRANSFER_TYPE, - "monitor_dirs": "", - "exclude_keywords": "" - } + { + 'component': 'VForm', + 'content': [ + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 6 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'enabled', + 'label': '启用插件', + } + } + ] + }, + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 6 + }, + 'content': [ + { + 'component': 'VSwitch', + 'props': { + 'model': 'notify', + 'label': '发送通知', + } + } + ] + } + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 6 + }, + 'content': [ + { + 'component': 'VSelect', + 'props': { + 'model': 'mode', + 'label': '监控模式', + 'items': [ + {'title': '兼容模式', 'value': 'compatibility'}, + {'title': '性能模式', 'value': 'fast'} + ] + } + } + ] + }, + { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 6 + }, + 'content': [ + { + 'component': 'VSelect', + 'props': { + 'model': 'transfer_type', + 'label': '转移方式', + 'items': [ + {'title': '移动', 'value': 'move'}, + {'title': '复制', 'value': 'copy'}, + {'title': '硬链接', 'value': 'link'}, + {'title': '软链接', 'value': 'softlink'} + ] + } + } + ] + } + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12 + }, + 'content': [ + { + 'component': 'VTextarea', + 'props': { + 'model': 'monitor_dirs', + 'label': '监控目录', + 'rows': 5, + 'placeholder': '每一行一个目录,支持两种配置方式:\n' + '监控目录\n' + '监控目录:转移目的目录' + } + } + ] + } + ] + }, + { + 'component': 'VRow', + 'content': [ + { + 'component': 'VCol', + 'props': { + 'cols': 12 + }, + 'content': [ + { + 'component': 'VTextarea', + 'props': { + 'model': 'exclude_keywords', + 'label': '排除关键词', + 'rows': 2, + 'placeholder': '每一行一个关键词' + } + } + ] + } + ] + } + ] + } + ], { + "enabled": False, + "notify": False, + "mode": "fast", + "transfer_type": settings.TRANSFER_TYPE, + "monitor_dirs": "", + "exclude_keywords": "" + } def get_page(self) -> List[dict]: pass diff --git a/app/plugins/libraryscraper/__init__.py b/app/plugins/libraryscraper/__init__.py index b55fa6ee..ee104260 100644 --- a/app/plugins/libraryscraper/__init__.py +++ b/app/plugins/libraryscraper/__init__.py @@ -10,6 +10,7 @@ from apscheduler.triggers.cron import CronTrigger from app.core.config import settings from app.core.context import MediaInfo from app.core.metainfo import MetaInfo +from app.db.transferhistory_oper import TransferHistoryOper from app.helper.nfo import NfoReader from app.log import logger from app.plugins import _PluginBase @@ -41,6 +42,7 @@ class LibraryScraper(_PluginBase): user_level = 1 # 私有属性 + transferhis = None _scheduler = None _scraper = None # 限速开关 @@ -66,6 +68,7 @@ class LibraryScraper(_PluginBase): # 启动定时任务 & 立即运行一次 if self._enabled or self._onlyonce: + self.transferhis = TransferHistoryOper(self.db) self._scheduler = BackgroundScheduler(timezone=settings.TZ) if self._cron: logger.info(f"媒体库刮削服务启动,周期:{self._cron}") @@ -304,6 +307,11 @@ class LibraryScraper(_PluginBase): if not mediainfo: logger.warn(f"未识别到媒体信息:{file}") continue + # 如果未开启新增已入库媒体是否跟随TMDB信息变化则根据tmdbid查询之前的title + if not settings.SCRAP_FOLLOW_TMDB: + transfer_historys = self.transferhis.get_by(tmdbid=str(mediainfo.tmdb_id)) + if not transfer_historys: + mediainfo.title = transfer_historys[0].title # 开始刮削 self.chain.scrape_metadata(path=file, mediainfo=mediainfo)