Browse Source

保存下载字幕文件遇到特殊字符的问题 fix #437

Signed-off-by: allan716 <[email protected]>
allan716 3 years ago
parent
commit
48386df596
2 changed files with 6 additions and 2 deletions
  1. 1 1
      pkg/decode/decode.go
  2. 5 1
      pkg/sub_helper/sub_helper.go

+ 1 - 1
pkg/decode/decode.go

@@ -573,7 +573,7 @@ const (
 	// 去除特殊字符,仅仅之有中文
 	regFixTitle = "[^\u4e00-\u9fa5a-zA-Z0-9\\s]"
 	// 去除特殊字符,把特殊字符都写进去
-	regFixTitle2 = "[~!@#$%^&*()\\+\\-=|{}';'\\[\\].<>/?~!@#¥%……&*()——+|{}【】';”“’。、?]"
+	regFixTitle2 = "[~!@#$%^&*:()\\+\\-=|{}';'\\[\\].<>/?~!@#¥%……&*()——+|{}【】';”“’。、?]"
 	// 获取数字
 	regGetNumber = "(?:\\-)?\\d{1,}(?:\\.\\d{1,})?"
 )

+ 5 - 1
pkg/sub_helper/sub_helper.go

@@ -214,10 +214,14 @@ func GetFrontNameAndOrgName(log *logrus.Logger, info *supplier.SubInfo) string {
 	fileName, err := decode.GetVideoInfoFromFileName(info.Name)
 	if err != nil {
 		log.Warnln("", err)
-		infoName = info.Name
+		// 替换特殊字符
+		infoName = my_util.ReplaceSpecString(info.Name, "x")
 	} else {
 		infoName = fileName.Title + "_S" + strconv.Itoa(fileName.Season) + "E" + strconv.Itoa(fileName.Episode) + filepath.Ext(info.Name)
 	}
+	if len(infoName) < 1 {
+		infoName = my_util.RandStringBytesMaskImprSrcSB(10) + filepath.Ext(info.Name)
+	}
 	info.Name = infoName
 
 	return "[" + info.FromWhere + "]_" + strconv.FormatInt(info.TopN, 10) + "_" + infoName