-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
323 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import json, os | ||
from helper.getvalue import apilists | ||
from qfluentwidgets import MessageBoxBase, SubtitleLabel, CheckBox, LineEdit, HyperlinkButton, TransparentPushButton, ToolTipFilter, ToolTipPosition | ||
from PyQt5.QtWidgets import QLabel, QHBoxLayout, QVBoxLayout | ||
from PyQt5.QtCore import QUrl | ||
from qfluentwidgets import FluentIcon as FIF | ||
from helper.getvalue import autoncmaapi, autoqqmaapi | ||
|
||
ncma_edited_api = None | ||
qqma_edited_api = None | ||
|
||
def get_all_api(folders_arg): | ||
global apilists | ||
for folder in folders_arg: | ||
for filename in os.listdir(folder): | ||
last_path = os.path.basename(folder) | ||
if filename.endswith('.py') and os.path.exists(folder) and os.path.exists( | ||
folder + "/index.json") and filename.replace(".py", "") == last_path and not os.path.exists( | ||
folder + "/plugin.lock"): | ||
u = open(folder + "/index.json", "r", encoding="utf-8") | ||
data = json.loads(u.read()) | ||
u.close() | ||
if data["type"] == "api": | ||
apilists.append(filename.replace(".py", "")) | ||
return apilists | ||
|
||
class DeleteAllData(MessageBoxBase): | ||
def __init__(self, parent): | ||
super().__init__(parent) | ||
self.titleLabel = SubtitleLabel('重置应用', self) | ||
self.contentLabel = QLabel("你确定要重置应用吗?\n重置应用将会删除你的设置等数据,\n同时你将会回到初始化时的状态。\n重置后将会直接关闭应用,\n请确保没有任何正在执行的下载任务。", self) | ||
self.contentLabel.setStyleSheet("QLabel{color:rgb(225,0,0);font-size:17px;font-weight:normal;font-family:SimHei;}") | ||
|
||
self.PrimiseCheckBox = CheckBox('我已悉知以上影响', self) | ||
self.DataCheckBox = CheckBox('同时删除下载的音乐', self) | ||
self.DataCheckBox.setDisabled(True) | ||
|
||
# add widget to view layout | ||
self.viewLayout.addWidget(self.titleLabel) | ||
self.viewLayout.addWidget(self.contentLabel) | ||
self.viewLayout.addWidget(self.PrimiseCheckBox) | ||
self.viewLayout.addWidget(self.DataCheckBox) | ||
|
||
# change the text of button | ||
self.yesButton.setText('取消') | ||
self.cancelButton.setText('重置') | ||
|
||
self.widget.setMinimumWidth(350) | ||
self.cancelButton.setDisabled(True) | ||
#self.urlLineEdit.textChanged.connect(self._validateUrl) | ||
self.PrimiseCheckBox.stateChanged.connect(self.IfPrimise) | ||
|
||
def IfPrimise(self): | ||
self.cancelButton.setEnabled(self.PrimiseCheckBox.isChecked()) | ||
|
||
class CustomAPIs(MessageBoxBase): | ||
def __init__(self, parent, ncmaapi, qqmaapi): | ||
super().__init__(parent) | ||
self.titleLabel = SubtitleLabel('自定义NCMA/QQMA的API地址', self) | ||
self.contentLabel = QLabel("API地址是一个完整的,包含协议头的地址。\nNCMA地址必须填写,QQMA由于没有默认值可以不填\n填写错误会导致下载失败,有任何问题请查阅文档", self) | ||
self.contentLabel.setStyleSheet("QLabel{font-size:15px;font-weight:normal;font-family:Microsoft YaHei;}") | ||
|
||
# NCMA配置 | ||
self.ncmaLabel = QLabel("NCMA:", self) | ||
self.ncmaLabel.setStyleSheet("QLabel{font-size:15px;font-weight:normal;font-family:Microsoft YaHei;}") | ||
self.NCMAedit = LineEdit(self) | ||
self.NCMAedit.setPlaceholderText('输入NCMA的API地址配置') | ||
self.NCMAedit.setText(ncmaapi) | ||
self.NCMAedit.setClearButtonEnabled(True) | ||
|
||
self.NCMAtoInit = TransparentPushButton('恢复默认值', self) | ||
self.NCMAtoInit.setToolTip(f'NCMA的默认值为 {autoncmaapi}') | ||
self.NCMAtoInit.installEventFilter(ToolTipFilter(self.NCMAtoInit, 0, ToolTipPosition.TOP)) | ||
self.NCMAdoc = HyperlinkButton( | ||
url='https://md.azprod.cn/docs/use_api.html', | ||
text='查阅文档', | ||
parent=self, | ||
icon=FIF.LINK | ||
) | ||
|
||
self.ncmaHLayout = QHBoxLayout(self) | ||
self.ncmaHLayout.addWidget(self.NCMAtoInit) | ||
self.ncmaHLayout.addWidget(self.NCMAdoc) | ||
|
||
# QQMA配置 | ||
self.qqmaLabel = QLabel("QQMA:", self) | ||
self.qqmaLabel.setStyleSheet("QLabel{font-size:15px;font-weight:normal;font-family:SimHei;font-family:Microsoft YaHei;}") | ||
self.QQMAedit = LineEdit(self) | ||
self.QQMAedit.setPlaceholderText('输入QQMA的API地址配置') | ||
self.QQMAedit.setText(qqmaapi) | ||
self.QQMAedit.setClearButtonEnabled(True) | ||
|
||
self.QQMAtoInit = TransparentPushButton('恢复默认值', self) | ||
self.QQMAtoInit.setToolTip('QQMA可以不填,同时没有默认值') | ||
self.QQMAtoInit.installEventFilter(ToolTipFilter(self.QQMAtoInit, 0, ToolTipPosition.TOP)) | ||
self.QQMAdoc = HyperlinkButton( | ||
url='https://md.azprod.cn/docs/use_api.html', | ||
text='查阅文档', | ||
parent=self, | ||
icon=FIF.LINK | ||
) | ||
|
||
self.qqmaHLayout = QHBoxLayout(self) | ||
self.qqmaHLayout.addWidget(self.QQMAtoInit) | ||
self.qqmaHLayout.addWidget(self.QQMAdoc) | ||
|
||
# 添加布局 | ||
self.viewLayout.addWidget(self.titleLabel) | ||
self.viewLayout.addWidget(self.contentLabel) | ||
self.viewLayout.addWidget(self.ncmaLabel) | ||
self.viewLayout.addWidget(self.NCMAedit) | ||
self.viewLayout.addLayout(self.ncmaHLayout) | ||
self.viewLayout.addWidget(self.qqmaLabel) | ||
self.viewLayout.addWidget(self.QQMAedit) | ||
self.viewLayout.addLayout(self.qqmaHLayout) | ||
|
||
# 对按钮进行设置 | ||
self.yesButton.setText('保存') | ||
self.cancelButton.setText('取消') | ||
self.widget.setMinimumWidth(350) | ||
self.NCMAtoInit.clicked.connect(self.ncmabacktoinit) | ||
self.QQMAtoInit.clicked.connect(self.qqmabacktoinit) | ||
self.yesButton.clicked.connect(self.save) | ||
|
||
def ncmabacktoinit(self): | ||
self.NCMAedit.setText(autoncmaapi) | ||
def qqmabacktoinit(self): | ||
self.QQMAedit.setText(autoqqmaapi) | ||
|
||
def save(self): | ||
# 设置修改操作 | ||
global ncma_edited_api | ||
global qqma_edited_api | ||
ncma_edited_api = self.NCMAedit.text() | ||
qqma_edited_api = self.QQMAedit.text() | ||
|
||
def editapi(parent, ncmaapi, qqmaapi): | ||
w = CustomAPIs(parent=parent, ncmaapi=ncmaapi, qqmaapi=qqmaapi) | ||
w.show() | ||
if w.exec(): | ||
new_api = [] | ||
new_api.append(ncma_edited_api) | ||
new_api.append(qqma_edited_api) | ||
return new_api | ||
else: | ||
w = False | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import logging, colorlog | ||
from helper.config import cfg | ||
|
||
#logger日志 | ||
def get_logger(level=logging.INFO): | ||
# 创建logger对象 | ||
logger = logging.getLogger() | ||
logger.setLevel(level) | ||
console_handler = logging.StreamHandler() | ||
console_handler.setLevel(level) | ||
|
||
# 定义颜色输出格式 | ||
color_formatter = colorlog.ColoredFormatter( | ||
'%(asctime)s - %(log_color)s[%(levelname)s]: %(message)s', | ||
log_colors={ | ||
'DEBUG': 'cyan', | ||
'INFO': 'green', | ||
'WARNING': 'yellow', | ||
'ERROR': 'red', | ||
'CRITICAL': 'red,bg_white', | ||
}, | ||
datefmt='%Y-%m-%d %H:%M:%S' | ||
) | ||
console_handler.setFormatter(color_formatter) | ||
|
||
#修改Handler | ||
for handler in logger.handlers: | ||
logger.removeHandler(handler) | ||
logger.addHandler(console_handler) | ||
return logger | ||
|
||
if cfg.debug_card.value: | ||
logger = get_logger(logging.DEBUG) | ||
else: | ||
logger = get_logger() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
# coding:utf-8 | ||
import importlib, sys, json, os | ||
|
||
from qfluentwidgets import FluentIcon as FIF | ||
from qfluentwidgets import SwitchSettingCard, PushSettingCard | ||
from helper.config import cfg | ||
from helper.flyoutmsg import dlerr | ||
from helper.getvalue import apilists | ||
from helper.loggerHelper import logger | ||
|
||
plugins_items = {} | ||
folders = cfg.PluginFolders.value | ||
|
||
def get_folders(directory): | ||
folders = [] | ||
for item in os.listdir(directory): | ||
item_path = os.path.join(directory, item) | ||
if os.path.isdir(item_path): | ||
folders.append(item) | ||
return folders | ||
|
||
def load_plugins(parent): | ||
global plugins_items | ||
# 遍历插件目录中的文件 | ||
num = 0 | ||
if cfg.debug_card.value: | ||
logger.info("开始导入插件") | ||
for dirname in folders: | ||
sys.path.append(dirname) | ||
for filename in os.listdir(dirname): | ||
last_path = os.path.basename(dirname) | ||
if filename.endswith('.py') and os.path.exists(dirname) and os.path.exists(dirname + "/index.json") and filename.replace(".py", "") == last_path and not os.path.exists(dirname + "/plugin.lock"): | ||
plugin_name = filename[:-3] | ||
module_name = f"{plugin_name}" | ||
try: | ||
module = importlib.import_module(module_name) | ||
plugin_class = getattr(module, plugin_name) | ||
plugins_items[plugin_name] = plugin_class() | ||
if cfg.debug_card.value: | ||
logger.info(f"导入插件: {plugin_name}") | ||
num = num + 1 | ||
except Exception as e: | ||
logger.error(f"导入{plugin_name}插件错误: {e}") | ||
#if cfg.debug_card.value: | ||
# print("添加Plugins中的API") | ||
#get_all_api() | ||
if cfg.debug_card.value: | ||
logger.info(f"成功导入了{str(num)}个插件") | ||
|
||
|
||
def run_plugins(parent): | ||
global plugins_items | ||
num = 0 | ||
for plugin_name, plugin_instance in plugins_items.items(): | ||
folder = folders[num] | ||
num = num + 1 | ||
get_v = open(f"{folder}/index.json", "r", encoding="utf-8") | ||
data = json.loads(get_v.read()) | ||
get_v.close() | ||
if data["type"] == "Bar" and os.path.basename(folder) == plugin_name: | ||
#icon = f'plugins/{plugin_name}/{data["icon"]}' | ||
icon = data["show_icon"] | ||
#icon = "resource/logo.png" | ||
name = data["name"] | ||
logger.debug(f"将插件添加至导航栏: {plugin_name}") | ||
exec(f"parent.addSubInterface(plugin_instance, {icon}, '{name}')") | ||
|
||
|
||
def set_plugin_disable(folder, state): | ||
if not state: | ||
w = open(f"{folder}/plugin.lock", "w") | ||
w.close() | ||
else: | ||
if os.path.exists(f"{folder}/plugin.lock"): | ||
os.remove(f"{folder}/plugin.lock") | ||
def run_plugins_plugin(parent, PluginsGroup): | ||
folders = cfg.PluginFolders.value | ||
for folder in folders: | ||
if os.path.exists(folder + "/index.json"): | ||
get_json = open(f"{folder}/index.json", "r", encoding="utf-8") | ||
data = json.loads(get_json.read()) | ||
get_json.close() | ||
addCard(parent, PluginsGroup, data["icon"], data["name"], data["desc"], data["type"], folder) | ||
|
||
def open_plugin_window(plugin, parent): | ||
try: | ||
plugin_name = os.path.basename(plugin) | ||
new = plugins_items[plugin_name] | ||
if os.path.exists(plugin + "/index.json"): | ||
get_json = open(f"{plugin}/index.json", "r", encoding="utf-8") | ||
data = json.loads(get_json.read()) | ||
new.setWindowTitle(data["name"]) | ||
new.show() | ||
except: | ||
dlerr(outid=9, parent=parent) | ||
|
||
|
||
|
||
|
||
def addCard(parent, PluginsGroup, icon, title, content, type, uuid): | ||
if type == "Bar": | ||
PluginCard_Bar = SwitchSettingCard( | ||
icon, | ||
title, | ||
content, | ||
cfg.micaEnabled, | ||
PluginsGroup | ||
) | ||
PluginCard_Bar.checkedChanged.connect(lambda: set_plugin_disable(uuid, PluginCard_Bar.isChecked())) | ||
if not os.path.exists(uuid + "/plugin.lock"): | ||
PluginCard_Bar.setValue(True) | ||
else: | ||
PluginCard_Bar.setValue(False) | ||
PluginCard_Bar.setObjectName(uuid) | ||
parent.PluginsGroup.addSettingCard(PluginCard_Bar) | ||
elif type == "api": | ||
PluginCard_api = SwitchSettingCard( | ||
icon, | ||
title, | ||
content, | ||
None, | ||
PluginsGroup | ||
) | ||
PluginCard_api.checkedChanged.connect(lambda: set_plugin_disable(uuid, PluginCard_api.isChecked())) | ||
if not os.path.exists(uuid + "/plugin.lock"): | ||
PluginCard_api.setValue(True) | ||
else: | ||
PluginCard_api.setValue(False) | ||
PluginCard_api.setObjectName(uuid) | ||
parent.PluginsGroup.addSettingCard(PluginCard_api) | ||
elif type == "Window": | ||
PluginCard_window = PushSettingCard( | ||
'打开', | ||
icon, | ||
title, | ||
content, | ||
PluginsGroup | ||
) | ||
PluginCard_window.setObjectName(uuid) | ||
PluginCard_window.clicked.connect(lambda: open_plugin_window(uuid, parent=parent)) | ||
parent.PluginsGroup.addSettingCard(PluginCard_window) |