Skip to content

Commit

Permalink
Merge pull request NAStool#4199 from NAStool/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jxxghp authored Apr 9, 2023
2 parents 715d6c2 + eb24322 commit 8691362
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 33 deletions.
52 changes: 36 additions & 16 deletions app/plugins/modules/cloudflarespeedtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.cron import CronTrigger

from app.message import Message
from app.plugins import EventManager
from app.plugins.modules._base import _IPluginModule
from app.utils import SystemUtils, RequestUtils, IpUtils
Expand Down Expand Up @@ -38,6 +39,7 @@ class CloudflareSpeedTest(_IPluginModule):

# 私有属性
eventmanager = None
message = None
_customhosts = False
_cf_ip = None
_scheduler = None
Expand All @@ -48,6 +50,7 @@ class CloudflareSpeedTest(_IPluginModule):
_version = None
_additional_args = None
_re_install = False
_notify = False
_cf_path = 'cloudflarespeedtest'
_cf_ipv4 = 'cloudflarespeedtest/ip.txt'
_cf_ipv6 = 'cloudflarespeedtest/ipv6.txt'
Expand Down Expand Up @@ -106,6 +109,19 @@ def get_fields():
'tooltip': '优选测速ipv6;v4和v6必须其一,都不选择则默认ipv4。选择ipv6会大大加长测速时间。',
'type': 'switch',
'id': 'ipv6',
},
{
'title': '',
'required': "",
'tooltip': '',
'type': 'text',
'hidden': True,
'content': [
{
'id': 'version',
'placeholder': 'CloudflareSpeedTest版本',
}
]
}
],
[
Expand All @@ -122,7 +138,14 @@ def get_fields():
'tooltip': '开启后,每次会重新下载CloudflareSpeedTest,网络不好慎选',
'type': 'switch',
'id': 're_install',
}
},
{
'title': '运行时通知',
'required': "",
'tooltip': '运行任务后会发送通知(需要打开自定义消息通知)',
'type': 'switch',
'id': 'notify',
},
]
]
},
Expand All @@ -141,19 +164,6 @@ def get_fields():
'placeholder': '-dd'
}
]
},
{
'title': '',
'required': "",
'tooltip': '',
'type': 'text',
'hidden': True,
'content': [
{
'id': 'version',
'placeholder': 'CloudflareSpeedTest版本',
}
]
}
]
]
Expand All @@ -162,6 +172,7 @@ def get_fields():

def init_config(self, config=None):
self.eventmanager = EventManager()
self.message = Message()

# 读取配置
if config:
Expand All @@ -173,6 +184,7 @@ def init_config(self, config=None):
self._ipv6 = config.get("ipv6")
self._re_install = config.get("re_install")
self._additional_args = config.get("additional_args")
self._notify = config.get("notify")

# 停止现有任务
self.stop_service()
Expand Down Expand Up @@ -267,16 +279,23 @@ def __cloudflareSpeedTest(self):
}, "CustomHosts")

# 更新优选ip
old_ip = self._cf_ip
self._cf_ip = best_ip
self.__update_config()
self.info(f"CLoudflare CDN优选ip [{best_ip}] 已替换自定义Hosts插件")
self.info(f"Cloudflare CDN优选ip [{best_ip}] 已替换自定义Hosts插件")

# 解发自定义hosts插件重载
self.info("通知CustomHosts插件重载 ...")
self.eventmanager.send_event(EventType.PluginReload,
{
"plugin_id": "CustomHosts"
})
if self._notify:
self.message.send_custom_message(
title="【Cloudflare优选任务完成】",
text=f"原ip:{old_ip}\n"
f"新ip:{best_ip}"
)
else:
self.error("获取到最优ip格式错误,请重试")
self._onlyonce = False
Expand Down Expand Up @@ -412,7 +431,8 @@ def __update_config(self):
"ipv4": self._ipv4,
"ipv6": self._ipv6,
"re_install": self._re_install,
"additional_args": self._additional_args
"additional_args": self._additional_args,
"notify": self._notify
})

@staticmethod
Expand Down
3 changes: 3 additions & 0 deletions app/plugins/modules/cookiecloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from apscheduler.triggers.cron import CronTrigger

import pytz

import log
from app.helper import DbHelper, IndexerHelper
from app.message import Message
from app.plugins.modules._base import _IPluginModule
Expand Down Expand Up @@ -243,6 +245,7 @@ def __cookie_sync(self):
self.info(f"同步服务开始 ...")
contents, msg, _ = self.__download_data()
if not contents:
log.error(msg)
self.__send_message(msg)
return
# 整理数据,使用domain域名的最后两级作为分组依据
Expand Down
19 changes: 19 additions & 0 deletions app/plugins/modules/doubanrank.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class DoubanRank(_IPluginModule):
_cron = ""
_rss_addrs = []
_ranks = []
_vote = 0
_scheduler = None

def init_config(self, config: dict = None):
Expand All @@ -69,6 +70,7 @@ def init_config(self, config: dict = None):
self._enable = config.get("enable")
self._onlyonce = config.get("onlyonce")
self._cron = config.get("cron")
self._vote = int(config.get("vote")) if config.get("vote") else 0
rss_addrs = config.get("rss_addrs")
if rss_addrs:
if isinstance(rss_addrs, str):
Expand Down Expand Up @@ -100,6 +102,7 @@ def init_config(self, config: dict = None):
"enable": self._enable,
"cron": self._cron,
"ranks": self._ranks,
"vote": self._vote,
"rss_addrs": "\n".join(self._rss_addrs)
})
if self._scheduler.get_jobs():
Expand Down Expand Up @@ -148,6 +151,18 @@ def get_fields():
'placeholder': '0 0 0 ? *',
}
]
},
{
'title': '评分',
'required': "",
'tooltip': '大于该评分的才会被订阅,不填则不限制',
'type': 'text',
'content': [
{
'id': 'vote',
'placeholder': '0',
}
]
}
],
[
Expand Down Expand Up @@ -260,6 +275,10 @@ def __refresh_rss(self):
if not media_info:
self.warn(f"未查询到媒体信息:{rss_info.get('doubanid')} - {rss_info.get('title')}")
continue
if self._vote and media_info.vote_average \
and media_info.vote_average < self._vote:
self.info(f"评分低于限制:{media_info.get_title_string()},跳过 ...")
continue
# 检查媒体服务器是否存在
item_id = self.mediaserver.check_item_exists(mtype=media_info.type,
title=media_info.title,
Expand Down
12 changes: 6 additions & 6 deletions app/plugins/modules/iyuuautoseed.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,11 @@ def auto_seed(self):
if self._notify:
self.message.send_custom_message(
title="【IYUU自动辅种任务完成】",
text=f"服务器返回可辅种总数:{self.total}"
f"实际可辅种数:{self.realtotal}"
f"已存在:{self.exist}, "
f"成功:{self.success}"
f"失败:{self.fail}"
text=f"服务器返回可辅种总数:{self.total}\n"
f"实际可辅种数:{self.realtotal}\n"
f"已存在:{self.exist}\n"
f"成功:{self.success}\n"
f"失败:{self.fail}\n"
f"{self.cached} 条失败记录已加入缓存"
)
self.info("辅种任务执行完成")
Expand Down Expand Up @@ -449,7 +449,7 @@ def __download_torrent(self, seed, downloader, save_path):
# 查询站点
site_info = self.sites.get_sites(siteurl=site_url)
if not site_info:
self.warn(f"没有维护种子对应的站点:{site_url}")
self.debug(f"没有维护种子对应的站点:{site_url}")
return
if self._sites and str(site_info.get("id")) not in self._sites:
self.info("当前站点不在选择的辅助站点范围,跳过 ...")
Expand Down
20 changes: 9 additions & 11 deletions app/plugins/modules/torrenttransfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,19 @@ def get_fields():
'content': [
{
'id': 'fromtorrentpath',
'placeholder': 'BT_backup|torrents',
'placeholder': 'xxx/BT_backup、xxx/torrents',
}
]
},
{
'title': '数据文件根路径',
'required': "required",
'tooltip': '源下载器中的种子数据文件保存根目录路径,必须是下载器能访问的路径,用于转移时替换种子数据文件路径使用',
'tooltip': '源下载器中的种子数据文件保存根目录路径,必须是下载器能访问的路径,用于转移时转换种子数据文件路径使用;留空不进行路径转换,使用种子的数据文件保存目录',
'type': 'text',
'content': [
{
'id': 'frompath',
'placeholder': '根路径',
'placeholder': '根路径,留空不进行路径转换',
}
]
}
Expand All @@ -170,12 +170,12 @@ def get_fields():
{
'title': '数据文件根路径',
'required': "required",
'tooltip': '目的下载器的种子数据文件保存目录根路径,必须是下载器能访问的路径,将会使用该路径替换源下载器中种子数据文件保存路径中的源目录根路径,替换后的新路径做为目的下载器种子数据文件的保存路径,需要准确填写,否则可能导致移转做种后找不到数据文件,从而触发重新下载',
'tooltip': '目的下载器的种子数据文件保存目录根路径,必须是下载器能访问的路径,将会使用该路径替换源下载器中种子数据文件保存路径中的源目录根路径,替换后的新路径做为目的下载器种子数据文件的保存路径,需要准确填写,否则可能导致移转做种后找不到数据文件无法做种;留空不进行路径转换,使用种子的数据文件保存路径',
'type': 'text',
'content': [
{
'id': 'topath',
'placeholder': '根路径',
'placeholder': '根路径,留空不进行路径转换',
}
]
}
Expand Down Expand Up @@ -247,6 +247,7 @@ def init_config(self, config=None):
self._todownloader = config.get("todownloader")
self._deletesource = config.get("deletesource")
self._fromtorrentpath = config.get("fromtorrentpath")
self._nopaths = config.get("nopaths")

# 停止现有任务
self.stop_service()
Expand Down Expand Up @@ -286,6 +287,7 @@ def init_config(self, config=None):
"todownloader": self._todownloader,
"deletesource": self._deletesource,
"fromtorrentpath": self._fromtorrentpath,
"nopaths": self._nopaths
})
if self._scheduler.get_jobs():
# 追加种子校验服务
Expand All @@ -299,8 +301,6 @@ def get_state(self):
and self._cron \
and self._fromdownloader \
and self._todownloader \
and self._frompath \
and self._topath \
and self._fromtorrentpath else False

def transfer(self):
Expand All @@ -310,8 +310,6 @@ def transfer(self):
if not self._enable \
or not self._fromdownloader \
or not self._todownloader \
or not self._frompath \
or not self._topath \
or not self._fromtorrentpath:
self.warn("移转做种服务未启用或未配置")
return
Expand Down Expand Up @@ -534,9 +532,9 @@ def __convert_save_path(save_path, from_root, to_root):
# 没有保存目录,以目的根目录为准
if not save_path:
return to_root
# 没有设置根目录时返回None
# 没有设置根目录时返回save_path
if not to_root or not from_root:
return None
return save_path
# 统一目录格式
save_path = os.path.normpath(save_path).replace("\\", "/")
from_root = os.path.normpath(from_root).replace("\\", "/")
Expand Down

0 comments on commit 8691362

Please sign in to comment.