diff --git a/app/db/models.py b/app/db/models.py index 2be470d2..011777ce 100644 --- a/app/db/models.py +++ b/app/db/models.py @@ -62,6 +62,7 @@ class CONFIGSYNCPATHS(Base): SOURCE = Column(Text) DEST = Column(Text) UNKNOWN = Column(Text) + TMDBID = Column(Text) MODE = Column(Text) COMPATIBILITY = Column(Integer) RENAME = Column(Integer) diff --git a/app/helper/db_helper.py b/app/helper/db_helper.py index 6271d6a5..18048583 100644 --- a/app/helper/db_helper.py +++ b/app/helper/db_helper.py @@ -2315,7 +2315,7 @@ def is_custom_word_group_existed(self, tmdbid=None, gtype=None): return False @DbPersist(_db) - def insert_config_sync_path(self, source, dest, unknown, mode, compatibility, rename, enabled, locating, note=None): + def insert_config_sync_path(self, source, dest, unknown, tmdbid, mode, compatibility, rename, enabled, locating, note=None): """ 增加目录同步 """ @@ -2323,6 +2323,7 @@ def insert_config_sync_path(self, source, dest, unknown, mode, compatibility, re SOURCE=source, DEST=dest, UNKNOWN=unknown, + TMDBID=tmdbid, MODE=mode, COMPATIBILITY=int(compatibility), RENAME=int(rename), diff --git a/app/sync.py b/app/sync.py index 17250dae..9acf797f 100644 --- a/app/sync.py +++ b/app/sync.py @@ -12,7 +12,8 @@ from app.helper import DbHelper from app.utils import PathUtils, ExceptionUtils from app.utils.commons import singleton -from app.utils.types import SyncType +from app.utils.types import SyncType, MediaType +from app.media import Media from config import RMT_MEDIAEXT lock = threading.Lock() @@ -56,6 +57,7 @@ def __init__(self): self.init_config() def init_config(self): + self.media = Media() self.dbhelper = DbHelper() self.filetransfer = FileTransfer() self._sync_path_confs = {} @@ -80,12 +82,15 @@ def init_config(self): monpath = sync_conf.SOURCE target_path = sync_conf.DEST unknown_path = sync_conf.UNKNOWN + tmdbid = sync_conf.TMDBID # 输出日志 log_content1, log_content2 = "", "" if target_path: log_content1 += f"目的目录:{target_path}," if unknown_path: log_content1 += f"未识别目录:{unknown_path}," + if tmdbid: + log_content1 += f"TMDBID: {tmdbid}," if rename: log_content2 += ",启用识别和重命名" if compatibility: @@ -105,6 +110,7 @@ def init_config(self): 'from': monpath, 'to': target_path or "", 'unknown': unknown_path or "", + "tmdbid": tmdbid or "", 'syncmod': syncmode, 'syncmod_name': syncmode_enum.value, "compatibility": compatibility, @@ -251,9 +257,16 @@ def file_change_handler(self, event, text, event_path): return # 监控根目录下的文件发生变化时直接发走 if is_root_path: + tmdb_info = None + tmdbid = sync_path_conf.get('tmdbid') + if tmdbid: + tmdb_info = self.media.get_tmdb_info(mtype=MediaType.TV, tmdbid=tmdbid) + log.info(f"【Sync】{event_path} 监听模式,预先获取TMDB INFO {tmdbid}") ret, ret_msg = self.filetransfer.transfer_media(in_from=SyncType.MON, in_path=event_path, target_dir=target_path, + tmdb_info = tmdb_info, + media_type = MediaType.TV if tmdb_info else None, unknown_dir=unknown_path, rmt_mode=sync_mode) if not ret: @@ -401,9 +414,16 @@ def transfer_sync(self, sid=None): for path in PathUtils.get_dir_level1_medias(mon_path, RMT_MEDIAEXT): if PathUtils.is_invalid_path(path): continue + tmdb_info = None + tmdbid = sync_path_conf.get('tmdbid') + if tmdbid: + tmdb_info = self.media.get_tmdb_info(mtype=MediaType.TV, tmdbid=tmdbid) + log.info(f"【Sync】{event_path} 监听模式,预先获取TMDB INFO {tmdbid}") ret, ret_msg = self.filetransfer.transfer_media(in_from=SyncType.MON, in_path=path, target_dir=target_path, + tmdb_info = tmdb_info, + media_type = MediaType.TV if tmdb_info else None, unknown_dir=unknown_path, rmt_mode=sync_mode) if not ret: @@ -438,13 +458,14 @@ def delete_sync_path(self, sid): self.init_config() return ret - def insert_sync_path(self, source, dest, unknown, mode, compatibility, rename, enabled, locating, note=None): + def insert_sync_path(self, source, dest, unknown, tmdbid, mode, compatibility, rename, enabled, locating, note=None): """ 添加同步目录配置 """ ret = self.dbhelper.insert_config_sync_path(source=source, dest=dest, unknown=unknown, + tmdbid=tmdbid, mode=mode, compatibility=compatibility, rename=rename, diff --git a/web/action.py b/web/action.py index fa787bed..e5e3eb17 100644 --- a/web/action.py +++ b/web/action.py @@ -1304,6 +1304,7 @@ def __add_or_edit_sync_path(data): source = data.get("from") dest = data.get("to") unknown = data.get("unknown") + tmdbid = data.get("tmdbid") mode = data.get("syncmod") compatibility = data.get("compatibility") rename = data.get("rename") @@ -1343,6 +1344,7 @@ def __add_or_edit_sync_path(data): _sync.insert_sync_path(source=source, dest=dest, unknown=unknown, + tmdbid=tmdbid, mode=mode, compatibility=compatibility, rename=rename, diff --git a/web/apiv1.py b/web/apiv1.py index 10999ced..08ea0113 100644 --- a/web/apiv1.py +++ b/web/apiv1.py @@ -2060,6 +2060,7 @@ class SyncDirectoryUpdate(ClientResource): parser.add_argument('from', type=str, help='源目录', location='form', required=True) parser.add_argument('to', type=str, help='目的目录', location='form') parser.add_argument('unknown', type=str, help='未知目录', location='form') + parser.add_argument('tmdbid', type=str, help='TMDB ID', location='form') parser.add_argument('syncmod', type=str, help='同步模式', location='form') parser.add_argument('compatibility', type=str, help='兼容模式', location='form') parser.add_argument('rename', type=str, help='重命名', location='form') diff --git a/web/templates/setting/directorysync.html b/web/templates/setting/directorysync.html index cd1961e7..12ea0867 100644 --- a/web/templates/setting/directorysync.html +++ b/web/templates/setting/directorysync.html @@ -79,6 +79,12 @@

{{ Attr.from }}

{{ Attr.unknown or '未设置' }} +
+
TMDBID
+
+ {{ Attr.tmdbid or '' }} +
+
同步方式
@@ -171,6 +177,17 @@ placeholder="留空不转移未识别文件" autocomplete="off">
+
+
+ +
+ + +
+
+