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.

fix: ffmpeg error when use youtube link

沈浩204972a4c564
diff --git a/internal/service/subtitle_service.go b/internal/service/subtitle_service.go
index 3ef59277..b3b57ee5 100644
--- a/internal/service/subtitle_service.go
+++ b/internal/service/subtitle_service.go
@@ -33,7 +33,7 @@ func (s Service) StartSubtitleTask(req dto.StartVideoSubtitleTaskReq) (*dto.Star
}
// 生成任务id
seperates := strings.Split(req.Url, "/")
- taskId := fmt.Sprintf("%s_%s", string([]rune(strings.ReplaceAll(seperates[len(seperates)-1], " ", ""))[:16]), util.GenerateRandStringWithUpperLowerNum(4))
+ taskId := fmt.Sprintf("%s_%s", util.KeepOnlyAlphanumeric(string([]rune(strings.ReplaceAll(seperates[len(seperates)-1], " ", ""))[:16])), util.GenerateRandStringWithUpperLowerNum(4))
// 构造任务所需参数
var resultType types.SubtitleResultType
// 根据入参选项确定要返回的字幕类型
diff --git a/pkg/util/base.go b/pkg/util/base.go
index 7aaa63a5..3f688abc 100644
--- a/pkg/util/base.go
+++ b/pkg/util/base.go
@@ -184,3 +184,14 @@ func CopyFile(src, dst string) error {
return destinationFile.Sync()
}
+
+// KeepOnlyAlphanumeric 只保留字母(a-zA-Z)和数字(0-9)
+func KeepOnlyAlphanumeric(input string) string {
+ var result []rune
+ for _, r := range input {
+ if unicode.IsLetter(r) || unicode.IsNumber(r) {
+ result = append(result, r)
+ }
+ }
+ return string(result)
+}