fix bug
This commit is contained in:
parent
2a7fc7bbe6
commit
781cffb255
@ -122,7 +122,7 @@ class DownloadFiles(Base):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def get_by_fullpath(db: Session, fullpath: str):
|
def get_by_fullpath(db: Session, fullpath: str):
|
||||||
return db.query(DownloadFiles).filter(DownloadFiles.fullpath == fullpath).order_by(
|
return db.query(DownloadFiles).filter(DownloadFiles.fullpath == fullpath).order_by(
|
||||||
DownloadHistory.id.desc()).first()
|
DownloadFiles.id.desc()).first()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_by_savepath(db: Session, savepath: str):
|
def get_by_savepath(db: Session, savepath: str):
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import ipaddress
|
|
||||||
from typing import List, Tuple, Dict, Any
|
from typing import List, Tuple, Dict, Any
|
||||||
|
|
||||||
from apscheduler.schedulers.background import BackgroundScheduler
|
from apscheduler.schedulers.background import BackgroundScheduler
|
||||||
@ -73,7 +72,8 @@ class SpeedLimiter(_PluginBase):
|
|||||||
if self._bandwidth > 0:
|
if self._bandwidth > 0:
|
||||||
# 自动限速开关
|
# 自动限速开关
|
||||||
self._auto_limit = True
|
self._auto_limit = True
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
logger.error(f"智能限速上行带宽设置错误:{str(e)}")
|
||||||
self._bandwidth = 0
|
self._bandwidth = 0
|
||||||
|
|
||||||
# 限速服务开关
|
# 限速服务开关
|
||||||
@ -112,199 +112,209 @@ class SpeedLimiter(_PluginBase):
|
|||||||
|
|
||||||
def get_form(self) -> Tuple[List[dict], Dict[str, Any]]:
|
def get_form(self) -> Tuple[List[dict], Dict[str, Any]]:
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
'component': 'VForm',
|
'component': 'VForm',
|
||||||
'content': [
|
'content': [
|
||||||
{
|
{
|
||||||
'component': 'VRow',
|
'component': 'VRow',
|
||||||
'content': [
|
'content': [
|
||||||
{
|
{
|
||||||
'component': 'VCol',
|
'component': 'VCol',
|
||||||
'props': {
|
'props': {
|
||||||
'cols': 12,
|
'cols': 12,
|
||||||
'md': 6
|
'md': 6
|
||||||
},
|
},
|
||||||
'content': [
|
'content': [
|
||||||
{
|
{
|
||||||
'component': 'VSwitch',
|
'component': 'VSwitch',
|
||||||
'props': {
|
'props': {
|
||||||
'model': 'enabled',
|
'model': 'enabled',
|
||||||
'label': '启用插件',
|
'label': '启用插件',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'component': 'VCol',
|
'component': 'VCol',
|
||||||
'props': {
|
'props': {
|
||||||
'cols': 12,
|
'cols': 12,
|
||||||
'md': 6
|
'md': 6
|
||||||
},
|
},
|
||||||
'content': [
|
'content': [
|
||||||
{
|
{
|
||||||
'component': 'VSwitch',
|
'component': 'VSwitch',
|
||||||
'props': {
|
'props': {
|
||||||
'model': 'notify',
|
'model': 'notify',
|
||||||
'label': '发送通知',
|
'label': '发送通知',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'component': 'VRow',
|
'component': 'VRow',
|
||||||
'content': [
|
'content': [
|
||||||
{
|
{
|
||||||
'component': 'VCol',
|
'component': 'VCol',
|
||||||
'content': [
|
'content': [
|
||||||
{
|
{
|
||||||
'component': 'VSelect',
|
'component': 'VSelect',
|
||||||
'props': {
|
'props': {
|
||||||
'chips': True,
|
'chips': True,
|
||||||
'multiple': True,
|
'multiple': True,
|
||||||
'model': 'downloader',
|
'model': 'downloader',
|
||||||
'label': '下载器',
|
'label': '下载器',
|
||||||
'items': [
|
'items': [
|
||||||
{'title': 'Qbittorrent', 'value': 'qbittorrent'},
|
{'title': 'Qbittorrent', 'value': 'qbittorrent'},
|
||||||
{'title': 'Transmission', 'value': 'transmission'},
|
{'title': 'Transmission', 'value': 'transmission'},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'component': 'VRow',
|
'component': 'VRow',
|
||||||
'content': [
|
'content': [
|
||||||
{
|
{
|
||||||
'component': 'VCol',
|
'component': 'VCol',
|
||||||
'props': {
|
'props': {
|
||||||
'cols': 12,
|
'cols': 12,
|
||||||
'md': 6
|
'md': 6
|
||||||
},
|
},
|
||||||
'content': [
|
'content': [
|
||||||
{
|
{
|
||||||
'component': 'VTextField',
|
'component': 'VTextField',
|
||||||
'props': {
|
'props': {
|
||||||
'model': 'play_up_speed',
|
'model': 'play_up_speed',
|
||||||
'label': '播放限速(上传)',
|
'label': '播放限速(上传)',
|
||||||
'placeholder': 'KB/s'
|
'placeholder': 'KB/s'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'component': 'VCol',
|
'component': 'VCol',
|
||||||
'props': {
|
'props': {
|
||||||
'cols': 12,
|
'cols': 12,
|
||||||
'md': 6
|
'md': 6
|
||||||
},
|
},
|
||||||
'content': [
|
'content': [
|
||||||
{
|
{
|
||||||
'component': 'VTextField',
|
'component': 'VTextField',
|
||||||
'props': {
|
'props': {
|
||||||
'model': 'play_down_speed',
|
'model': 'play_down_speed',
|
||||||
'label': '播放限速(下载)',
|
'label': '播放限速(下载)',
|
||||||
'placeholder': 'KB/s'
|
'placeholder': 'KB/s'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'component': 'VRow',
|
'component': 'VRow',
|
||||||
'content': [
|
'content': [
|
||||||
{
|
{
|
||||||
'component': 'VCol',
|
'component': 'VCol',
|
||||||
'props': {
|
'props': {
|
||||||
'cols': 12,
|
'cols': 12,
|
||||||
'md': 6
|
'md': 6
|
||||||
},
|
},
|
||||||
'content': [
|
'content': [
|
||||||
{
|
{
|
||||||
'component': 'VTextField',
|
'component': 'VTextField',
|
||||||
'props': {
|
'props': {
|
||||||
'model': 'noplay_up_speed',
|
'model': 'noplay_up_speed',
|
||||||
'label': '未播放限速(上传)',
|
'label': '未播放限速(上传)',
|
||||||
'placeholder': 'KB/s'
|
'placeholder': 'KB/s'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'component': 'VCol',
|
'component': 'VCol',
|
||||||
'props': {
|
'props': {
|
||||||
'cols': 12,
|
'cols': 12,
|
||||||
'md': 6
|
'md': 6
|
||||||
},
|
},
|
||||||
'content': [
|
'content': [
|
||||||
{
|
{
|
||||||
'component': 'VTextField',
|
'component': 'VTextField',
|
||||||
'props': {
|
'props': {
|
||||||
'model': 'noplay_down_speed',
|
'model': 'noplay_down_speed',
|
||||||
'label': '未播放限速(下载)',
|
'label': '未播放限速(下载)',
|
||||||
'placeholder': 'KB/s'
|
'placeholder': 'KB/s'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'component': 'VRow',
|
'component': 'VRow',
|
||||||
'content': [
|
'content': [
|
||||||
{
|
{
|
||||||
'component': 'VCol',
|
'component': 'VCol',
|
||||||
'props': {
|
'props': {
|
||||||
'cols': 12,
|
'cols': 12,
|
||||||
'md': 6
|
'md': 6
|
||||||
},
|
},
|
||||||
'content': [
|
'content': [
|
||||||
{
|
{
|
||||||
'component': 'VTextField',
|
'component': 'VTextField',
|
||||||
'props': {
|
'props': {
|
||||||
'model': 'bandwidth',
|
'model': 'bandwidth',
|
||||||
'label': '智能限速上行带宽',
|
'label': '智能限速上行带宽',
|
||||||
'placeholder': '设置上行带宽后,媒体服务器有媒体播放时根据上行带宽和媒体播放占用带宽计算上传限速数值。'
|
'placeholder': 'MB/s'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'component': 'VCol',
|
'component': 'VCol',
|
||||||
'props': {
|
'props': {
|
||||||
'cols': 12,
|
'cols': 12,
|
||||||
'md': 6
|
'md': 6
|
||||||
},
|
},
|
||||||
'content': [
|
'content': [
|
||||||
{
|
{
|
||||||
'component': 'VTextField',
|
'component': 'VSelect',
|
||||||
'props': {
|
'props': {
|
||||||
'model': 'allocation_ratio',
|
'model': 'allocation_ratio',
|
||||||
'label': '智能限速分配比例',
|
'label': '智能限速分配比例',
|
||||||
'placeholder': '多个下载器设置分配比例,如两个下载器设置1:2,留空均分'
|
'items': [
|
||||||
}
|
{'title': '平均', 'value': ''},
|
||||||
}
|
{'title': '1:9', 'value': '1:9'},
|
||||||
]
|
{'title': '2:8', 'value': '2:8'},
|
||||||
}
|
{'title': '3:7', 'value': '3:7'},
|
||||||
]
|
{'title': '4:6', 'value': '4:6'},
|
||||||
},
|
{'title': '6:4', 'value': '6:4'},
|
||||||
]
|
{'title': '7:3', 'value': '7:3'},
|
||||||
}
|
{'title': '8:2', 'value': '8:2'},
|
||||||
], {
|
{'title': '9:1', 'value': '9:1'},
|
||||||
"enabled": False,
|
]
|
||||||
"notify": True,
|
}
|
||||||
"downloader": [],
|
}
|
||||||
"play_up_speed": 0,
|
]
|
||||||
"play_down_speed": 0,
|
}
|
||||||
"noplay_up_speed": 0,
|
]
|
||||||
"noplay_down_speed": 0,
|
},
|
||||||
"bandwidth": 0,
|
]
|
||||||
"allocation_ratio": "",
|
}
|
||||||
}
|
], {
|
||||||
|
"enabled": False,
|
||||||
|
"notify": True,
|
||||||
|
"downloader": [],
|
||||||
|
"play_up_speed": None,
|
||||||
|
"play_down_speed": None,
|
||||||
|
"noplay_up_speed": None,
|
||||||
|
"noplay_down_speed": None,
|
||||||
|
"bandwidth": None,
|
||||||
|
"allocation_ratio": "",
|
||||||
|
}
|
||||||
|
|
||||||
def get_page(self) -> List[dict]:
|
def get_page(self) -> List[dict]:
|
||||||
pass
|
pass
|
||||||
@ -428,12 +438,19 @@ class SpeedLimiter(_PluginBase):
|
|||||||
for download in self._downloader:
|
for download in self._downloader:
|
||||||
if self._auto_limit and limit_type == "播放":
|
if self._auto_limit and limit_type == "播放":
|
||||||
# 开启了播放智能限速
|
# 开启了播放智能限速
|
||||||
allocation_count = sum(self._allocation_ratio) if self._allocation_ratio else len(self._downloader)
|
if len(self._downloader) == 1:
|
||||||
if not self._allocation_ratio:
|
# 只有一个下载器
|
||||||
upload_limit = int(upload_limit / allocation_count)
|
upload_limit = int(upload_limit)
|
||||||
else:
|
else:
|
||||||
upload_limit = int(upload_limit * float(self._allocation_ratio[cnt]) / allocation_count)
|
# 多个下载器
|
||||||
cnt += 1
|
if not self._allocation_ratio:
|
||||||
|
# 平均
|
||||||
|
upload_limit = int(upload_limit / len(self._downloader))
|
||||||
|
else:
|
||||||
|
# 按比例
|
||||||
|
allocation_count = sum([int(i) for i in self._allocation_ratio.split(":")])
|
||||||
|
upload_limit = int(upload_limit * int(self._allocation_ratio[cnt]) / allocation_count)
|
||||||
|
cnt += 1
|
||||||
|
|
||||||
if str(download) == 'qbittorrent':
|
if str(download) == 'qbittorrent':
|
||||||
if self._qb:
|
if self._qb:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user