mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 15:38:19 +08:00
Merge pull request #2624 from Aqr-K/dev
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import secrets
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import sys
|
||||
import threading
|
||||
from pathlib import Path
|
||||
@@ -226,6 +228,46 @@ class Settings(BaseSettings):
|
||||
}
|
||||
return None
|
||||
|
||||
@property
|
||||
def PROXY_URLPARSE(self):
|
||||
"""
|
||||
解析地址组成
|
||||
"""
|
||||
if self.PROXY_HOST:
|
||||
parsed_url = urlparse(self.PROXY_HOST)
|
||||
protocol = parsed_url.scheme or "" # 协议
|
||||
username = parsed_url.username or "" # 用户名
|
||||
password = parsed_url.password or "" # 密码
|
||||
host = parsed_url.hostname or "" # 主机
|
||||
port = parsed_url.port or "" # 端口
|
||||
path = parsed_url.path or "" # 路径
|
||||
netloc = parsed_url.netloc or "" # 用户名:密码@主机:端口
|
||||
query = parsed_url.query or "" # 查询参数: ?key=value
|
||||
params = parsed_url.params or "" # 使用;分割的参数
|
||||
fragment = parsed_url.fragment or "" # 片段: #fragment
|
||||
|
||||
if not port:
|
||||
if protocol == "https":
|
||||
port = 443
|
||||
elif protocol == "http":
|
||||
port = 80
|
||||
elif protocol in {"socks5", "socks5h", "socks4", "socks4a"}:
|
||||
port = 1080
|
||||
|
||||
return {
|
||||
"protocol": protocol,
|
||||
"username": username,
|
||||
"password": password,
|
||||
"host": host,
|
||||
"port": port,
|
||||
"path": path,
|
||||
"netloc": netloc,
|
||||
"query": query,
|
||||
"params": params,
|
||||
"fragment": fragment
|
||||
}
|
||||
return None
|
||||
|
||||
@property
|
||||
def PROXY_SERVER(self):
|
||||
if self.PROXY_HOST:
|
||||
@@ -244,6 +286,28 @@ class Settings(BaseSettings):
|
||||
}
|
||||
return {}
|
||||
|
||||
@property
|
||||
def PIP_OPTIONS(self):
|
||||
"""
|
||||
pip调用附加参数
|
||||
"""
|
||||
protocol = host = port = ""
|
||||
parsed_url = self.PROXY_URLPARSE
|
||||
if parsed_url:
|
||||
protocol = parsed_url.get("scheme", "").lower()
|
||||
host = parsed_url.get("host", "").lower()
|
||||
port = parsed_url.get("port", "")
|
||||
# 优先级:镜像站 > 全局 > 不代理
|
||||
if settings.PIP_PROXY:
|
||||
PIP_OPTIONS = f" -i {settings.PIP_PROXY} "
|
||||
# 全局代理地址
|
||||
elif protocol in {"http", "https", "socks4", "socks4a", "socks5", "socks5h"} and host and port:
|
||||
PIP_OPTIONS = f" --proxy={settings.PROXY_HOST} "
|
||||
# 不使用代理
|
||||
else:
|
||||
PIP_OPTIONS = ""
|
||||
return PIP_OPTIONS
|
||||
|
||||
@property
|
||||
def VAPID(self):
|
||||
return {
|
||||
|
||||
@@ -222,8 +222,7 @@ class PluginHelper(metaclass=Singleton):
|
||||
# 插件目录下如有requirements.txt则安装依赖
|
||||
requirements_file = plugin_dir / "requirements.txt"
|
||||
if requirements_file.exists():
|
||||
PIP_PROXY = f" -i {settings.PIP_PROXY} " if settings.PIP_PROXY else ""
|
||||
SystemUtils.execute(f"pip install -r {requirements_file} {PIP_PROXY} > /dev/null 2>&1")
|
||||
SystemUtils.execute(f"pip install -r {requirements_file} {settings.PIP_OPTIONS} > /dev/null 2>&1")
|
||||
# 安装成功后统计
|
||||
self.install_reg(pid)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user