mirror of
https://github.com/YaoFANGUK/video-subtitle-remover.git
synced 2026-05-17 19:03:28 +08:00
支持设置视频保存路径
This commit is contained in:
@@ -3,10 +3,11 @@
|
||||
"""
|
||||
|
||||
from PySide6 import QtWidgets, QtCore, QtGui
|
||||
from PySide6.QtWidgets import QFileDialog
|
||||
from qfluentwidgets import (ScrollArea, ExpandLayout, CardWidget, SubtitleLabel,
|
||||
FluentIcon, NavigationWidget, NavigationItemPosition,
|
||||
SettingCardGroup, RangeSettingCard, SwitchSettingCard,
|
||||
HyperlinkCard, PrimaryPushSettingCard, ComboBoxSettingCard,
|
||||
HyperlinkCard, PrimaryPushSettingCard, PushSettingCard,
|
||||
MessageBox)
|
||||
from backend.config import config, tr, VERSION, PROJECT_HOME_URL, PROJECT_ISSUES_URL, PROJECT_RELEASES_URL
|
||||
from backend.tools.version_service import VersionService
|
||||
@@ -58,6 +59,7 @@ class AdvancedSettingInterface(ScrollArea):
|
||||
self.propainter_group.addSettingCard(self.propainter_max_load_num)
|
||||
self.expandLayout.addWidget(self.propainter_group)
|
||||
|
||||
self.advanced_group.addSettingCard(self.save_directory)
|
||||
self.advanced_group.addSettingCard(self.check_update_on_startup)
|
||||
self.expandLayout.addWidget(self.advanced_group)
|
||||
|
||||
@@ -170,6 +172,16 @@ class AdvancedSettingInterface(ScrollArea):
|
||||
parent=self.propainter_group
|
||||
)
|
||||
|
||||
# 视频保存路径
|
||||
self.save_directory = PushSettingCard(
|
||||
text=tr["Setting"]["ChooseDirectory"],
|
||||
icon=FluentIcon.DOWNLOAD,
|
||||
title=tr["Setting"]["SaveDirectory"],
|
||||
content=tr["Setting"]["SaveDirectoryDefault"] if not config.saveDirectory.value else config.saveDirectory.value,
|
||||
parent=self.advanced_group
|
||||
)
|
||||
self.save_directory.clicked.connect(self.choose_save_directory)
|
||||
|
||||
self.check_update_on_startup = SwitchSettingCard(
|
||||
configItem=config.checkUpdateOnStartup,
|
||||
icon=FluentIcon.UPDATE,
|
||||
@@ -244,4 +256,15 @@ class AdvancedSettingInterface(ScrollArea):
|
||||
self.show_message_box(
|
||||
tr["Setting"]["NoUpdatesAvailableTitle"],
|
||||
tr["Setting"]["NoUpdatesAvailableDesc"],
|
||||
)
|
||||
)
|
||||
|
||||
def choose_save_directory(self):
|
||||
"""选择保存目录"""
|
||||
last_save_directory = "./" if not config.saveDirectory.value else config.saveDirectory.value
|
||||
folder = QFileDialog.getExistingDirectory(
|
||||
self, tr['Setting']['ChooseDirectory'], last_save_directory)
|
||||
if not folder:
|
||||
folder = ""
|
||||
|
||||
config.set(config.saveDirectory, folder)
|
||||
self.save_directory.setContent(tr["Setting"]["SaveDirectoryDefault"] if not config.saveDirectory.value else config.saveDirectory.value)
|
||||
@@ -1,13 +1,17 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
from enum import Enum, unique
|
||||
from dataclasses import dataclass
|
||||
from functools import cached_property
|
||||
|
||||
from PySide6.QtWidgets import QWidget, QVBoxLayout, QMenu, QAbstractItemView, QTableWidgetItem, QHeaderView
|
||||
from PySide6.QtCore import Qt, Signal, QModelIndex, QUrl
|
||||
from qfluentwidgets import TableWidget, BodyLabel, FluentIcon, InfoBar, InfoBarPosition
|
||||
from PySide6.QtGui import QAction, QColor, QBrush
|
||||
from showinfm import show_in_file_manager
|
||||
|
||||
from backend.config import tr
|
||||
from backend.config import config, tr
|
||||
from backend.tools.common_tools import is_image_file
|
||||
|
||||
@unique
|
||||
class TaskStatus(Enum):
|
||||
@@ -28,8 +32,30 @@ class Task:
|
||||
name: str
|
||||
progress: int
|
||||
status: TaskStatus
|
||||
output_path: str
|
||||
options: dict
|
||||
# 用于储存只读的输出路径, 在任务完成后设置
|
||||
_output_path: str = None
|
||||
|
||||
@property
|
||||
def output_path(self):
|
||||
"""获取输出路径"""
|
||||
if self._output_path is not None:
|
||||
return self._output_path
|
||||
save_directory = os.path.dirname(self.path) if not config.saveDirectory.value else config.saveDirectory.value
|
||||
if self.is_image:
|
||||
output_path = os.path.abspath(os.path.join(save_directory, f'{Path(self.path).stem}_no_sub.png'))
|
||||
else:
|
||||
output_path = os.path.abspath(os.path.join(save_directory, f'{Path(self.path).stem}_no_sub.mp4'))
|
||||
return output_path
|
||||
|
||||
@output_path.setter
|
||||
def output_path(self, value):
|
||||
self._output_path = value
|
||||
|
||||
@cached_property
|
||||
def is_image(self):
|
||||
"""判断是否是图片文件"""
|
||||
return is_image_file(self.path)
|
||||
|
||||
class TaskListComponent(QWidget):
|
||||
"""任务列表组件"""
|
||||
@@ -81,7 +107,7 @@ class TaskListComponent(QWidget):
|
||||
|
||||
layout.addWidget(self.table)
|
||||
|
||||
def add_task(self, video_path, output_path):
|
||||
def add_task(self, video_path):
|
||||
"""添加任务到列表
|
||||
|
||||
Args:
|
||||
@@ -102,7 +128,6 @@ class TaskListComponent(QWidget):
|
||||
name=file_name,
|
||||
progress=0,
|
||||
status=TaskStatus.PENDING,
|
||||
output_path=output_path,
|
||||
options={},
|
||||
)
|
||||
self.tasks.append(task)
|
||||
|
||||
@@ -4,7 +4,6 @@ import threading
|
||||
import multiprocessing
|
||||
import time
|
||||
import traceback
|
||||
from pathlib import Path
|
||||
from PySide6.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout
|
||||
from PySide6.QtCore import Slot, QRect, Signal
|
||||
from PySide6 import QtWidgets
|
||||
@@ -13,7 +12,7 @@ from ui.setting_interface import SettingInterface
|
||||
from ui.component.video_display_component import VideoDisplayComponent
|
||||
from ui.component.task_list_component import TaskListComponent, TaskStatus, TaskOptions
|
||||
from ui.icon.my_fluent_icon import MyFluentIcon
|
||||
from backend.config import tr
|
||||
from backend.config import config, tr
|
||||
from backend.tools.subtitle_remover_remote_call import SubtitleRemoverRemoteCall
|
||||
from backend.tools.process_manager import ProcessManager
|
||||
from backend.tools.common_tools import get_readable_path, is_image_file, read_image
|
||||
@@ -344,12 +343,17 @@ class HomeInterface(QWidget):
|
||||
if key == TaskOptions.SUB_AREAS.value:
|
||||
value = self.video_display_component.preview_coordinates_to_video_coordinates(value)
|
||||
options[key] = value
|
||||
process = self.run_subtitle_remover_process(task.path, task.output_path, options)
|
||||
# 清理缓存, 使用动态路径
|
||||
task.output_path = None
|
||||
output_path = task.output_path
|
||||
process = self.run_subtitle_remover_process(task.path, output_path, options)
|
||||
|
||||
# 更新任务状态为已完成
|
||||
task = self.task_list_component.get_task(self.current_processing_task_index)
|
||||
if process.exitcode == 0 and task and task.status == TaskStatus.PROCESSING:
|
||||
self.progress_signal.emit(100, True)
|
||||
# 任务完成, 更新输出路径为只读
|
||||
task.output_path = output_path
|
||||
self.task_list_component.update_task_status(self.current_processing_task_index, TaskStatus.COMPLETED)
|
||||
else:
|
||||
self.task_list_component.update_task_status(self.current_processing_task_index, TaskStatus.FAILED)
|
||||
@@ -584,11 +588,7 @@ class HomeInterface(QWidget):
|
||||
# 正序添加, 确保任务列表顺序一致
|
||||
for path in reversed(files_loaded):
|
||||
# 添加到任务列表
|
||||
if is_image_file(path):
|
||||
output_path = os.path.abspath(os.path.join(os.path.dirname(path), f'{Path(path).stem}_no_sub.png'))
|
||||
else:
|
||||
output_path = os.path.abspath(os.path.join(os.path.dirname(path), f'{Path(path).stem}_no_sub.mp4'))
|
||||
self.task_list_component.add_task(path, output_path)
|
||||
self.task_list_component.add_task(path)
|
||||
index = max(0, self.task_list_component.find_task_index_by_path(path))
|
||||
self.task_list_component.select_task(index)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user