fix plugins

This commit is contained in:
jxxghp 2023-08-03 08:21:56 +08:00
parent 62d3f8c322
commit 88fec3ee9e
8 changed files with 107 additions and 13 deletions

View File

@ -133,7 +133,7 @@ class PluginManager(metaclass=Singleton):
for _, plugin in self._running_plugins.items():
if hasattr(plugin, "get_command") \
and ObjectUtils.check_method(plugin.get_command):
ret_commands += plugin.get_command()
ret_commands += plugin.get_command() or []
return ret_commands
def get_plugin_apis(self) -> List[Dict[str, Any]]:
@ -151,7 +151,7 @@ class PluginManager(metaclass=Singleton):
for pid, plugin in self._running_plugins.items():
if hasattr(plugin, "get_api") \
and ObjectUtils.check_method(plugin.get_api):
apis = plugin.get_api()
apis = plugin.get_api() or []
for api in apis:
api["path"] = f"/{pid}{api['path']}"
ret_apis.extend(apis)

View File

@ -28,7 +28,7 @@ class ChineseSubFinder(_PluginBase):
# 插件配置项ID前缀
plugin_config_prefix = "chinesesubfinder_"
# 加载顺序
plugin_order = 3
plugin_order = 5
# 可使用的用户级别
auth_level = 1

View File

@ -28,7 +28,7 @@ class CustomHosts(_PluginBase):
# 插件配置项ID前缀
plugin_config_prefix = "customhosts_"
# 加载顺序
plugin_order = 11
plugin_order = 10
# 可使用的用户级别
auth_level = 1

View File

@ -7,11 +7,11 @@ class DirMonitor(_PluginBase):
# 插件名称
plugin_name = "目录监控"
# 插件描述
plugin_desc = "监控目录文件发生变化时实时整理到媒体库。"
plugin_desc = "监控目录文件发生变化时实时整理到媒体库。"
# 插件图标
plugin_icon = "synctimer.png"
plugin_icon = "directory.png"
# 主题色
plugin_color = "#53BA48"
plugin_color = "#E0995E"
# 插件版本
plugin_version = "1.0"
# 插件作者
@ -21,7 +21,7 @@ class DirMonitor(_PluginBase):
# 插件配置项ID前缀
plugin_config_prefix = "dirmonitor_"
# 加载顺序
plugin_order = 5
plugin_order = 4
# 可使用的用户级别
user_level = 1

View File

@ -32,7 +32,7 @@ class DoubanRank(_PluginBase):
# 插件配置项ID前缀
plugin_config_prefix = "doubanrank_"
# 加载顺序
plugin_order = 16
plugin_order = 6
# 可使用的用户级别
auth_level = 2

View File

@ -25,7 +25,7 @@ class MediaSyncDel(_PluginBase):
# 插件配置项ID前缀
plugin_config_prefix = "mediasyncdel_"
# 加载顺序
plugin_order = 15
plugin_order = 9
# 可使用的用户级别
auth_level = 1

View File

@ -0,0 +1,94 @@
from typing import List, Tuple, Dict, Any
from apscheduler.schedulers.background import BackgroundScheduler
from app.core.config import settings
from app.log import logger
from app.plugins import _PluginBase
class SpeedLimiter(_PluginBase):
# 插件名称
plugin_name = "播放限速"
# 插件描述
plugin_desc = "媒体服务器播通过外网播放时,自动对下载器进行限速。"
# 插件图标
plugin_icon = "SpeedLimiter.jpg"
# 主题色
plugin_color = "#183883"
# 插件版本
plugin_version = "1.0"
# 插件作者
plugin_author = "Shurelol"
# 作者主页
author_url = "https://github.com/Shurelol"
# 插件配置项ID前缀
plugin_config_prefix = "speedlimit_"
# 加载顺序
plugin_order = 11
# 可使用的用户级别
auth_level = 2
# 私有属性
_scheduler = None
_enable: bool = False
_notify: bool = False
_bandwidth: int = 0
_interval: int = 60
def init_plugin(self, config: dict = None):
# 读取配置
if config:
self._enable = config.get("enable")
self._notify = config.get("notify")
try:
# 总带宽
self._bandwidth = int(float(config.get("bandwidth") or 0)) * 1000000
except Exception as e:
logger.error(f"总带宽配置错误:{e}")
self._bandwidth = 0
# 移出现有任务
self.stop_service()
# 启动限速任务
if self._enable:
self._scheduler = BackgroundScheduler(timezone=settings.TZ)
self._scheduler.add_job(func=self.__check_playing_sessions,
trigger='interval',
seconds=self._interval)
self._scheduler.print_jobs()
self._scheduler.start()
logger.info("播放限速服务启动")
@staticmethod
def get_command() -> List[Dict[str, Any]]:
pass
def get_api(self) -> List[Dict[str, Any]]:
pass
def get_form(self) -> Tuple[List[dict], Dict[str, Any]]:
pass
def get_page(self) -> List[dict]:
pass
def __check_playing_sessions(self):
"""
检查播放会话
"""
pass
def stop_service(self):
"""
退出插件
"""
try:
if self._scheduler:
self._scheduler.remove_all_jobs()
if self._scheduler.running:
self._scheduler.shutdown()
self._scheduler = None
except Exception as e:
print(str(e))

View File

@ -11,9 +11,9 @@ class TorrentRemover(_PluginBase):
# 插件描述
plugin_desc = "自动删除下载器中的下载任务。"
# 插件图标
plugin_icon = "torrentremover.png"
plugin_icon = "torrent.png"
# 主题色
plugin_color = "#F44336"
plugin_color = "#02853F"
# 插件版本
plugin_version = "1.0"
# 插件作者
@ -23,7 +23,7 @@ class TorrentRemover(_PluginBase):
# 插件配置项ID前缀
plugin_config_prefix = "torrentremover_"
# 加载顺序
plugin_order = 9
plugin_order = 8
# 可使用的用户级别
auth_level = 2