fix LIBRARY_PATH

This commit is contained in:
jxxghp 2023-09-09 21:41:55 +08:00
parent 66b91abe90
commit ca01db31a9
4 changed files with 21 additions and 22 deletions

View File

@ -41,12 +41,7 @@ def storage(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
""" """
查询存储空间信息 查询存储空间信息
""" """
if settings.LIBRARY_PATH: total_storage, free_storage = SystemUtils.space_usage(settings.LIBRARY_PATHS)
total_storage, free_storage = SystemUtils.space_usage(
[Path(path) for path in settings.LIBRARY_PATH.split(",")]
)
else:
total_storage, free_storage = 0, 0
return schemas.Storage( return schemas.Storage(
total_storage=total_storage, total_storage=total_storage,
used_storage=total_storage - free_storage used_storage=total_storage - free_storage

View File

@ -132,13 +132,10 @@ def arr_rootfolder(apikey: str) -> Any:
status_code=403, status_code=403,
detail="认证失败!", detail="认证失败!",
) )
library_path = "/"
if settings.LIBRARY_PATH:
library_path = settings.LIBRARY_PATH.split(",")[0]
return [ return [
{ {
"id": 1, "id": 1,
"path": library_path, "path": "/" if not settings.LIBRARY_PATHS else str(settings.LIBRARY_PATHS[0]),
"accessible": True, "accessible": True,
"freeSpace": 0, "freeSpace": 0,
"unmappedFolders": [] "unmappedFolders": []

View File

@ -1,5 +1,6 @@
import secrets import secrets
from pathlib import Path from pathlib import Path
from typing import List
from pydantic import BaseSettings from pydantic import BaseSettings
@ -165,7 +166,7 @@ class Settings(BaseSettings):
OCR_HOST: str = "https://movie-pilot.org" OCR_HOST: str = "https://movie-pilot.org"
# CookieCloud对应的浏览器UA # CookieCloud对应的浏览器UA
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.57" USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.57"
# 媒体库目录 # 媒体库目录,多个目录使用,分隔
LIBRARY_PATH: str = None LIBRARY_PATH: str = None
# 电影媒体库目录名,默认"电影" # 电影媒体库目录名,默认"电影"
LIBRARY_MOVIE_NAME: str = None LIBRARY_MOVIE_NAME: str = None
@ -251,6 +252,12 @@ class Settings(BaseSettings):
"server": self.PROXY_HOST "server": self.PROXY_HOST
} }
@property
def LIBRARY_PATHS(self) -> List[Path]:
if self.LIBRARY_PATH:
return [Path(path) for path in self.LIBRARY_PATH.split(",")]
return []
def __init__(self): def __init__(self):
super().__init__() super().__init__()
with self.CONFIG_PATH as p: with self.CONFIG_PATH as p:

View File

@ -520,13 +520,13 @@ class FileTransferModule(_ModuleBase):
计算一个最好的目的目录有in_path时找与in_path同路径的没有in_path时顺序查找1个符合大小要求的没有in_path和size时返回第1个 计算一个最好的目的目录有in_path时找与in_path同路径的没有in_path时顺序查找1个符合大小要求的没有in_path和size时返回第1个
:param in_path: 源目录 :param in_path: 源目录
""" """
if not settings.LIBRARY_PATH: if not settings.LIBRARY_PATHS:
return None return None
# 目的路径,多路径以,分隔 # 目的路径,多路径以,分隔
dest_paths = str(settings.LIBRARY_PATH).split(",") dest_paths = settings.LIBRARY_PATHS
# 只有一个路径,直接返回 # 只有一个路径,直接返回
if len(dest_paths) == 1: if len(dest_paths) == 1:
return Path(dest_paths[0]) return dest_paths[0]
# 匹配有最长共同上级路径的目录 # 匹配有最长共同上级路径的目录
max_length = 0 max_length = 0
target_path = None target_path = None
@ -541,15 +541,15 @@ class FileTransferModule(_ModuleBase):
logger.debug(f"计算目标路径时出错:{e}") logger.debug(f"计算目标路径时出错:{e}")
continue continue
if target_path: if target_path:
return Path(target_path) return target_path
# 顺序匹配第1个满足空间存储要求的目录 # 顺序匹配第1个满足空间存储要求的目录
if in_path.exists(): if in_path.exists():
file_size = in_path.stat().st_size file_size = in_path.stat().st_size
for path in dest_paths: for path in dest_paths:
if SystemUtils.free_space(Path(path)) > file_size: if SystemUtils.free_space(path) > file_size:
return Path(path) return path
# 默认返回第1个 # 默认返回第1个
return Path(dest_paths[0]) return dest_paths[0]
def media_exists(self, mediainfo: MediaInfo, itemid: str = None) -> Optional[ExistMediaInfo]: def media_exists(self, mediainfo: MediaInfo, itemid: str = None) -> Optional[ExistMediaInfo]:
""" """
@ -558,14 +558,14 @@ class FileTransferModule(_ModuleBase):
:param itemid: 媒体服务器ItemID :param itemid: 媒体服务器ItemID
:return: 如不存在返回None存在时返回信息包括每季已存在所有集{type: movie/tv, seasons: {season: [episodes]}} :return: 如不存在返回None存在时返回信息包括每季已存在所有集{type: movie/tv, seasons: {season: [episodes]}}
""" """
if not settings.LIBRARY_PATH: if not settings.LIBRARY_PATHS:
return None return None
# 目的路径,多路径以,分隔 # 目的路径
dest_paths = str(settings.LIBRARY_PATH).split(",") dest_paths = settings.LIBRARY_PATHS
# 检查每一个媒体库目录 # 检查每一个媒体库目录
for dest_path in dest_paths: for dest_path in dest_paths:
# 媒体库路径 # 媒体库路径
target_dir = self.get_target_path(Path(dest_path)) target_dir = self.get_target_path(dest_path)
if not target_dir: if not target_dir:
continue continue
# 媒体分类路径 # 媒体分类路径