Skip to content

Commit

Permalink
Merge pull request #44 from thsrite/main
Browse files Browse the repository at this point in the history
fix 同步历史记录插件增加下载器映射
  • Loading branch information
jxxghp authored Aug 8, 2023
2 parents c51728d + d872efa commit cb9bc2d
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 109 deletions.
219 changes: 119 additions & 100 deletions app/plugins/autobackup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,106 +179,125 @@ def get_form(self) -> Tuple[List[dict], Dict[str, Any]]:
拼装插件配置页面,需要返回两块数据:1、页面配置;2、数据结构
"""
return [
{
'component': 'VForm',
'content': [
{
'component': 'VRow',
'content': [
{
'component': 'VCol',
'props': {
'cols': 12,
'md': 4
},
'content': [
{
'component': 'VSwitch',
'props': {
'model': 'enabled',
'label': '启用插件',
}
}
]
},
{
'component': 'VCol',
'props': {
'cols': 12,
'md': 4
},
'content': [
{
'component': 'VSwitch',
'props': {
'model': 'notify',
'label': '开启通知',
}
}
]
},
{
'component': 'VCol',
'props': {
'cols': 12,
'md': 4
},
'content': [
{
'component': 'VSwitch',
'props': {
'model': 'onlyonce',
'label': '立即运行一次',
}
}
]
}
]
},
{
'component': 'VRow',
'content': [
{
'component': 'VCol',
'props': {
'cols': 12,
'md': 6
},
'content': [
{
'component': 'VTextField',
'props': {
'model': 'cron',
'label': '备份周期'
}
}
]
},
{
'component': 'VCol',
'props': {
'cols': 12,
'md': 6
},
'content': [
{
'component': 'VTextField',
'props': {
'model': 'cnt',
'label': '最大保留备份数'
}
}
]
}
]
},
]
}
], {
"enabled": False,
"request_method": "POST",
"webhook_url": ""
}
{
'component': 'VForm',
'content': [
{
'component': 'VRow',
'content': [
{
'component': 'VCol',
'props': {
'cols': 12,
'md': 4
},
'content': [
{
'component': 'VSwitch',
'props': {
'model': 'enabled',
'label': '启用插件',
}
}
]
},
{
'component': 'VCol',
'props': {
'cols': 12,
'md': 4
},
'content': [
{
'component': 'VSwitch',
'props': {
'model': 'notify',
'label': '开启通知',
}
}
]
},
{
'component': 'VCol',
'props': {
'cols': 12,
'md': 4
},
'content': [
{
'component': 'VSwitch',
'props': {
'model': 'onlyonce',
'label': '立即运行一次',
}
}
]
}
]
},
{
'component': 'VRow',
'content': [
{
'component': 'VCol',
'props': {
'cols': 12,
'md': 6
},
'content': [
{
'component': 'VTextField',
'props': {
'model': 'cron',
'label': '备份周期'
}
}
]
},
{
'component': 'VCol',
'props': {
'cols': 12,
'md': 6
},
'content': [
{
'component': 'VTextField',
'props': {
'model': 'cnt',
'label': '最大保留备份数'
}
}
]
}
]
},
{
'component': 'VRow',
'content': [
{
'component': 'VCol',
'props': {
'cols': 12,
},
'content': [
{
'component': 'VAlert',
'props': {
'text': '备份文件路径默认为本地映射的config/plugins/AutoBackup。'
}
}
]
}
]
}
]
}
], {
"enabled": False,
"request_method": "POST",
"webhook_url": ""
}

def get_page(self) -> List[dict]:
pass
Expand Down
2 changes: 1 addition & 1 deletion app/plugins/iyuuautoseed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ def __save_history(self, current_hash: str, downloader: str, success_torrents: [
if not history.get("downloader"):
continue
# 如果本次辅种下载器之前有过记录则继续添加
if int(history.get("downloader")) == downloader:
if str(history.get("downloader")) == downloader:
history_torrents = history.get("torrents") or []
history["torrents"] = list(set(history_torrents + success_torrents))
new_history = False
Expand Down
82 changes: 74 additions & 8 deletions app/plugins/nastoolsync/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os
import sqlite3
from datetime import datetime
Expand Down Expand Up @@ -43,6 +44,7 @@ class NAStoolSync(_PluginBase):
_transfer = None
_plugin = None
_download = None
_downloader = None

def init_plugin(self, config: dict = None):
self._transferhistory = TransferHistoryOper()
Expand All @@ -55,6 +57,7 @@ def init_plugin(self, config: dict = None):
self._site = config.get("site")
self._transfer = config.get("transfer")
self._plugin = config.get("plugin")
self._downloader = config.get("downloader")
self._download = config.get("download")

if self._nt_db_path and (self._transfer or self._plugin or self._download):
Expand Down Expand Up @@ -85,18 +88,31 @@ def init_plugin(self, config: dict = None):
self.update_config(
{
"clear": False,
"nt_db_path": "",
"nt_db_path": self._nt_db_path,
"path": self._path,
"downloader": self._downloader,
"site": self._site,
"transfer": self._transfer,
"plugin": self._plugin,
"download": self._download,
"transfer": False,
"plugin": False,
"download": False,
}
)

def sync_plugin_history(self, plugin_history):
"""
导入插件记录
NAStool
{
"id": "TorrentTransfer",
"key: "1-4bdc22bc1e062803c8686beb2796369c59ee141f",
"value": "{"to_download": 2, "to_download_id": "4bdc22bc1e062803c8686beb2796369c59ee141f", "delete_source": true}"
},
{
"id": "IYUUAutoSeed",
"key: "f161efaf008d2e56e7939272e8d95eca58fa71dd",
"value": "[{"downloader": "2", "torrents": ["bd64a8edc5afe6b4beb8813bdbf6faedfb1d4cc4"]}]"
}
"""
# 开始计时
start_time = datetime.now()
Expand All @@ -111,6 +127,34 @@ def sync_plugin_history(self, plugin_history):
plugin_key = history[2]
plugin_value = history[3]

# 处理下载器映射
if self._downloader:
downloaders = self._downloader.split("\n")
for downloader in downloaders:
sub_downloaders = downloader.split(":")
# 替换转种记录
if str(plugin_id) == "TorrentTransfer":
keys = str(plugin_key).split("-")
if keys[0].isdigit() and int(keys[0]) == int(sub_downloaders[0]):
# 替换key
plugin_key = plugin_key.replace(keys[0], sub_downloaders[1])

# 替换value
if isinstance(plugin_value, str):
plugin_value = json.loads(plugin_value)
if str(plugin_value.get("to_download")).isdigit() and int(
plugin_value.get("to_download")) == int(sub_downloaders[0]):
plugin_value["to_download"] = sub_downloaders[1]

# 替换辅种记录
if str(plugin_id) == "IYUUAutoSeed":
if isinstance(plugin_value, str):
plugin_value = json.loads(plugin_value)
for value in plugin_value:
if str(value.get("downloader")).isdigit() and int(value.get("downloader")) == int(
sub_downloaders[0]):
value["downloader"] = sub_downloaders[1]

self._plugindata.save(plugin_id=plugin_id,
key=plugin_key,
value=plugin_value)
Expand Down Expand Up @@ -351,7 +395,7 @@ def get_nt_transfer_history(cursor):
return nt_historys

def get_state(self) -> bool:
return True if self._nt_db_path else False
return True if self._transfer or self._plugin or self._download else False

@staticmethod
def get_command() -> List[Dict[str, Any]]:
Expand Down Expand Up @@ -471,14 +515,36 @@ def get_form(self) -> Tuple[List[dict], Dict[str, Any]]:
'props': {
'model': 'path',
'rows': '2',
'label': '路径映射',
'label': '历史记录路径映射',
'placeholder': 'NAStool路径:MoviePilot路径(一行一个)'
}
}
]
}
]
},
{
'component': 'VRow',
'content': [
{
'component': 'VCol',
'props': {
'cols': 12,
},
'content': [
{
'component': 'VTextarea',
'props': {
'model': 'downloader',
'rows': '2',
'label': '插件数据下载器映射',
'placeholder': 'NAStool下载器id:qbittorrent|transmission(一行一个)'
}
}
]
}
]
},
{
'component': 'VRow',
'content': [
Expand All @@ -492,7 +558,7 @@ def get_form(self) -> Tuple[List[dict], Dict[str, Any]]:
'component': 'VTextarea',
'props': {
'model': 'site',
'label': '站点映射',
'label': '下载历史站点映射',
'placeholder': 'NAStool站点名:MoviePilot站点名(一行一个)'
}
}
Expand All @@ -516,7 +582,6 @@ def get_form(self) -> Tuple[List[dict], Dict[str, Any]]:
'开启清空记录时,会在导入历史数据之前删除MoviePilot之前的记录。'
'如果转移记录很多,同步时间可能会长,'
'所以点击确定后页面没反应是正常现象,后台正在处理。'
'路径映射在同步转移记录时有效、站点映射在同步下载记录时有效。'
}
}
]
Expand All @@ -532,6 +597,7 @@ def get_form(self) -> Tuple[List[dict], Dict[str, Any]]:
"download": False,
"nt_db_path": "",
"path": "",
"downloader": "",
"site": "",
}

Expand Down

0 comments on commit cb9bc2d

Please sign in to comment.