|
|
@@ -230,8 +230,8 @@ func SearchMatchedSubFile(dir string) ([]string, error) {
|
|
|
return fileFullPathList, nil
|
|
|
}
|
|
|
|
|
|
-// SearchVideoMatchSubFileAndRemoveDefaultMark 找到找个视频目录下相匹配的字幕,同时去除这些字幕中 .default 的标记
|
|
|
-func SearchVideoMatchSubFileAndRemoveDefaultMark(oneVideoFullPath string) error {
|
|
|
+// SearchVideoMatchSubFileAndRemoveExtMark 找到找个视频目录下相匹配的字幕,同时去除这些字幕中 .default 或者 .forced 的标记。注意这两个标记不应该同时出现,否则无法正确去除
|
|
|
+func SearchVideoMatchSubFileAndRemoveExtMark(oneVideoFullPath string) error {
|
|
|
|
|
|
dir := filepath.Dir(oneVideoFullPath)
|
|
|
fileName := filepath.Base(oneVideoFullPath)
|
|
|
@@ -261,147 +261,30 @@ func SearchVideoMatchSubFileAndRemoveDefaultMark(oneVideoFullPath string) error
|
|
|
continue
|
|
|
}
|
|
|
// 得包含 .default. 找个关键词
|
|
|
- if strings.Contains(nowFileName, types.Emby_default+".") == false {
|
|
|
+ if strings.Contains(nowFileName, types.Sub_Ext_Mark_Default+".") == true {
|
|
|
+ oldPath := dir + pathSep + curFile.Name()
|
|
|
+ newPath := dir + pathSep + strings.ReplaceAll(curFile.Name(), types.Sub_Ext_Mark_Default+".", ".")
|
|
|
+ err = os.Rename(oldPath, newPath)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ } else if strings.Contains(nowFileName, types.Sub_Ext_Mark_Forced+".") == true {
|
|
|
+ // 得包含 .forced. 找个关键词
|
|
|
+ oldPath := dir + pathSep + curFile.Name()
|
|
|
+ newPath := dir + pathSep + strings.ReplaceAll(curFile.Name(), types.Sub_Ext_Mark_Forced+".", ".")
|
|
|
+ err = os.Rename(oldPath, newPath)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ } else {
|
|
|
continue
|
|
|
}
|
|
|
- oldPath := dir + pathSep + curFile.Name()
|
|
|
- newPath := dir + pathSep + strings.ReplaceAll(curFile.Name(), types.Emby_default+".", ".")
|
|
|
- err = os.Rename(oldPath, newPath)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-// IsOldVersionSubPrefixName 是否是老版本的字幕命名 .chs_en[shooter] ,符合也返回这个部分+字幕格式后缀名 .chs_en[shooter].ass, 修改后的名称
|
|
|
-func IsOldVersionSubPrefixName(subFileName string) (bool, string, string) {
|
|
|
-
|
|
|
- /*
|
|
|
- 传入的必须是字幕格式的文件,这个就再之前判断,不要在这里再判断
|
|
|
- 传入的文件名可能有一下几种情况
|
|
|
- 无罪之最 - S01E01 - 重建生活.chs[shooter].ass
|
|
|
- 无罪之最 - S01E03 - 初见端倪.zh.srt
|
|
|
- Loki - S01E01 - Glorious Purpose WEBDL-1080p Proper.chs_en.ass
|
|
|
- 那么就需要先剔除,字幕的格式后缀名,然后再向后取后缀名就是 .chs[shooter] or .zh
|
|
|
- 再判断即可
|
|
|
- */
|
|
|
- // 无罪之最 - S01E01 - 重建生活.chs[shooter].ass -> 无罪之最 - S01E01 - 重建生活.chs[shooter]
|
|
|
- subTypeExt := filepath.Ext(subFileName)
|
|
|
- subFileNameWithOutExt := strings.ReplaceAll(subFileName, subTypeExt, "")
|
|
|
- // .chs[shooter]
|
|
|
- nowExt := filepath.Ext(subFileNameWithOutExt)
|
|
|
- // .chs_en[shooter].ass
|
|
|
- orgMixExt := nowExt + subTypeExt
|
|
|
- orgFileNameWithOutOrgMixExt := strings.ReplaceAll(subFileName, orgMixExt, "")
|
|
|
- // 这里也有两种情况,一种是单字幕 SaveMultiSub: false
|
|
|
- // 一种的保存了多字幕 SaveMultiSub: true
|
|
|
- // 先判断 单字幕
|
|
|
- switch nowExt {
|
|
|
- case types.Emby_chs:
|
|
|
- return true, orgMixExt, makeMixSubExtString(orgFileNameWithOutOrgMixExt, types.MatchLangChs, subTypeExt, "", true)
|
|
|
- case types.Emby_cht:
|
|
|
- return true, orgMixExt, makeMixSubExtString(orgFileNameWithOutOrgMixExt, types.MatchLangCht, subTypeExt, "", false)
|
|
|
- case types.Emby_chs_en:
|
|
|
- return true, orgMixExt, makeMixSubExtString(orgFileNameWithOutOrgMixExt, types.MatchLangChsEn, subTypeExt, "", true)
|
|
|
- case types.Emby_cht_en:
|
|
|
- return true, orgMixExt, makeMixSubExtString(orgFileNameWithOutOrgMixExt, types.MatchLangChtEn, subTypeExt, "", false)
|
|
|
- case types.Emby_chs_jp:
|
|
|
- return true, orgMixExt, makeMixSubExtString(orgFileNameWithOutOrgMixExt, types.MatchLangChsJp, subTypeExt, "", true)
|
|
|
- case types.Emby_cht_jp:
|
|
|
- return true, orgMixExt, makeMixSubExtString(orgFileNameWithOutOrgMixExt, types.MatchLangChtJp, subTypeExt, "", false)
|
|
|
- case types.Emby_chs_kr:
|
|
|
- return true, orgMixExt, makeMixSubExtString(orgFileNameWithOutOrgMixExt, types.MatchLangChsKr, subTypeExt, "", true)
|
|
|
- case types.Emby_cht_kr:
|
|
|
- return true, orgMixExt, makeMixSubExtString(orgFileNameWithOutOrgMixExt, types.MatchLangChtKr, subTypeExt, "", false)
|
|
|
- }
|
|
|
- // 再判断 多字幕情况
|
|
|
- spStrings := strings.Split(nowExt, "[")
|
|
|
- if len(spStrings) != 2 {
|
|
|
- return false, "", ""
|
|
|
- }
|
|
|
- // 分两段来判断是否符合标准
|
|
|
- // 第一段
|
|
|
- firstOk := true
|
|
|
- lang := types.MatchLangChs
|
|
|
- site := ""
|
|
|
- switch spStrings[0] {
|
|
|
- case types.Emby_chs:
|
|
|
- lang = types.MatchLangChs
|
|
|
- case types.Emby_cht:
|
|
|
- lang = types.MatchLangCht
|
|
|
- case types.Emby_chs_en:
|
|
|
- lang = types.MatchLangChsEn
|
|
|
- case types.Emby_cht_en:
|
|
|
- lang = types.MatchLangChtEn
|
|
|
- case types.Emby_chs_jp:
|
|
|
- lang = types.MatchLangChsJp
|
|
|
- case types.Emby_cht_jp:
|
|
|
- lang = types.MatchLangChtJp
|
|
|
- case types.Emby_chs_kr:
|
|
|
- lang = types.MatchLangChsKr
|
|
|
- case types.Emby_cht_kr:
|
|
|
- lang = types.MatchLangChtKr
|
|
|
- default:
|
|
|
- firstOk = false
|
|
|
- }
|
|
|
- // 第二段
|
|
|
- secondOk := true
|
|
|
- tmpSecond := strings.ReplaceAll(spStrings[1], "]", "")
|
|
|
- switch tmpSecond {
|
|
|
- case common.SubSiteZiMuKu:
|
|
|
- site = common.SubSiteZiMuKu
|
|
|
- case common.SubSiteSubHd:
|
|
|
- site = common.SubSiteSubHd
|
|
|
- case common.SubSiteShooter:
|
|
|
- site = common.SubSiteShooter
|
|
|
- case common.SubSiteXunLei:
|
|
|
- site = common.SubSiteXunLei
|
|
|
- default:
|
|
|
- secondOk = false
|
|
|
- }
|
|
|
- // 都要符合条件
|
|
|
- if firstOk == true && secondOk == true {
|
|
|
- return true, orgMixExt, makeMixSubExtString(orgFileNameWithOutOrgMixExt, lang, subTypeExt, site, false)
|
|
|
- }
|
|
|
- return false, "", ""
|
|
|
-}
|
|
|
-
|
|
|
-// GenerateMixSubName 这里会生成类似的文件名 xxxx.chinese(中英,shooter)
|
|
|
-func GenerateMixSubName(videoFileName, subExt string, subLang types.Language, extraSubPreName string) (string, string, string) {
|
|
|
-
|
|
|
- videoFileNameWithOutExt := strings.ReplaceAll(filepath.Base(videoFileName),
|
|
|
- filepath.Ext(videoFileName), "")
|
|
|
- note := ""
|
|
|
- // extraSubPreName 那个字幕网站下载的
|
|
|
- if extraSubPreName != "" {
|
|
|
- note = "," + extraSubPreName
|
|
|
- }
|
|
|
- defaultString := ".default"
|
|
|
- forcedString := ".forced"
|
|
|
-
|
|
|
- subNewName := videoFileNameWithOutExt + ".chinese" + "(" + language.Lang2ChineseString(subLang) + note + ")" + subExt
|
|
|
- subNewNameWithDefault := videoFileNameWithOutExt + ".chinese" + "(" + language.Lang2ChineseString(subLang) + note + ")" + defaultString + subExt
|
|
|
- subNewNameWithForced := videoFileNameWithOutExt + ".chinese" + "(" + language.Lang2ChineseString(subLang) + note + ")" + forcedString + subExt
|
|
|
-
|
|
|
- return subNewName, subNewNameWithDefault, subNewNameWithForced
|
|
|
-}
|
|
|
-
|
|
|
-func makeMixSubExtString(orgFileNameWithOutExt, lang string, ext, site string, beDefault bool) string {
|
|
|
-
|
|
|
- tmpDefault := ""
|
|
|
- if beDefault == true {
|
|
|
- tmpDefault = types.Emby_default
|
|
|
- }
|
|
|
-
|
|
|
- if site == "" {
|
|
|
- return orgFileNameWithOutExt + types.Emby_chinese + "(" + lang + ")" + tmpDefault + ext
|
|
|
- }
|
|
|
- return orgFileNameWithOutExt + types.Emby_chinese + "(" + lang + "," + site + ")" + tmpDefault + ext
|
|
|
-}
|
|
|
-
|
|
|
// DeleteOneSeasonSubCacheFolder 删除一个连续剧中的所有一季字幕的缓存文件夹
|
|
|
func DeleteOneSeasonSubCacheFolder(seriesDir string) error {
|
|
|
|