Skip to content

Commit

Permalink
refactor: get_parent
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Oct 23, 2024
1 parent a441979 commit a6f0792
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
17 changes: 6 additions & 11 deletions app/modules/filemanager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,17 +565,14 @@ def __transfer_subtitles(self, fileitem: FileItem, target_storage: str, target_f
if not storage_oper:
logger.error(f"不支持 {fileitem.storage} 的文件整理")
return False, f"不支持的文件存储:{fileitem.storage}"

# 上级目录
org_dir: Path = org_path.parent
# 查找上级文件项
parent_item: FileItem = storage_oper.get_folder(org_dir)
parent_item: FileItem = storage_oper.get_parent(fileitem)
if not parent_item:
return False, f"{org_dir} 目录获取失败"
return False, f"{org_path} 上级目录获取失败"
# 字幕文件列表
file_list: List[FileItem] = storage_oper.list(parent_item)
if len(file_list) == 0:
logger.debug(f"{org_dir} 目录下没有找到字幕文件...")
logger.debug(f"{parent_item.path} 目录下没有找到字幕文件...")
else:
logger.debug("字幕文件清单:" + str(file_list))
# 识别文件名
Expand Down Expand Up @@ -662,18 +659,16 @@ def __transfer_audio_track_files(self, fileitem: FileItem, target_storage: str,
if not storage_oper:
logger.error(f"不支持 {fileitem.storage} 的文件整理")
return False, f"不支持的文件存储:{fileitem.storage}"
# 上级目录
org_dir = org_path.parent
# 查找上级文件项
parent_item: FileItem = storage_oper.get_folder(org_dir)
parent_item: FileItem = storage_oper.get_parent(fileitem)
if not parent_item:
return False, f"{org_dir} 目录获取失败"
return False, f"{org_path} 上级目录获取失败"
file_list: List[FileItem] = storage_oper.list(parent_item)
# 匹配音轨文件
pending_file_list: List[FileItem] = [file for file in file_list if Path(file.name).stem == org_path.name
and f".{file.extension.lower()}" in settings.RMT_AUDIOEXT]
if len(pending_file_list) == 0:
return True, f"{org_dir} 目录下没有找到匹配的音轨文件"
return True, f"{parent_item.path} 目录下没有找到匹配的音轨文件"
logger.debug("音轨文件清单:" + str(pending_file_list))
for track_file in pending_file_list:
track_ext = f".{track_file.extension}"
Expand Down
6 changes: 6 additions & 0 deletions app/modules/filemanager/storages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ def get_item(self, path: Path) -> Optional[schemas.FileItem]:
"""
pass

def get_parent(self, fileitem: schemas.FileItem) -> Optional[schemas.FileItem]:
"""
获取父目录
"""
return self.get_folder(Path(fileitem.path).parent)

@abstractmethod
def delete(self, fileitem: schemas.FileItem) -> bool:
"""
Expand Down

0 comments on commit a6f0792

Please sign in to comment.