Skip to content

Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.

1. Added multi-file download functionality, allowing multiple files to be uploaded at once. 2. Modified the resolution retrieval code to remove a potentially redundant trailing 'x' and use regular expression matching.

Puji0d45fab44ce0
diff --git a/internal/handler/subtitle_task.go b/internal/handler/subtitle_task.go
index 26a22d27..070a39dc 100644
--- a/internal/handler/subtitle_task.go
+++ b/internal/handler/subtitle_task.go
@@ -65,7 +65,7 @@ func (h Handler) GetSubtitleTask(c *gin.Context) {
}
func (h Handler) UploadFile(c *gin.Context) {
- file, err := c.FormFile("file")
+ form, err := c.MultipartForm()
if err != nil {
response.R(c, response.Response{
Error: -1,
@@ -75,20 +75,35 @@ func (h Handler) UploadFile(c *gin.Context) {
return
}
- savePath := "./uploads/" + file.Filename
- if err = c.SaveUploadedFile(file, savePath); err != nil {
+ files := form.File["file"]
+ if len(files) == 0 {
response.R(c, response.Response{
Error: -1,
- Msg: "文件保存失败",
+ Msg: "未上传任何文件",
Data: nil,
})
return
}
+ // 保存每个文件
+ var savedFiles []string
+ for _, file := range files {
+ savePath := "./uploads/" + file.Filename
+ if err := c.SaveUploadedFile(file, savePath); err != nil {
+ response.R(c, response.Response{
+ Error: -1,
+ Msg: "文件保存失败: " + file.Filename,
+ Data: nil,
+ })
+ return
+ }
+ savedFiles = append(savedFiles, "local:"+savePath)
+ }
+
response.R(c, response.Response{
Error: 0,
Msg: "文件上传成功",
- Data: gin.H{"file_path": "local:" + savePath},
+ Data: gin.H{"file_path": savedFiles},
})
}
diff --git a/internal/service/srt_embed.go b/internal/service/srt_embed.go
index d2d6504f..2576e9dc 100644
--- a/internal/service/srt_embed.go
+++ b/internal/service/srt_embed.go
@@ -364,13 +364,17 @@ func getResolution(inputVideo string) (int, int, error) {
}
output := strings.TrimSpace(out.String())
- dimensions := strings.Split(output, "x")
- if len(dimensions) != 2 {
+ output = strings.TrimSuffix(output, "x") // 去除尾部可能存在的x,例如1920x1080x
+
+ re := regexp.MustCompile(`^(\d+)x(\d+)$`)
+ dimensions := re.FindStringSubmatch(output)
+ if len(dimensions) != 3 {
log.GetLogger().Error("获取视频分辨率失败", zap.String("output", output))
return 0, 0, fmt.Errorf("invalid resolution format: %s", output)
}
- width, _ := strconv.Atoi(dimensions[0])
- height, _ := strconv.Atoi(dimensions[1])
+
+ width, _ := strconv.Atoi(dimensions[1])
+ height, _ := strconv.Atoi(dimensions[2])
return width, height, nil
}
diff --git a/static/index.html b/static/index.html
index a44df6b3..715ef666 100644
--- a/static/index.html
+++ b/static/index.html
@@ -316,7 +316,7 @@
<div class="formItem hidden" id="fileInputContainer">
<label for="fileInput">上传本地视频:</label>
- <input style="margin-left: 6px" type="file" id="fileInput" name="fileInput" accept="video/*, audio/*">
+ <input style="margin-left: 6px" type="file" id="fileInput" name="fileInput" accept="video/*, audio/*" multiple>
<p id="uploadStatus" class="loading hidden">正在上传...</p>
</div>
@@ -680,10 +680,10 @@
uploadStatus.classList.remove('hidden');
executeButton.disabled = true; // 禁用“执行”按钮
- const file = fileInput.files[0];
-
const formData = new FormData();
- formData.append('file', file);
+ for (const file of fileInput.files) {
+ formData.append('file', file); // 确保字段名与后端一致
+ }
try {
const response = await fetch(API_UPLOAD_URL, {
@@ -694,9 +694,9 @@
const res = await response.json();
const { error, data, msg } = res || {};
if (error !== 0 && error !== 200) {
- throw new Error(msg || '上传失败,请重试')
+ throw new Error(msg || '上传失败,请重试');
}
- uploadedVideoUrl = data.file_path; // 获取返回的视频地址
+ uploadedVideoUrl = data.file_path; // 获取返回的文件路径数组
executeButton.disabled = false; // 启用“执行”按钮
} catch (error) {
console.error('视频上传失败:', error);
@@ -781,16 +781,22 @@
const params = getParams();
// 请求启动任务接口
- const taskId = await startTask({...params, url});
-
- downloadLinks.classList.add('hidden');
- downloadLinks.innerHTML = ''; // 清空之前的下载链接
-
- if (taskId) {
- executeButton.disabled = true;
- // 显示任务进度区域
- progressSection.classList.remove('hidden');
- await pollTaskProgress(taskId);
+ if (Array.isArray(url)) {
+ for (const singleUrl of url) {
+ const taskId = await startTask({ ...params, url: singleUrl });
+ if (taskId) {
+ executeButton.disabled = true;
+ progressSection.classList.remove('hidden');
+ await pollTaskProgress(taskId);
+ }
+ }
+ } else {
+ const taskId = await startTask({ ...params, url });
+ if (taskId) {
+ executeButton.disabled = true;
+ progressSection.classList.remove('hidden');
+ await pollTaskProgress(taskId);
+ }
}
});