Skip to content

Commit 442d241

Browse files
ChesyreAkimioJR
authored andcommitted
Add public_url parameter for separate internal/external URLs
1 parent 73a28cb commit 442d241

4 files changed

Lines changed: 46 additions & 29 deletions

File tree

app/modules/alist/v3/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def __init__(
2121
username: str = "",
2222
password: str = "",
2323
token: str = "",
24+
public_url: str = "",
2425
) -> None:
2526
"""
2627
AlistClient 类初始化
@@ -29,6 +30,7 @@ def __init__(
2930
:param username: Alist 用户名
3031
:param password: Alist 密码
3132
:param token: Alist 永久令牌
33+
:param public_url: 公共访问地址,用于生成 .strm 文件(可选)
3234
"""
3335

3436
if (username == "" or password == "") and token == "":
@@ -45,6 +47,11 @@ def __init__(
4547
if not url.startswith("http"):
4648
url = "https://" + url
4749
self.url = url.rstrip("/")
50+
51+
# 存储公共访问地址(如果提供)
52+
if public_url and not public_url.startswith("http"):
53+
public_url = "https://" + public_url
54+
self.public_url = public_url.rstrip("/") if public_url else None
4855

4956
if token != "":
5057
self.__token["token"] = token
@@ -217,6 +224,7 @@ async def async_api_fs_list(self, dir_path: str) -> list[AlistPath]:
217224
return [
218225
AlistPath(
219226
server_url=self.url,
227+
public_url=self.public_url,
220228
base_path=self.base_path,
221229
full_path=dir_path + "/" + alist_path["name"],
222230
**alist_path,
@@ -255,6 +263,7 @@ async def async_api_fs_get(self, path: str) -> AlistPath:
255263
logger.debug(f"获取路径 {path} 详细信息成功")
256264
return AlistPath(
257265
server_url=self.url,
266+
public_url=self.public_url,
258267
base_path=self.base_path,
259268
full_path=path,
260269
**result["data"],

app/modules/alist/v3/path.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class AlistPath(BaseModel):
1313
"""
1414

1515
server_url: str # 服务器地址
16+
public_url: str | None = None # 公共访问地址,用于生成 .strm 文件(可选,如果与 server_url 不同)
1617
base_path: str # 用户基础路径(用于计算文件/目录在 Alist 服务器上的绝对地址)
1718
full_path: str # 相对用户根文件/目录路径
1819

@@ -48,10 +49,13 @@ def download_url(self) -> str:
4849
"""
4950
文件下载地址
5051
"""
52+
# 如果定义了 public_url 则使用它,否则使用 server_url
53+
base_url = self.public_url if self.public_url else self.server_url
54+
5155
if self.sign:
52-
url = self.server_url + "/d" + self.abs_path + "?sign=" + self.sign
56+
url = base_url + "/d" + self.abs_path + "?sign=" + self.sign
5357
else:
54-
url = self.server_url + "/d" + self.abs_path
58+
url = base_url + "/d" + self.abs_path
5559

5660
return URLUtils.encode(url)
5761

app/modules/alist2strm/alist2strm.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def __init__(
2020
username: str = "",
2121
password: str = "",
2222
token: str = "",
23+
public_url: str = "",
2324
source_dir: str = "/",
2425
target_dir: str | PathLike = "",
2526
flatten_mode: bool = False,
@@ -44,6 +45,7 @@ def __init__(
4445
:param url: Alist 服务器地址,默认为 "http://localhost:5244"
4546
:param username: Alist 用户名,默认为空
4647
:param password: Alist 密码,默认为空
48+
:param public_url: 公共访问地址,用于生成 .strm 文件(可选)
4749
:param source_dir: 需要同步的 Alist 的目录,默认为 "/"
4850
:param target_dir: strm 文件输出目录,默认为当前工作目录
4951
:param flatten_mode: 平铺模式,将所有 Strm 文件保存至同一级目录,默认为 False
@@ -61,7 +63,7 @@ def __init__(
6163
:param smart_protection: 智能保护配置 {enabled: bool, threshold: int, grace_scans: int}
6264
"""
6365

64-
self.client = AlistClient(url, username, password, token)
66+
self.client = AlistClient(url, username, password, token, public_url)
6567
self.mode = Alist2StrmMode.from_str(mode)
6668

6769
self.source_dir = source_dir

config/config.yaml.example

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,42 @@ Settings:
22
DEV: False # 开发者模式(可选,默认 False)
33

44
Alist2StrmList:
5-
- id: 动漫 # 标识 ID
6-
cron: 0 20 * * * # 后台定时任务 Cron 表达式
7-
url: https://alist.akimio.top # Alist 服务器地址
8-
username: admin # Alist 用户名
9-
password: adminadmin # Alist 密码
10-
token: alist-d22d23ddf42fvv2 # Alist Token 永久令牌(可选,使用永久令牌则无需设置账号密码)
11-
source_dir: /ani/ # Alist 服务器上文件夹路径
12-
target_dir: D:\media\ # 输出路径
13-
flatten_mode: False # 平铺模式,开启后 subtitle、image、nfo 强制关闭(可选,默认 False)
14-
subtitle: False # 是否下载字幕文件(可选,默认 False)
15-
image: False # 是否下载图片文件(可选,默认 False)
16-
nfo: False # 是否下载 .nfo 文件(可选,默认 False)
17-
mode: AlistURL # Strm 文件中的内容(可选项:AlistURL、RawURL、AlistPath)
18-
overwrite: False # 覆盖模式,本地路径存在同名文件时是否重新生成/下载该文件(可选,默认 False)
19-
sync_server: True # 是否同步服务器(可选,默认为 True)
20-
sync_ignore: \.(nfo|jpg)$ # 同步时忽略的文件正则表达式(可选,默认为空,仅对文件名及拓展名有效,对路径无效)
21-
smart_protection: # 智能保护,防止 Alist 故障导致的大量删除(可选)
22-
enabled: True # 启用保护(默认:False)
23-
threshold: 100 # 触发保护的文件数量阈值(默认:100)
24-
grace_scans: 3 # 删除前需要的扫描次数(默认:3)
25-
other_ext: # 自定义下载后缀,使用西文半角逗号进行分割,(可选,默认为空)
26-
max_workers: 50 # 最大并发数,减轻对 Alist 服务器的负载(可选,默认 50)
27-
max_downloaders: 5 # 最大同时下载文件数(可选,默认 5)
28-
wait_time: 0 # 遍历请求间隔时间,避免被风控,单位为秒,默认为 0
5+
- id: 动漫 # 标识 ID
6+
cron: 0 20 * * * # 后台定时任务 Cron 表达式
7+
url: http://alist:5244 # Alist 服务器地址
8+
public_url: https://alist.akimio.top # 公共访问地址,用于 AlistURL 模式生成 .strm 文件内容(可选,默认使用 url)
9+
username: admin # Alist 用户名
10+
password: adminadmin # Alist 密码
11+
token: alist-d22d23ddf42fvv2 # Alist Token 永久令牌(可选,使用永久令牌则无需设置账号密码)
12+
source_dir: /ani/ # Alist 服务器上文件夹路径
13+
target_dir: D:\media\ # 输出路径
14+
flatten_mode: False # 平铺模式,开启后 subtitle、image、nfo 强制关闭(可选,默认 False)
15+
subtitle: False # 是否下载字幕文件(可选,默认 False)
16+
image: False # 是否下载图片文件(可选,默认 False)
17+
nfo: False # 是否下载 .nfo 文件(可选,默认 False)
18+
mode: AlistURL # Strm 文件中的内容(可选项:AlistURL、RawURL、AlistPath)
19+
overwrite: False # 覆盖模式,本地路径存在同名文件时是否重新生成/下载该文件(可选,默认 False)
20+
sync_server: True # 是否同步服务器(可选,默认为 True)
21+
sync_ignore: \.(nfo|jpg)$ # 同步时忽略的文件正则表达式(可选,默认为空,仅对文件名及拓展名有效,对路径无效)
22+
smart_protection: # 智能保护,防止 Alist 故障导致的大量删除(可选)
23+
enabled: True # 启用保护(默认:False)
24+
threshold: 100 # 触发保护的文件数量阈值(默认:100)
25+
grace_scans: 3 # 删除前需要的扫描次数(默认:3)
26+
other_ext: # 自定义下载后缀,使用西文半角逗号进行分割,(可选,默认为空)
27+
max_workers: 50 # 最大并发数,减轻对 Alist 服务器的负载(可选,默认 50)
28+
max_downloaders: 5 # 最大同时下载文件数(可选,默认 5)
29+
wait_time: 0 # 遍历请求间隔时间,避免被风控,单位为秒,默认为 0
2930

3031
- id: 电影
3132
cron: 0 0 7 * *
3233
url: http://alist.example2.com:5244
34+
public_url:
3335
username: alist
3436
password: alist
3537
token:
3638
source_dir: /网盘/115/电影
37-
target_dir: /media/my_video
38-
flatten_mode: False
39+
target_dir: /media/my_video
40+
flatten_mode: False
3941
subtitle: False
4042
image: False
4143
nfo: False

0 commit comments

Comments
 (0)