hahah
This commit is contained in:
493
gui_app.py
493
gui_app.py
@@ -33,10 +33,11 @@ class WorkerThread(QThread):
|
||||
log_message = pyqtSignal(str)
|
||||
progress = pyqtSignal(int)
|
||||
|
||||
def __init__(self, config_data, is_batch_mode, parent=None):
|
||||
def __init__(self, config_data, is_batch_mode, prepared_files=None, parent=None):
|
||||
super().__init__(parent)
|
||||
self.config_data = config_data
|
||||
self.is_batch_mode = is_batch_mode
|
||||
self.prepared_files = prepared_files # 预查找的文件列表
|
||||
self.is_running = True
|
||||
|
||||
def run(self):
|
||||
@@ -65,20 +66,6 @@ class WorkerThread(QThread):
|
||||
config = self.config_data
|
||||
self.log_message.emit(f"开始处理单个任务(逐个上传模式)...")
|
||||
|
||||
# 获取文件夹路径,如果为空则使用默认路径
|
||||
folder_path = config.get('文件夹路径', '').strip()
|
||||
if not folder_path:
|
||||
folder_path = get_default_folder_path()
|
||||
|
||||
if not os.path.exists(folder_path):
|
||||
error_msg = f"文件夹路径不存在: {folder_path}"
|
||||
self.finished.emit(False, error_msg)
|
||||
self.log_message.emit(error_msg)
|
||||
return
|
||||
|
||||
self.log_message.emit(f"使用文件夹路径: {folder_path}")
|
||||
self.progress.emit(30)
|
||||
|
||||
pdd = Pdd(
|
||||
url=config.get('达人链接', ''),
|
||||
user_id=config.get('多多id', ''),
|
||||
@@ -88,26 +75,95 @@ class WorkerThread(QThread):
|
||||
title=config.get('标题', None)
|
||||
)
|
||||
|
||||
# 检查是否勾选了批量上传
|
||||
is_batch_mode = self.is_batch_mode
|
||||
|
||||
# 调用action方法
|
||||
# 如果勾选了批量上传,传递collect_all_videos=True,收集所有视频文件
|
||||
try:
|
||||
pdd.action(folder_path=folder_path, collect_all_videos=is_batch_mode)
|
||||
except Exception as e:
|
||||
error_msg = f"执行action方法失败: {str(e)}"
|
||||
self.log_message.emit(error_msg)
|
||||
logger.error(error_msg)
|
||||
import traceback
|
||||
traceback_str = traceback.format_exc()
|
||||
logger.error(traceback_str)
|
||||
self.log_message.emit(f"错误详情: {traceback_str}")
|
||||
self.finished.emit(False, error_msg)
|
||||
return
|
||||
|
||||
self.progress.emit(100)
|
||||
self.finished.emit(True, "单个任务执行完成")
|
||||
# 如果已经预查找了文件,直接使用
|
||||
if self.prepared_files:
|
||||
self.log_message.emit(f"使用预查找的文件列表,共 {len(self.prepared_files)} 个文件")
|
||||
self.progress.emit(30)
|
||||
|
||||
# 判断是否为视频文件
|
||||
video_extensions = ['.mp4', '.avi', '.mov', '.mkv', '.flv', '.wmv', '.webm']
|
||||
video_files = [f for f in self.prepared_files if f['path'].is_file() and any(f['path'].suffix.lower() == ext for ext in video_extensions)]
|
||||
|
||||
# 如果勾选了批量上传且是视频,调用action1方法
|
||||
if self.is_batch_mode and video_files:
|
||||
# 批量上传视频,调用action1方法
|
||||
self.log_message.emit(f"批量上传模式:找到 {len(video_files)} 个视频文件,调用action1方法")
|
||||
try:
|
||||
pdd.action1(folder_path=video_files)
|
||||
self.progress.emit(100)
|
||||
self.finished.emit(True, f"批量上传完成,共处理 {len(video_files)} 个视频")
|
||||
except Exception as e:
|
||||
error_msg = f"执行action1方法失败: {str(e)}"
|
||||
self.log_message.emit(error_msg)
|
||||
logger.error(error_msg)
|
||||
import traceback
|
||||
traceback_str = traceback.format_exc()
|
||||
logger.error(traceback_str)
|
||||
self.log_message.emit(f"错误详情: {traceback_str}")
|
||||
self.finished.emit(False, error_msg)
|
||||
return
|
||||
else:
|
||||
# 单个上传模式,使用action方法
|
||||
# 从预查找的文件中提取文件夹路径(取第一个文件的父目录的父目录,回到最外层文件夹)
|
||||
if self.prepared_files:
|
||||
first_file = self.prepared_files[0]
|
||||
if first_file['path'].is_file():
|
||||
# 文件路径:最外层文件夹/多多ID文件夹/文件名
|
||||
# 需要回到最外层文件夹
|
||||
folder_path = str(first_file['path'].parent.parent)
|
||||
else:
|
||||
# 文件夹路径:最外层文件夹/多多ID文件夹/文件夹名
|
||||
folder_path = str(first_file['path'].parent.parent)
|
||||
|
||||
self.log_message.emit(f"使用文件夹路径: {folder_path}")
|
||||
try:
|
||||
pdd.action(folder_path=folder_path, collect_all_videos=False)
|
||||
self.progress.emit(100)
|
||||
self.finished.emit(True, "单个任务执行完成")
|
||||
except Exception as e:
|
||||
error_msg = f"执行action方法失败: {str(e)}"
|
||||
self.log_message.emit(error_msg)
|
||||
logger.error(error_msg)
|
||||
import traceback
|
||||
traceback_str = traceback.format_exc()
|
||||
logger.error(traceback_str)
|
||||
self.log_message.emit(f"错误详情: {traceback_str}")
|
||||
self.finished.emit(False, error_msg)
|
||||
return
|
||||
else:
|
||||
# 未预查找文件,使用原来的逻辑
|
||||
folder_path = config.get('文件夹路径', '').strip()
|
||||
if not folder_path:
|
||||
folder_path = get_default_folder_path()
|
||||
|
||||
if not os.path.exists(folder_path):
|
||||
error_msg = f"文件夹路径不存在: {folder_path}"
|
||||
self.finished.emit(False, error_msg)
|
||||
self.log_message.emit(error_msg)
|
||||
return
|
||||
|
||||
self.log_message.emit(f"使用文件夹路径: {folder_path}")
|
||||
self.progress.emit(30)
|
||||
|
||||
# 检查是否勾选了批量上传
|
||||
is_batch_mode = self.is_batch_mode
|
||||
|
||||
# 调用action方法
|
||||
try:
|
||||
pdd.action(folder_path=folder_path, collect_all_videos=is_batch_mode)
|
||||
except Exception as e:
|
||||
error_msg = f"执行action方法失败: {str(e)}"
|
||||
self.log_message.emit(error_msg)
|
||||
logger.error(error_msg)
|
||||
import traceback
|
||||
traceback_str = traceback.format_exc()
|
||||
logger.error(traceback_str)
|
||||
self.log_message.emit(f"错误详情: {traceback_str}")
|
||||
self.finished.emit(False, error_msg)
|
||||
return
|
||||
|
||||
self.progress.emit(100)
|
||||
self.finished.emit(True, "单个任务执行完成")
|
||||
except Exception as e:
|
||||
error_msg = f"执行失败: {str(e)}"
|
||||
self.finished.emit(False, error_msg)
|
||||
@@ -124,25 +180,8 @@ class WorkerThread(QThread):
|
||||
config = self.config_data
|
||||
self.log_message.emit(f"开始处理批量上传任务...")
|
||||
|
||||
# 获取文件夹路径,如果为空则使用默认路径
|
||||
folder_path = config.get('文件夹路径', '').strip()
|
||||
if not folder_path:
|
||||
folder_path = get_default_folder_path()
|
||||
|
||||
if not os.path.exists(folder_path):
|
||||
self.finished.emit(False, f"文件夹路径不存在: {folder_path}")
|
||||
return
|
||||
|
||||
index = config.get('序号', '')
|
||||
|
||||
# 第一步:收集所有视频文件
|
||||
self.log_message.emit("第一步:收集所有视频文件...")
|
||||
video_file_paths = self.prepare_batch_files(folder_path, config)
|
||||
|
||||
# 第二步:收集所有图片文件夹
|
||||
self.log_message.emit("第二步:收集所有图片文件夹...")
|
||||
image_folders = self.prepare_image_folders(folder_path, index)
|
||||
|
||||
# 创建Pdd实例
|
||||
pdd = Pdd(
|
||||
url=config.get('达人链接', ''),
|
||||
@@ -153,36 +192,95 @@ class WorkerThread(QThread):
|
||||
title=config.get('标题', None)
|
||||
)
|
||||
|
||||
# 第三步:如果有视频,批量上传所有视频
|
||||
if video_file_paths:
|
||||
self.log_message.emit(f"找到 {len(video_file_paths)} 个视频文件,开始批量上传...")
|
||||
# 如果已经预查找了文件,直接使用
|
||||
if self.prepared_files:
|
||||
self.log_message.emit(f"使用预查找的文件列表,共 {len(self.prepared_files)} 个文件")
|
||||
self.progress.emit(30)
|
||||
pdd.action1(folder_path=video_file_paths)
|
||||
self.log_message.emit(f"批量上传视频完成,共处理 {len(video_file_paths)} 个视频")
|
||||
else:
|
||||
self.log_message.emit("未找到视频文件,跳过视频上传")
|
||||
|
||||
# 第四步:如果有图片文件夹,逐个上传图片
|
||||
if image_folders:
|
||||
self.log_message.emit(f"找到 {len(image_folders)} 个图片文件夹,开始逐个上传...")
|
||||
self.progress.emit(70)
|
||||
|
||||
for idx, image_folder in enumerate(image_folders):
|
||||
if not self.is_running:
|
||||
break
|
||||
# 分离视频文件和图片文件夹
|
||||
video_extensions = ['.mp4', '.avi', '.mov', '.mkv', '.flv', '.wmv', '.webm']
|
||||
video_file_paths = [f for f in self.prepared_files if f['path'].is_file() and any(f['path'].suffix.lower() == ext for ext in video_extensions)]
|
||||
image_folders = [f for f in self.prepared_files if f['path'].is_dir()]
|
||||
|
||||
# 如果有视频,批量上传所有视频
|
||||
if video_file_paths:
|
||||
self.log_message.emit(f"找到 {len(video_file_paths)} 个视频文件,开始批量上传...")
|
||||
self.progress.emit(30)
|
||||
pdd.action1(folder_path=video_file_paths)
|
||||
self.log_message.emit(f"批量上传视频完成,共处理 {len(video_file_paths)} 个视频")
|
||||
else:
|
||||
self.log_message.emit("未找到视频文件,跳过视频上传")
|
||||
|
||||
# 如果有图片文件夹,逐个上传图片
|
||||
if image_folders:
|
||||
self.log_message.emit(f"找到 {len(image_folders)} 个图片文件夹,开始逐个上传...")
|
||||
self.progress.emit(70)
|
||||
|
||||
self.log_message.emit(f"处理第 {idx + 1}/{len(image_folders)} 个图片文件夹: {image_folder}")
|
||||
# 使用action方法处理图片文件夹
|
||||
pdd.action(folder_path=image_folder)
|
||||
self.log_message.emit(f"图片文件夹 {idx + 1} 上传完成")
|
||||
for idx, image_folder_info in enumerate(image_folders):
|
||||
if not self.is_running:
|
||||
break
|
||||
|
||||
image_folder = str(image_folder_info['path'])
|
||||
self.log_message.emit(f"处理第 {idx + 1}/{len(image_folders)} 个图片文件夹: {image_folder}")
|
||||
# 使用action方法处理图片文件夹
|
||||
pdd.action(folder_path=image_folder)
|
||||
self.log_message.emit(f"图片文件夹 {idx + 1} 上传完成")
|
||||
|
||||
self.log_message.emit(f"所有图片文件夹上传完成,共处理 {len(image_folders)} 个文件夹")
|
||||
else:
|
||||
self.log_message.emit("未找到图片文件夹,跳过图片上传")
|
||||
|
||||
self.log_message.emit(f"所有图片文件夹上传完成,共处理 {len(image_folders)} 个文件夹")
|
||||
self.progress.emit(100)
|
||||
total_count = len(video_file_paths) + len(image_folders)
|
||||
self.finished.emit(True, f"批量任务执行完成,共处理 {len(video_file_paths)} 个视频和 {len(image_folders)} 个图片文件夹")
|
||||
else:
|
||||
self.log_message.emit("未找到图片文件夹,跳过图片上传")
|
||||
|
||||
self.progress.emit(100)
|
||||
total_count = len(video_file_paths) + len(image_folders)
|
||||
self.finished.emit(True, f"批量任务执行完成,共处理 {len(video_file_paths)} 个视频和 {len(image_folders)} 个图片文件夹")
|
||||
# 未预查找文件,使用原来的逻辑
|
||||
folder_path = config.get('文件夹路径', '').strip()
|
||||
if not folder_path:
|
||||
folder_path = get_default_folder_path()
|
||||
|
||||
if not os.path.exists(folder_path):
|
||||
self.finished.emit(False, f"文件夹路径不存在: {folder_path}")
|
||||
return
|
||||
|
||||
# 第一步:收集所有视频文件
|
||||
self.log_message.emit("第一步:收集所有视频文件...")
|
||||
video_file_paths = self.prepare_batch_files(folder_path, config)
|
||||
|
||||
# 第二步:收集所有图片文件夹
|
||||
self.log_message.emit("第二步:收集所有图片文件夹...")
|
||||
image_folders = self.prepare_image_folders(folder_path, index)
|
||||
|
||||
# 第三步:如果有视频,批量上传所有视频
|
||||
if video_file_paths:
|
||||
self.log_message.emit(f"找到 {len(video_file_paths)} 个视频文件,开始批量上传...")
|
||||
self.progress.emit(30)
|
||||
pdd.action1(folder_path=video_file_paths)
|
||||
self.log_message.emit(f"批量上传视频完成,共处理 {len(video_file_paths)} 个视频")
|
||||
else:
|
||||
self.log_message.emit("未找到视频文件,跳过视频上传")
|
||||
|
||||
# 第四步:如果有图片文件夹,逐个上传图片
|
||||
if image_folders:
|
||||
self.log_message.emit(f"找到 {len(image_folders)} 个图片文件夹,开始逐个上传...")
|
||||
self.progress.emit(70)
|
||||
|
||||
for idx, image_folder in enumerate(image_folders):
|
||||
if not self.is_running:
|
||||
break
|
||||
|
||||
self.log_message.emit(f"处理第 {idx + 1}/{len(image_folders)} 个图片文件夹: {image_folder}")
|
||||
# 使用action方法处理图片文件夹
|
||||
pdd.action(folder_path=image_folder)
|
||||
self.log_message.emit(f"图片文件夹 {idx + 1} 上传完成")
|
||||
|
||||
self.log_message.emit(f"所有图片文件夹上传完成,共处理 {len(image_folders)} 个文件夹")
|
||||
else:
|
||||
self.log_message.emit("未找到图片文件夹,跳过图片上传")
|
||||
|
||||
self.progress.emit(100)
|
||||
total_count = len(video_file_paths) + len(image_folders)
|
||||
self.finished.emit(True, f"批量任务执行完成,共处理 {len(video_file_paths)} 个视频和 {len(image_folders)} 个图片文件夹")
|
||||
|
||||
except Exception as e:
|
||||
self.finished.emit(False, f"批量执行失败: {str(e)}")
|
||||
@@ -357,6 +455,7 @@ class MainWindow(QMainWindow):
|
||||
super().__init__()
|
||||
self.worker_thread = None
|
||||
self.configs = [] # 存储从Excel导入的配置
|
||||
self.prepared_files = None # 存储通过"更新数据"找到的文件列表
|
||||
self.init_ui()
|
||||
|
||||
def init_ui(self):
|
||||
@@ -456,6 +555,29 @@ class MainWindow(QMainWindow):
|
||||
tip_label.setStyleSheet("color: #666; font-size: 10px;")
|
||||
config_layout.addWidget(tip_label)
|
||||
|
||||
# 文件路径字段(用于单个文件或文件列表)
|
||||
h8_1 = QHBoxLayout()
|
||||
h8_1.addWidget(QLabel("文件路径:"))
|
||||
self.file_path_input = QLineEdit()
|
||||
self.file_path_input.setPlaceholderText("可选:填写单个文件路径或留空使用文件夹路径查找")
|
||||
h8_1.addWidget(self.file_path_input)
|
||||
self.file_browse_btn = QPushButton("浏览文件")
|
||||
self.file_browse_btn.clicked.connect(self.browse_file)
|
||||
h8_1.addWidget(self.file_browse_btn)
|
||||
config_layout.addLayout(h8_1)
|
||||
|
||||
# 更新数据按钮
|
||||
h8_2 = QHBoxLayout()
|
||||
self.update_data_btn = QPushButton("更新数据")
|
||||
self.update_data_btn.setStyleSheet("background-color: #2196F3; color: white; font-size: 12px; padding: 8px;")
|
||||
self.update_data_btn.clicked.connect(self.update_data)
|
||||
h8_2.addWidget(self.update_data_btn)
|
||||
self.update_status_label = QLabel("未更新")
|
||||
self.update_status_label.setStyleSheet("color: #666; font-size: 10px;")
|
||||
h8_2.addWidget(self.update_status_label)
|
||||
h8_2.addStretch()
|
||||
config_layout.addLayout(h8_2)
|
||||
|
||||
# 批量上传勾选框
|
||||
h9 = QHBoxLayout()
|
||||
self.batch_upload_checkbox = QCheckBox("批量上传(如果文件夹中有多个视频,将使用批量上传模式)")
|
||||
@@ -483,7 +605,7 @@ class MainWindow(QMainWindow):
|
||||
main_layout.addWidget(self.table_group)
|
||||
|
||||
# 执行按钮
|
||||
self.execute_btn = QPushButton("开始执行")
|
||||
self.execute_btn = QPushButton("开始上传")
|
||||
self.execute_btn.setStyleSheet("background-color: #4CAF50; color: white; font-size: 14px; padding: 10px;")
|
||||
self.execute_btn.clicked.connect(self.execute_task)
|
||||
main_layout.addWidget(self.execute_btn)
|
||||
@@ -520,6 +642,14 @@ class MainWindow(QMainWindow):
|
||||
folder_path = QFileDialog.getExistingDirectory(self, "选择文件夹")
|
||||
if folder_path:
|
||||
self.folder_path_input.setText(folder_path)
|
||||
|
||||
def browse_file(self):
|
||||
"""浏览文件"""
|
||||
file_path, _ = QFileDialog.getOpenFileName(
|
||||
self, "选择文件", "", "所有文件 (*.*)"
|
||||
)
|
||||
if file_path:
|
||||
self.file_path_input.setText(file_path)
|
||||
|
||||
def import_excel(self):
|
||||
"""导入Excel配置文件"""
|
||||
@@ -637,8 +767,156 @@ class MainWindow(QMainWindow):
|
||||
'达人链接': self.url_input.text(),
|
||||
'执行人': self.executor_input.text(),
|
||||
'文件夹路径': folder_path,
|
||||
'文件路径': self.file_path_input.text().strip(),
|
||||
'情况': '待执行'
|
||||
}
|
||||
|
||||
def update_data(self):
|
||||
"""更新数据:找出文件并保存"""
|
||||
try:
|
||||
# 优先使用Excel导入的配置(如果存在)
|
||||
if self.configs and self.config_table.rowCount() > 0:
|
||||
config = self.get_config_from_table(0)
|
||||
if not config:
|
||||
QMessageBox.warning(self, "警告", "无法获取配置数据")
|
||||
return
|
||||
# 添加文件夹路径
|
||||
folder_path = self.folder_path_input.text().strip()
|
||||
if not folder_path:
|
||||
folder_path = get_default_folder_path()
|
||||
config['文件夹路径'] = folder_path
|
||||
config['文件路径'] = self.file_path_input.text().strip()
|
||||
else:
|
||||
config = self.get_config()
|
||||
|
||||
# 验证必填字段
|
||||
if not config.get('多多id') or not config.get('序号'):
|
||||
QMessageBox.warning(self, "警告", "请先填写多多ID和序号")
|
||||
return
|
||||
|
||||
# 获取文件夹路径或文件路径
|
||||
folder_path = config.get('文件夹路径', '')
|
||||
file_path = config.get('文件路径', '').strip()
|
||||
|
||||
if not folder_path:
|
||||
folder_path = get_default_folder_path()
|
||||
|
||||
if not os.path.exists(folder_path):
|
||||
QMessageBox.warning(self, "警告", f"文件夹路径不存在: {folder_path}")
|
||||
return
|
||||
|
||||
self.log_text.append("=" * 50)
|
||||
self.log_text.append("开始更新数据,查找文件...")
|
||||
|
||||
# 如果指定了文件路径,直接使用该文件
|
||||
if file_path and os.path.exists(file_path):
|
||||
self.log_text.append(f"使用指定的文件路径: {file_path}")
|
||||
path_obj = Path(file_path)
|
||||
if path_obj.is_file():
|
||||
# 判断是否为视频文件
|
||||
video_extensions = ['.mp4', '.avi', '.mov', '.mkv', '.flv', '.wmv', '.webm']
|
||||
is_video = any(path_obj.suffix.lower() == ext for ext in video_extensions)
|
||||
|
||||
self.prepared_files = [{
|
||||
"url": config.get('达人链接', ''),
|
||||
"user_id": config.get('多多id', ''),
|
||||
"time_start": config.get('定时发布', '') if config.get('定时发布') else None,
|
||||
"ht": config.get('话题', ''),
|
||||
"index": config.get('序号', ''),
|
||||
"path": path_obj
|
||||
}]
|
||||
|
||||
file_type = "视频" if is_video else "文件"
|
||||
self.log_text.append(f"找到 1 个{file_type}文件: {path_obj.name}")
|
||||
self.update_status_label.setText(f"已更新: 1个{file_type}文件")
|
||||
self.update_status_label.setStyleSheet("color: #4CAF50; font-size: 10px;")
|
||||
QMessageBox.information(self, "成功", f"已找到 1 个{file_type}文件")
|
||||
return
|
||||
else:
|
||||
QMessageBox.warning(self, "警告", "指定的路径不是文件")
|
||||
return
|
||||
|
||||
# 否则在文件夹中查找文件
|
||||
index = config.get('序号', '')
|
||||
video_extensions = ['.mp4', '.avi', '.mov', '.mkv', '.flv', '.wmv', '.webm']
|
||||
|
||||
found_files = []
|
||||
|
||||
# 遍历最外层文件夹下的所有子文件夹
|
||||
subdirs = [f for f in os.listdir(folder_path) if os.path.isdir(os.path.join(folder_path, f))]
|
||||
self.log_text.append(f"在最外层文件夹下找到 {len(subdirs)} 个子文件夹")
|
||||
|
||||
# 找到匹配当前多多ID的文件夹
|
||||
target_subdir = None
|
||||
for subdir_name in subdirs:
|
||||
if subdir_name == str(config.get('多多id')):
|
||||
target_subdir = os.path.join(folder_path, subdir_name)
|
||||
self.log_text.append(f"找到匹配的多多ID文件夹: {subdir_name}")
|
||||
break
|
||||
|
||||
if not target_subdir:
|
||||
QMessageBox.warning(self, "警告", f"未找到多多ID为 {config.get('多多id')} 的文件夹")
|
||||
self.log_text.append(f"未找到匹配的多多ID文件夹")
|
||||
return
|
||||
|
||||
# 扫描该文件夹下的文件
|
||||
items = os.listdir(target_subdir)
|
||||
self.log_text.append(f"扫描文件夹: {os.path.basename(target_subdir)},共 {len(items)} 个项目")
|
||||
|
||||
for item_name in items:
|
||||
item_path = os.path.join(target_subdir, item_name)
|
||||
name_parts = item_name.split("-")
|
||||
|
||||
# 检查序号是否匹配
|
||||
if len(name_parts) > 0 and name_parts[0] == str(index):
|
||||
path_obj = Path(item_path)
|
||||
|
||||
if path_obj.is_file():
|
||||
# 检查是否为视频文件
|
||||
if any(path_obj.suffix.lower() == ext for ext in video_extensions):
|
||||
found_files.append({
|
||||
"url": config.get('达人链接', ''),
|
||||
"user_id": config.get('多多id', ''),
|
||||
"time_start": config.get('定时发布', '') if config.get('定时发布') else None,
|
||||
"ht": config.get('话题', ''),
|
||||
"index": str(index),
|
||||
"path": path_obj
|
||||
})
|
||||
self.log_text.append(f"找到视频文件: {item_name}")
|
||||
else:
|
||||
# 如果是文件夹,可能是图片文件夹
|
||||
found_files.append({
|
||||
"url": config.get('达人链接', ''),
|
||||
"user_id": config.get('多多id', ''),
|
||||
"time_start": config.get('定时发布', '') if config.get('定时发布') else None,
|
||||
"ht": config.get('话题', ''),
|
||||
"index": str(index),
|
||||
"path": path_obj
|
||||
})
|
||||
self.log_text.append(f"找到文件夹: {item_name}")
|
||||
|
||||
if found_files:
|
||||
self.prepared_files = found_files
|
||||
video_count = sum(1 for f in found_files if f['path'].is_file() and any(f['path'].suffix.lower() == ext for ext in video_extensions))
|
||||
folder_count = len(found_files) - video_count
|
||||
self.log_text.append(f"更新完成!找到 {len(found_files)} 个文件/文件夹({video_count} 个视频,{folder_count} 个文件夹)")
|
||||
self.update_status_label.setText(f"已更新: {len(found_files)}个文件")
|
||||
self.update_status_label.setStyleSheet("color: #4CAF50; font-size: 10px;")
|
||||
QMessageBox.information(self, "成功", f"已找到 {len(found_files)} 个文件/文件夹")
|
||||
else:
|
||||
self.prepared_files = None
|
||||
self.log_text.append("未找到匹配的文件")
|
||||
self.update_status_label.setText("未找到文件")
|
||||
self.update_status_label.setStyleSheet("color: #f44336; font-size: 10px;")
|
||||
QMessageBox.warning(self, "警告", "未找到匹配的文件")
|
||||
|
||||
except Exception as e:
|
||||
error_msg = f"更新数据失败: {str(e)}"
|
||||
self.log_text.append(error_msg)
|
||||
QMessageBox.critical(self, "错误", error_msg)
|
||||
logger.error(f"更新数据失败: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
def execute_task(self):
|
||||
"""执行任务"""
|
||||
@@ -670,26 +948,25 @@ class MainWindow(QMainWindow):
|
||||
# 检查是否勾选了批量上传
|
||||
is_batch_mode = self.batch_upload_checkbox.isChecked()
|
||||
|
||||
# 如果勾选了批量上传,检查文件夹中是否有多个视频(不限制序号)
|
||||
if is_batch_mode:
|
||||
# 在批量上传模式下,统计同一个多多ID文件夹下的所有视频文件
|
||||
video_count = self.count_all_videos_in_user_folder(config.get('文件夹路径'), config.get('多多id'))
|
||||
if video_count > 1:
|
||||
self.log_text.append(f"检测到 {video_count} 个视频(同一多多ID文件夹),使用批量上传模式...")
|
||||
elif video_count == 1:
|
||||
self.log_text.append(f"只找到 {video_count} 个视频,将使用单个上传模式...")
|
||||
is_batch_mode = False
|
||||
else:
|
||||
self.log_text.append(f"未找到视频文件,将使用单个上传模式...")
|
||||
# 如果已经更新了数据,根据预查找的文件判断是否为批量上传
|
||||
if self.prepared_files:
|
||||
video_extensions = ['.mp4', '.avi', '.mov', '.mkv', '.flv', '.wmv', '.webm']
|
||||
video_files = [f for f in self.prepared_files if f['path'].is_file() and any(f['path'].suffix.lower() == ext for ext in video_extensions)]
|
||||
if is_batch_mode and len(video_files) > 1:
|
||||
self.log_text.append(f"检测到 {len(video_files)} 个视频文件,使用批量上传模式...")
|
||||
elif is_batch_mode and len(video_files) <= 1:
|
||||
self.log_text.append(f"只找到 {len(video_files)} 个视频文件,将使用单个上传模式...")
|
||||
is_batch_mode = False
|
||||
elif not is_batch_mode:
|
||||
self.log_text.append(f"使用单个上传模式...")
|
||||
|
||||
# 禁用按钮
|
||||
self.execute_btn.setEnabled(False)
|
||||
self.progress_bar.setVisible(True)
|
||||
self.progress_bar.setValue(0)
|
||||
|
||||
# 创建工作线程
|
||||
self.worker_thread = WorkerThread(config, is_batch_mode, self)
|
||||
# 创建工作线程,传递预查找的文件列表
|
||||
self.worker_thread = WorkerThread(config, is_batch_mode, self.prepared_files, self)
|
||||
self.worker_thread.finished.connect(self.on_task_finished)
|
||||
self.worker_thread.log_message.connect(self.log_text.append)
|
||||
self.worker_thread.progress.connect(self.progress_bar.setValue)
|
||||
@@ -697,7 +974,10 @@ class MainWindow(QMainWindow):
|
||||
|
||||
self.log_text.append("=" * 50)
|
||||
mode_text = "批量上传" if is_batch_mode else "逐个上传"
|
||||
self.log_text.append(f"开始执行任务({mode_text}模式)...")
|
||||
if self.prepared_files:
|
||||
self.log_text.append(f"开始执行任务({mode_text}模式,使用预查找的文件列表)...")
|
||||
else:
|
||||
self.log_text.append(f"开始执行任务({mode_text}模式)...")
|
||||
|
||||
def execute_batch_from_excel(self):
|
||||
"""从Excel配置批量执行(使用表格中修改后的配置)"""
|
||||
@@ -727,25 +1007,25 @@ class MainWindow(QMainWindow):
|
||||
config['文件夹路径'] = folder_path
|
||||
|
||||
# 检查是否勾选了批量上传
|
||||
if is_batch_mode:
|
||||
# 在批量上传模式下,统计同一个多多ID文件夹下的所有视频文件
|
||||
video_count = self.count_all_videos_in_user_folder(folder_path, config.get('多多id'))
|
||||
if video_count > 1:
|
||||
self.log_text.append(f"检测到 {video_count} 个视频(同一多多ID文件夹),使用批量上传模式...")
|
||||
elif video_count == 1:
|
||||
self.log_text.append(f"只找到 {video_count} 个视频,将使用单个上传模式...")
|
||||
is_batch_mode = False
|
||||
else:
|
||||
self.log_text.append(f"未找到视频文件,将使用单个上传模式...")
|
||||
# 如果已经更新了数据,根据预查找的文件判断是否为批量上传
|
||||
if self.prepared_files:
|
||||
video_extensions = ['.mp4', '.avi', '.mov', '.mkv', '.flv', '.wmv', '.webm']
|
||||
video_files = [f for f in self.prepared_files if f['path'].is_file() and any(f['path'].suffix.lower() == ext for ext in video_extensions)]
|
||||
if is_batch_mode and len(video_files) > 1:
|
||||
self.log_text.append(f"检测到 {len(video_files)} 个视频文件,使用批量上传模式...")
|
||||
elif is_batch_mode and len(video_files) <= 1:
|
||||
self.log_text.append(f"只找到 {len(video_files)} 个视频文件,将使用单个上传模式...")
|
||||
is_batch_mode = False
|
||||
elif not is_batch_mode:
|
||||
self.log_text.append(f"使用单个上传模式...")
|
||||
|
||||
# 禁用按钮
|
||||
self.execute_btn.setEnabled(False)
|
||||
self.progress_bar.setVisible(True)
|
||||
self.progress_bar.setValue(0)
|
||||
|
||||
# 创建工作线程
|
||||
self.worker_thread = WorkerThread(config, is_batch_mode, self)
|
||||
# 创建工作线程,传递预查找的文件列表
|
||||
self.worker_thread = WorkerThread(config, is_batch_mode, self.prepared_files, self)
|
||||
self.worker_thread.finished.connect(self.on_task_finished)
|
||||
self.worker_thread.log_message.connect(self.log_text.append)
|
||||
self.worker_thread.progress.connect(self.progress_bar.setValue)
|
||||
@@ -753,7 +1033,10 @@ class MainWindow(QMainWindow):
|
||||
|
||||
self.log_text.append("=" * 50)
|
||||
mode_text = "批量上传" if is_batch_mode else "逐个上传"
|
||||
self.log_text.append(f"开始执行任务({mode_text}模式)...")
|
||||
if self.prepared_files:
|
||||
self.log_text.append(f"开始执行任务({mode_text}模式,使用预查找的文件列表)...")
|
||||
else:
|
||||
self.log_text.append(f"开始执行任务({mode_text}模式)...")
|
||||
self.log_text.append(f"使用配置 - 多多ID: {config.get('多多id')}, 序号: {config.get('序号')}, 话题: {config.get('话题')}")
|
||||
|
||||
def count_videos_in_folder(self, folder_path, index):
|
||||
|
||||
Reference in New Issue
Block a user