old.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package old
  2. import (
  3. "github.com/allanpk716/ChineseSubFinder/internal/common"
  4. "github.com/allanpk716/ChineseSubFinder/internal/types"
  5. "path/filepath"
  6. "strings"
  7. )
  8. /*
  9. 整个是早期版本使用的字幕命名格式,现在已经弃用,通过 HotFix01 进行调整过。
  10. 后续是无需关心的
  11. */
  12. // IsOldVersionSubPrefixName 是否是老版本的字幕命名 .chs_en[shooter] ,符合也返回这个部分+字幕格式后缀名 .chs_en[shooter].ass, 修改后的名称
  13. func IsOldVersionSubPrefixName(subFileName string) (bool, string, string) {
  14. /*
  15. {
  16. name: "chs_en[shooter]", args: args{
  17. subFileName: "Loki - S01E01 - Glorious Purpose WEBDL-1080p Proper.chs_en[shooter].ass"},
  18. want: true,
  19. want1: ".chs_en[shooter].ass",
  20. want2: "Loki - S01E01 - Glorious Purpose WEBDL-1080p Proper.chinese(简英,shooter).ass"
  21. },
  22. 传入的必须是字幕格式的文件,这个就再之前判断,不要在这里再判断
  23. 传入的文件名可能有一下几种情况
  24. 无罪之最 - S01E01 - 重建生活.chs[shooter].ass
  25. 无罪之最 - S01E03 - 初见端倪.zh.srt
  26. Loki - S01E01 - Glorious Purpose WEBDL-1080p Proper.chs_en.ass
  27. 那么就需要先剔除,字幕的格式后缀名,然后再向后取后缀名就是 .chs[shooter] or .zh
  28. 再判断即可
  29. */
  30. // 无罪之最 - S01E01 - 重建生活.chs[shooter].ass -> 无罪之最 - S01E01 - 重建生活.chs[shooter]
  31. subTypeExt := filepath.Ext(subFileName)
  32. subFileNameWithOutExt := strings.ReplaceAll(subFileName, subTypeExt, "")
  33. // .chs[shooter]
  34. nowExt := filepath.Ext(subFileNameWithOutExt)
  35. // .chs_en[shooter].ass
  36. orgMixExt := nowExt + subTypeExt
  37. orgFileNameWithOutOrgMixExt := strings.ReplaceAll(subFileName, orgMixExt, "")
  38. // 这里也有两种情况,一种是单字幕 SaveMultiSub: false
  39. // 一种的保存了多字幕 SaveMultiSub: true
  40. // 先判断 单字幕
  41. switch nowExt {
  42. case types.Emby_chs:
  43. return true, orgMixExt, makeMixSubExtString(orgFileNameWithOutOrgMixExt, types.MatchLangChs, subTypeExt, "", true)
  44. case types.Emby_cht:
  45. return true, orgMixExt, makeMixSubExtString(orgFileNameWithOutOrgMixExt, types.MatchLangCht, subTypeExt, "", false)
  46. case types.Emby_chs_en:
  47. return true, orgMixExt, makeMixSubExtString(orgFileNameWithOutOrgMixExt, types.MatchLangChsEn, subTypeExt, "", true)
  48. case types.Emby_cht_en:
  49. return true, orgMixExt, makeMixSubExtString(orgFileNameWithOutOrgMixExt, types.MatchLangChtEn, subTypeExt, "", false)
  50. case types.Emby_chs_jp:
  51. return true, orgMixExt, makeMixSubExtString(orgFileNameWithOutOrgMixExt, types.MatchLangChsJp, subTypeExt, "", true)
  52. case types.Emby_cht_jp:
  53. return true, orgMixExt, makeMixSubExtString(orgFileNameWithOutOrgMixExt, types.MatchLangChtJp, subTypeExt, "", false)
  54. case types.Emby_chs_kr:
  55. return true, orgMixExt, makeMixSubExtString(orgFileNameWithOutOrgMixExt, types.MatchLangChsKr, subTypeExt, "", true)
  56. case types.Emby_cht_kr:
  57. return true, orgMixExt, makeMixSubExtString(orgFileNameWithOutOrgMixExt, types.MatchLangChtKr, subTypeExt, "", false)
  58. }
  59. // 再判断 多字幕情况
  60. spStrings := strings.Split(nowExt, "[")
  61. if len(spStrings) != 2 {
  62. return false, "", ""
  63. }
  64. // 分两段来判断是否符合标准
  65. // 第一段
  66. firstOk := true
  67. lang := types.MatchLangChs
  68. site := ""
  69. switch spStrings[0] {
  70. case types.Emby_chs:
  71. lang = types.MatchLangChs
  72. case types.Emby_cht:
  73. lang = types.MatchLangCht
  74. case types.Emby_chs_en:
  75. lang = types.MatchLangChsEn
  76. case types.Emby_cht_en:
  77. lang = types.MatchLangChtEn
  78. case types.Emby_chs_jp:
  79. lang = types.MatchLangChsJp
  80. case types.Emby_cht_jp:
  81. lang = types.MatchLangChtJp
  82. case types.Emby_chs_kr:
  83. lang = types.MatchLangChsKr
  84. case types.Emby_cht_kr:
  85. lang = types.MatchLangChtKr
  86. default:
  87. firstOk = false
  88. }
  89. // 第二段
  90. secondOk := true
  91. tmpSecond := strings.ReplaceAll(spStrings[1], "]", "")
  92. switch tmpSecond {
  93. case common.SubSiteZiMuKu:
  94. site = common.SubSiteZiMuKu
  95. case common.SubSiteSubHd:
  96. site = common.SubSiteSubHd
  97. case common.SubSiteShooter:
  98. site = common.SubSiteShooter
  99. case common.SubSiteXunLei:
  100. site = common.SubSiteXunLei
  101. default:
  102. secondOk = false
  103. }
  104. // 都要符合条件
  105. if firstOk == true && secondOk == true {
  106. return true, orgMixExt, makeMixSubExtString(orgFileNameWithOutOrgMixExt, lang, subTypeExt, site, false)
  107. }
  108. return false, "", ""
  109. }
  110. func makeMixSubExtString(orgFileNameWithOutExt, lang string, ext, site string, beDefault bool) string {
  111. tmpDefault := ""
  112. if beDefault == true {
  113. tmpDefault = types.Emby_default
  114. }
  115. if site == "" {
  116. return orgFileNameWithOutExt + types.Emby_chinese + "(" + lang + ")" + tmpDefault + ext
  117. }
  118. return orgFileNameWithOutExt + types.Emby_chinese + "(" + lang + "," + site + ")" + tmpDefault + ext
  119. }