Skip to content

Commit bf4f992

Browse files
authored
Merge pull request jxxghp#5224 from stkevintan/file_uri
2 parents 785540e + 167ae65 commit bf4f992

File tree

7 files changed

+37
-13
lines changed

7 files changed

+37
-13
lines changed

app/agent/tools/impl/add_download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class AddDownloadInput(BaseModel):
2525
downloader: Optional[str] = Field(None,
2626
description="Name of the downloader to use (optional, uses default if not specified)")
2727
save_path: Optional[str] = Field(None,
28-
description="Directory path where the downloaded files should be saved (optional, uses default path if not specified)")
28+
description="Directory path where the downloaded files should be saved. Using `<storage>:<path>` for remote storage. e.g. rclone:/MP, smb:/server/share/Movies. (optional, uses default path if not specified)")
2929
labels: Optional[str] = Field(None,
3030
description="Comma-separated list of labels/tags to assign to the download (optional, e.g., 'movie,hd,bluray')")
3131

app/api/endpoints/download.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def add(
6868
tmdbid: Annotated[int | None, Body()] = None,
6969
doubanid: Annotated[str | None, Body()] = None,
7070
downloader: Annotated[str | None, Body()] = None,
71+
# 保存路径, 支持<storage>:<path>, 如rclone:/MP, smb:/server/share/Movies等
7172
save_path: Annotated[str | None, Body()] = None,
7273
current_user: User = Depends(get_current_active_user)) -> Any:
7374
"""
@@ -92,6 +93,7 @@ def add(
9293
media_info=mediainfo,
9394
torrent_info=torrentinfo
9495
)
96+
9597
did = DownloadChain().download_single(context=context, username=current_user.name,
9698
downloader=downloader, save_path=save_path, source="Manual")
9799
if not did:

app/chain/download.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def download_single(self, context: Context,
162162
:param channel: 通知渠道
163163
:param source: 来源(消息通知、Subscribe、Manual等)
164164
:param downloader: 下载器
165-
:param save_path: 保存路径
165+
:param save_path: 保存路径, 支持<storage>:<path>, 如rclone:/MP, smb:/server/share/Movies等
166166
:param userid: 用户ID
167167
:param username: 调用下载的用户名/插件名
168168
:param label: 自定义标签
@@ -235,11 +235,10 @@ def download_single(self, context: Context,
235235
storage = 'local'
236236
# 下载目录
237237
if save_path:
238+
uri = schemas.FileURI.from_uri(save_path)
238239
# 下载目录使用自定义的
239-
download_dir = Path(save_path)
240-
# Check if the download_dir matches any configured dirs
241-
dir_info = DirectoryHelper().get_dir(dest_path=download_dir)
242-
storage = dir_info.storage if dir_info else storage
240+
download_dir = Path(uri.path)
241+
storage = uri.storage
243242
else:
244243
# 根据媒体信息查询下载目录配置
245244
dir_info = DirectoryHelper().get_dir(_media, include_unsorted=True)
@@ -405,7 +404,7 @@ def batch_download(self,
405404
根据缺失数据,自动种子列表中组合择优下载
406405
:param contexts: 资源上下文列表
407406
:param no_exists: 缺失的剧集信息
408-
:param save_path: 保存路径
407+
:param save_path: 保存路径, 支持<storage>:<path>, 如rclone:/MP, smb:/server/share/Movies等
409408
:param channel: 通知渠道
410409
:param source: 来源(消息通知、订阅、手工下载等)
411410
:param userid: 用户ID

app/modules/qbittorrent/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def __get_torrent_info() -> Tuple[Optional[Torrent], Optional[bytes]]:
150150
# 添加任务
151151
state = server.add_torrent(
152152
content=content,
153-
download_dir=str(download_dir),
153+
download_dir= download_dir.as_posix(),
154154
is_paused=is_paused,
155155
tag=tags,
156156
cookie=cookie,

app/modules/transmission/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def __get_torrent_info() -> Tuple[Optional[Torrent], Optional[bytes]]:
151151
# 添加任务
152152
torrent = server.add_torrent(
153153
content=content,
154-
download_dir=str(download_dir),
154+
download_dir=download_dir.as_posix(),
155155
is_paused=is_paused,
156156
labels=labels,
157157
cookie=cookie

app/schemas/file.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
11
from typing import Optional
22

3+
from pathlib import Path
34
from pydantic import BaseModel, Field
5+
from app.schemas.types import StorageSchema
46

57

6-
class FileItem(BaseModel):
8+
class FileURI(BaseModel):
9+
# 文件路径
10+
path: Optional[str] = "/"
711
# 存储类型
812
storage: Optional[str] = Field(default="local")
13+
14+
@property
15+
def uri(self) -> str:
16+
return self.path if self.storage == "local" else f"{self.storage}:{self.path}"
17+
18+
@classmethod
19+
def from_uri(cls, uri: str) -> "FileURI":
20+
storage, path = 'local', uri
21+
for s in StorageSchema:
22+
protocol = f"{s.value}:"
23+
if uri.startswith(protocol):
24+
path = uri[len(protocol):]
25+
storage = s.value
26+
break
27+
if not path.startswith("/"):
28+
path = "/" + path
29+
path = Path(path).as_posix()
30+
return cls(storage=storage, path=path)
31+
32+
class FileItem(FileURI):
933
# 类型 dir/file
1034
type: Optional[str] = None
11-
# 文件路径
12-
path: Optional[str] = "/"
1335
# 文件名
1436
name: Optional[str] = None
1537
# 文件名
@@ -46,3 +68,4 @@ class StorageUsage(BaseModel):
4668
class StorageTransType(BaseModel):
4769
# 传输类型
4870
transtype: Optional[dict] = Field(default_factory=dict)
71+

app/workflow/actions/add_download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class AddDownloadParams(ActionParams):
1616
添加下载资源参数
1717
"""
1818
downloader: Optional[str] = Field(default=None, description="下载器")
19-
save_path: Optional[str] = Field(default=None, description="保存路径")
19+
save_path: Optional[str] = Field(default=None, description="保存路径, 支持<storage>:<path>, 如rclone:/MP, smb:/server/share/Movies等")
2020
labels: Optional[str] = Field(default=None, description="标签(,分隔)")
2121
only_lack: Optional[bool] = Field(default=False, description="仅下载缺失的资源")
2222

0 commit comments

Comments
 (0)