Skip to content

Commit

Permalink
feat: 更新3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
林源 committed Mar 3, 2023
2 parents 968ef1b + 0ec1160 commit d917800
Show file tree
Hide file tree
Showing 28 changed files with 218 additions and 106 deletions.
3 changes: 2 additions & 1 deletion app/brushtask.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def __is_allow_new_torrent(self, taskinfo, dlcount):
downloader_id = taskinfo.get("downloader")
downloader_name = taskinfo.get("downloader_name")
total_size = self.dbhelper.get_brushtask_totalsize(taskinfo.get("id"))
if taskinfo.get(""):
if seed_size:
if float(seed_size) * 1024 ** 3 <= int(total_size):
log.warn("【Brush】刷流任务 %s 当前保种体积 %sGB,不再新增下载"
% (task_name, round(int(total_size) / 1024 / 1024 / 1024, 1)))
Expand Down Expand Up @@ -458,6 +458,7 @@ def __download_torrent(self,
media_info=meta_info,
tag=tag,
downloader_id=downloader_id,
download_setting="-2",
download_limit=download_limit,
upload_limit=upload_limit,
)
Expand Down
15 changes: 15 additions & 0 deletions app/conf/moduleconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,21 @@ class ModuleConf(object):
"title": "密码",
"type": "password",
"placeholder": "password"
},
"torrent_management": {
"id": "qbittorrent_torrent_management",
"required": False,
"title": "种子管理模式",
"tooltip": """默认:Torrent管理模式应用Qbittorrent下载器-选项-下载-保存管理中设置;
手动:Torrent管理模式为手动,下载目录由NAStool传递的下载目录决定;
自动:Torrent管理模式为自动,下载目录由NAStool传递的分类及下载器中分类保存路径决定,需要在NAStool下载目录设置中配置分类标签""",
"type": "select",
"options": {
"default": "默认",
"manual": "手动",
"auto": "自动"
},
"default": "manual"
}
}
},
Expand Down
10 changes: 7 additions & 3 deletions app/conf/systemconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

from app.helper import DictHelper
from app.utils.commons import singleton
from app.utils.types import SystemConfigKey


@singleton
class SystemConfig:

# 系统设置
systemconfig = {}

Expand All @@ -33,10 +33,12 @@ def __is_obj(obj):
else:
return str(obj).startswith("{") or str(obj).startswith("[")

def set_system_config(self, key, value):
def set_system_config(self, key: [SystemConfigKey, str], value):
"""
设置系统设置
"""
if isinstance(key, SystemConfigKey):
key = key.value
# 更新内存
self.systemconfig[key] = value
# 写入数据库
Expand All @@ -47,10 +49,12 @@ def set_system_config(self, key, value):
value = ''
self.dicthelper.set("SystemConfig", key, value)

def get_system_config(self, key=None):
def get_system_config(self, key: [SystemConfigKey, str] = None):
"""
获取系统设置
"""
if not key:
return self.systemconfig
if isinstance(key, SystemConfigKey):
key = key.value
return self.systemconfig.get(key)
29 changes: 14 additions & 15 deletions app/downloader/client/qbittorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class Qbittorrent(_IDownloadClient):

# 私有属性
_client_config = {}
_force_upload = False
_auto_management = False
_torrent_management = False

qbc = None
ver = None
Expand All @@ -45,10 +44,16 @@ def init_config(self):
self.username = self._client_config.get('username')
self.password = self._client_config.get('password')
self.download_dir = self._client_config.get('download_dir')
# 强制做种开关
self._force_upload = self._client_config.get('force_upload')
# 自动管理模式开关
self._auto_management = self._client_config.get('auto_management')
# 种子管理模式
match self._client_config.get('torrent_management'):
case "default":
self._torrent_management = None
case "manual":
self._torrent_management = False
case "auto":
self._torrent_management = True
case _:
self._torrent_management = False

@classmethod
def match(cls, ctype):
Expand Down Expand Up @@ -165,10 +170,6 @@ def set_torrents_status(self, ids, tags=None):
try:
# 打标签
self.qbc.torrents_add_tags(tags="已整理", torrent_hashes=ids)
# 超级做种
if self._force_upload:
self.qbc.torrents_set_force_start(enable=True, torrent_hashes=ids)
log.info(f"【{self.client_name}】设置qBittorrent种子状态成功")
except Exception as err:
ExceptionUtils.exception_traceback(err)

Expand Down Expand Up @@ -373,10 +374,8 @@ def add_torrent(self,
else:
seeding_time_limit = None
try:
if self._auto_management:
use_auto_torrent_management = True
else:
use_auto_torrent_management = False
if self._torrent_management:
save_path = None
qbc_ret = self.qbc.torrents_add(urls=urls,
torrent_files=torrent_files,
save_path=save_path,
Expand All @@ -388,7 +387,7 @@ def add_torrent(self,
download_limit=download_limit,
ratio_limit=ratio_limit,
seeding_time_limit=seeding_time_limit,
use_auto_torrent_management=use_auto_torrent_management,
use_auto_torrent_management=self._torrent_management,
cookie=cookie)
return True if qbc_ret and str(qbc_ret).find("Ok") != -1 else False
except Exception as err:
Expand Down
51 changes: 32 additions & 19 deletions app/downloader/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from app.sites import Sites, SiteSubtitle
from app.utils import Torrent, StringUtils, SystemUtils, ExceptionUtils
from app.utils.commons import singleton
from app.utils.types import MediaType, DownloaderType, SearchType, RmtMode, EventType
from app.utils.types import MediaType, DownloaderType, SearchType, RmtMode, EventType, SystemConfigKey
from config import Config, PT_TAG, RMT_MEDIAEXT, PT_TRANSFER_INTERVAL

lock = Lock()
Expand Down Expand Up @@ -66,15 +66,8 @@ def init_config(self):
self.systemconfig = SystemConfig()
self.eventmanager = EventManager()
self.sitesubtitle = SiteSubtitle()
# 移出现有任务
try:
if self._scheduler:
self._scheduler.remove_all_jobs()
if self._scheduler.running:
self._scheduler.shutdown()
self._scheduler = None
except Exception as e:
ExceptionUtils.exception_traceback(e)
# 清空已存在下载器实例
self.clients = {}
# 下载器配置,生成实例
self._downloader_confs = {}
downloaders_conf = self.dbhelper.get_downloaders()
Expand All @@ -99,7 +92,7 @@ def init_config(self):
}
# 下载器ID-名称枚举类生成
self._DownloaderEnum = Enum('DownloaderIdName',
{id: conf.get("name") for id, conf in self._downloader_confs.items()})
{did: conf.get("name") for did, conf in self._downloader_confs.items()})
pt = Config().get_config('pt')
if pt:
self._download_order = pt.get("download_order")
Expand Down Expand Up @@ -163,7 +156,7 @@ def default_downloader_id(self):
"""
获取默认下载器id
"""
default_downloader_id = SystemConfig().get_system_config("DefaultDownloader")
default_downloader_id = SystemConfig().get_system_config(SystemConfigKey.DefaultDownloader)
if not default_downloader_id or not self.get_downloader_conf(default_downloader_id):
default_downloader_id = ""
return default_downloader_id
Expand All @@ -174,7 +167,7 @@ def default_download_setting_id(self):
获取默认下载设置
:return: 默认下载设置id
"""
default_download_setting_id = SystemConfig().get_system_config("DefaultDownloadSetting") or "-1"
default_download_setting_id = SystemConfig().get_system_config(SystemConfigKey.DefaultDownloadSetting) or "-1"
if not self._download_settings.get(default_download_setting_id):
default_download_setting_id = "-1"
return default_download_setting_id
Expand Down Expand Up @@ -209,9 +202,18 @@ def transfer_scheduler(self):
"""
转移任务调度
"""
# 移出现有任务
try:
if self._scheduler:
self._scheduler.remove_all_jobs()
if self._scheduler.running:
self._scheduler.shutdown()
self._scheduler = None
except Exception as e:
ExceptionUtils.exception_traceback(e)
# 启动转移任务
if not self.monitor_downloader_ids:
return
# 启动转移任务
self._scheduler = BackgroundScheduler(timezone=Config().get_timezone())
for downloader_id in self.monitor_downloader_ids:
self._scheduler.add_job(func=self.transfer,
Expand Down Expand Up @@ -258,7 +260,7 @@ def download(self,
:param is_paused: 是否暂停下载
:param tag: 种子标签
:param download_dir: 指定下载目录
:param download_setting: 下载设置id
:param download_setting: 下载设置id,为None则使用-1默认设置,为"-2"则不使用下载设置
:param downloader_id: 指定下载器ID下载
:param upload_limit: 上传速度限制
:param download_limit: 下载速度限制
Expand Down Expand Up @@ -332,12 +334,20 @@ def __download_fail(msg):

# 下载设置
if not download_setting and media_info.site:
# 站点的下载设置
download_setting = self.sites.get_site_download_setting(media_info.site)
if download_setting:
if download_setting == "-2":
# 不使用下载设置
download_attr = {}
elif download_setting:
# 传入的下载设置
download_attr = self.get_download_setting(download_setting) \
or self.get_download_setting(self.default_download_setting_id)
else:
# 默认下载设置
download_attr = self.get_download_setting(self.default_download_setting_id)

# 下载设置名称
download_setting_name = download_attr.get('name')

# 下载器实例
Expand Down Expand Up @@ -478,7 +488,10 @@ def __download_fail(msg):
# 发送下载消息
if in_from:
media_info.user_name = user_name
self.message.send_download_message(in_from, media_info, download_setting_name, downloader_name)
self.message.send_download_message(in_from=in_from,
can_item=media_info,
download_setting_name=download_setting_name,
downloader_name=downloader_name)
return downloader_id, download_id, ""
else:
__download_fail("请检查下载任务是否已存在")
Expand Down Expand Up @@ -1138,7 +1151,7 @@ def __get_download_dir_info(media, downloaddir):
"""
根据媒体信息读取一个下载目录的信息
"""
if media and media.tmdb_info:
if media:
for attr in downloaddir or []:
if not attr:
continue
Expand Down Expand Up @@ -1208,7 +1221,7 @@ def get_download_setting(self, sid=None):
self._download_settings["-1"]["downloader_type"] = preset_downloader_conf.get("type")
if not sid:
return self._download_settings
return self._download_settings.get(str(sid))
return self._download_settings.get(str(sid)) or {}

def set_speed_limit(self, downloader_id=None, download_limit=None, upload_limit=None):
"""
Expand Down
2 changes: 1 addition & 1 deletion app/media/meta/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class MetaBase(object):
# 音频编码
audio_encode = None
# 二级分类
category = None
category = ""
# TMDB ID
tmdb_id = 0
# IMDB ID
Expand Down
2 changes: 1 addition & 1 deletion app/mediaserver/client/plex.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def get_tv_episodes(self,
"season_num": episode.seasonNumber,
"episode_num": episode.index
})
return ret_tvs

def get_no_exists_episodes(self, meta_info, season, total_num):
"""
Expand Down Expand Up @@ -253,7 +254,6 @@ def get_libraries(self):
libraries.append({"id": library.key, "name": library.title})
return libraries

@staticmethod
def get_iteminfo(self, itemid):
"""
获取单个项目详情
Expand Down
10 changes: 5 additions & 5 deletions app/mediaserver/media_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from app.message import Message
from app.utils import ExceptionUtils
from app.utils.commons import singleton
from app.utils.types import MediaServerType, MovieTypes
from app.utils.types import MediaServerType, MovieTypes, SystemConfigKey
from app.utils.types import MediaType
from config import Config

Expand Down Expand Up @@ -194,7 +194,7 @@ def sync_mediaserver(self):
self.progress.start("mediasync")
self.progress.update(ptype="mediasync", text="请稍候...")
# 获取需同步的媒体库
librarys = self.systemconfig.get_system_config("SyncLibrary") or []
librarys = self.systemconfig.get_system_config(SystemConfigKey.SyncLibrary) or []
# 汇总统计
medias_count = self.get_medias_count()
total_media_count = medias_count.get("MovieCount") + medias_count.get("SeriesCount")
Expand All @@ -204,7 +204,7 @@ def sync_mediaserver(self):
# 清空登记薄
self.mediadb.empty()
for library in self.get_libraries():
if library.get("id") not in librarys:
if str(library.get("id")) not in librarys:
continue
# 获取媒体库所有项目
self.progress.update(ptype="mediasync",
Expand Down Expand Up @@ -318,7 +318,7 @@ def webhook_message_handler(self, message: str, channel: MediaServerType):
"""
if not self.server:
return
if channel != self._server_type:
if channel != self.server.get_type():
return
event_info = self.server.get_webhook_message(message)
if event_info:
Expand All @@ -331,7 +331,7 @@ def webhook_message_handler(self, message: str, channel: MediaServerType):
season_id=event_info.get('season_id'),
episode_id=event_info.get('episode_id'))
else:
if self._server_type == MediaServerType.PLEX:
if self._server_type == "plex":
# Plex:根据返回的tmdb_id去调用tmdb获取
image_url = self.media.get_tmdb_backdrop(mtype=MediaType.MOVIE,
tmdbid=event_info.get('tmdb_id'))
Expand Down
10 changes: 7 additions & 3 deletions app/plugins/modules/speedlimiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,19 @@ def init_config(self, config=None):
try:
# 下载限速
self._download_limit = int(float(config.get("download_limit") or 0))
# 上传限速
self._upload_limit = int(float(config.get("download_limit") or 0))
except Exception as e:
ExceptionUtils.exception_traceback(e)
self._download_limit = 0

try:
# 上传限速
self._upload_limit = int(float(config.get("upload_limit") or 0))
except Exception as e:
ExceptionUtils.exception_traceback(e)
self._upload_limit = 0

# 限速服务开关
self._limit_enabled = True if self._download_limit or self._upload_limit else False
self._limit_enabled = True if self._download_limit or self._upload_limit or self._auto_limit else False

# 不限速地址
self._unlimited_ips["ipv4"] = config.get("ipv4") or "0.0.0.0/0"
Expand Down
2 changes: 1 addition & 1 deletion app/plugins/modules/synctimer.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_fields():
'content': [
{
'id': 'cron',
'placeholder': '0 0 */2 * * ?',
'placeholder': '0 0 */2 * *',
}
]
}
Expand Down
Loading

0 comments on commit d917800

Please sign in to comment.