Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nastool同步目录支持预填写TMDB #805

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion app/helper/db_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2315,14 +2315,15 @@ 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):
"""
增加目录同步
"""
return self._db.insert(CONFIGSYNCPATHS(
SOURCE=source,
DEST=dest,
UNKNOWN=unknown,
TMDBID=tmdbid,
MODE=mode,
COMPATIBILITY=int(compatibility),
RENAME=int(rename),
Expand Down
25 changes: 23 additions & 2 deletions app/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 = {}
Expand All @@ -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:
Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions web/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions web/apiv1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
19 changes: 19 additions & 0 deletions web/templates/setting/directorysync.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ <h3 class="card-title ms-3">{{ Attr.from }}</h3>
{{ Attr.unknown or '未设置' }}
</div>
</div>
<div class="datagrid-item">
<div class="datagrid-title">TMDBID</div>
<div class="datagrid-content">
{{ Attr.tmdbid or '' }}
</div>
</div>
<div class="datagrid-item">
<div class="datagrid-title">同步方式</div>
<div class="datagrid-content">
Expand Down Expand Up @@ -171,6 +177,17 @@ <h5 class="modal-title" id="directory_modal_title"></h5>
placeholder="留空不转移未识别文件" autocomplete="off">
</div>
</div>
<div class="col-lg-4">
<div class="mb-3">
<label class="form-label">TMDB ID <span class="form-help"
title="TMDB ID为预先填写的TMBD ID, 会在监听模式下持续按照此ID同步文件"
data-bs-toggle="tooltip">?</span></label>
<div class="input-group">
<input type="text" value="" id="sync_path_tmdbid" class="form-control" placeholder="留空不设置">
<button class="btn" type="button" onclick="show_search_tmdbid_modal('sync_path_tmdbid', 'modal-directory')">查询</button>
</div>
</div>
</div>
<div class="col-lg-6">
<div class="mb-3">
<label class="form-label required">同步方式 <span class="form-help"
Expand Down Expand Up @@ -230,6 +247,7 @@ <h5 class="modal-title" id="directory_modal_title"></h5>
$("#sync_path_from").val('');
$("#sync_path_to").val('');
$("#sync_path_unknown").val('');
$("#sync_path_tmdbid").val('');
$("#sync_path_compatibility").prop("checked", false);
$("#sync_path_rename").prop("checked", true);
$("#sync_path_enabled").prop("checked", true);
Expand All @@ -248,6 +266,7 @@ <h5 class="modal-title" id="directory_modal_title"></h5>
$("#sync_path_from").val(sync_item.from);
$("#sync_path_to").val(sync_item.to);
$("#sync_path_unknown").val(sync_item.unknown);
$("#sync_path_tmdbid").val(sync_item.tmdbid);
$("#sync_path_syncmod").val(sync_item.syncmod);
$("#sync_path_compatibility").prop("checked", sync_item.compatibility);
$("#sync_path_rename").prop("checked", sync_item.rename);
Expand Down