This commit is contained in:
jxxghp 2023-08-31 20:12:38 +08:00
parent 2a7fc7bbe6
commit 781cffb255
2 changed files with 218 additions and 201 deletions

View File

@ -122,7 +122,7 @@ class DownloadFiles(Base):
@staticmethod
def get_by_fullpath(db: Session, fullpath: str):
return db.query(DownloadFiles).filter(DownloadFiles.fullpath == fullpath).order_by(
DownloadHistory.id.desc()).first()
DownloadFiles.id.desc()).first()
@staticmethod
def get_by_savepath(db: Session, savepath: str):

View File

@ -1,4 +1,3 @@
import ipaddress
from typing import List, Tuple, Dict, Any
from apscheduler.schedulers.background import BackgroundScheduler
@ -73,7 +72,8 @@ class SpeedLimiter(_PluginBase):
if self._bandwidth > 0:
# 自动限速开关
self._auto_limit = True
except Exception:
except Exception as e:
logger.error(f"智能限速上行带宽设置错误:{str(e)}")
self._bandwidth = 0
# 限速服务开关
@ -268,7 +268,7 @@ class SpeedLimiter(_PluginBase):
'props': {
'model': 'bandwidth',
'label': '智能限速上行带宽',
'placeholder': '设置上行带宽后,媒体服务器有媒体播放时根据上行带宽和媒体播放占用带宽计算上传限速数值。'
'placeholder': 'MB/s'
}
}
]
@ -281,11 +281,21 @@ class SpeedLimiter(_PluginBase):
},
'content': [
{
'component': 'VTextField',
'component': 'VSelect',
'props': {
'model': 'allocation_ratio',
'label': '智能限速分配比例',
'placeholder': '多个下载器设置分配比例如两个下载器设置1:2,留空均分'
'items': [
{'title': '平均', 'value': ''},
{'title': '19', 'value': '1:9'},
{'title': '28', 'value': '2:8'},
{'title': '37', 'value': '3:7'},
{'title': '46', 'value': '4:6'},
{'title': '64', 'value': '6:4'},
{'title': '73', 'value': '7:3'},
{'title': '82', 'value': '8:2'},
{'title': '91', 'value': '9:1'},
]
}
}
]
@ -298,11 +308,11 @@ class SpeedLimiter(_PluginBase):
"enabled": False,
"notify": True,
"downloader": [],
"play_up_speed": 0,
"play_down_speed": 0,
"noplay_up_speed": 0,
"noplay_down_speed": 0,
"bandwidth": 0,
"play_up_speed": None,
"play_down_speed": None,
"noplay_up_speed": None,
"noplay_down_speed": None,
"bandwidth": None,
"allocation_ratio": "",
}
@ -428,11 +438,18 @@ class SpeedLimiter(_PluginBase):
for download in self._downloader:
if self._auto_limit and limit_type == "播放":
# 开启了播放智能限速
allocation_count = sum(self._allocation_ratio) if self._allocation_ratio else len(self._downloader)
if not self._allocation_ratio:
upload_limit = int(upload_limit / allocation_count)
if len(self._downloader) == 1:
# 只有一个下载器
upload_limit = int(upload_limit)
else:
upload_limit = int(upload_limit * float(self._allocation_ratio[cnt]) / allocation_count)
# 多个下载器
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':