hot_fix_001.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package hot_fix
  2. import (
  3. "errors"
  4. movieHelper "github.com/allanpk716/ChineseSubFinder/internal/logic/movie_helper"
  5. seriesHelper "github.com/allanpk716/ChineseSubFinder/internal/logic/series_helper"
  6. "github.com/allanpk716/ChineseSubFinder/internal/pkg"
  7. "github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_formatter/old"
  8. "github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_helper"
  9. "os"
  10. )
  11. /*
  12. 本模块的目标是解决开发过程中遗留的功能缺陷需要升级的问题
  13. 之前字幕的命名不规范,现在需要进行一次批量的替换
  14. chs_en[shooter] -> Chinese(中英,shooter)
  15. */
  16. type HotFix001 struct {
  17. movieRootDir string
  18. seriesRootDir string
  19. }
  20. func NewHotFix001(movieRootDir string, seriesRootDir string) *HotFix001 {
  21. return &HotFix001{movieRootDir: movieRootDir, seriesRootDir: seriesRootDir}
  22. }
  23. func (h HotFix001) GetKey() string {
  24. return "001"
  25. }
  26. func (h HotFix001) Process() (interface{}, error) {
  27. var err error
  28. outStruct := OutStruct001{}
  29. outStruct.RenamedFiles = make([]string, 0)
  30. outStruct.ErrFiles = make([]string, 0)
  31. if pkg.IsDir(h.movieRootDir) == false {
  32. return outStruct, errors.New("movieRootDir path not exist: " + h.movieRootDir)
  33. }
  34. if pkg.IsDir(h.seriesRootDir) == false {
  35. return outStruct, errors.New("seriesRootDir path not exist: " + h.seriesRootDir)
  36. }
  37. // 先找出有那些电影文件夹和连续剧文件夹
  38. var movieFullPathList = make([]string, 0)
  39. movieFullPathList, err = pkg.SearchMatchedVideoFile(h.movieRootDir)
  40. if err != nil {
  41. return outStruct, err
  42. }
  43. seriesDirList, err := seriesHelper.GetSeriesList(h.seriesRootDir)
  44. if err != nil {
  45. return outStruct, err
  46. }
  47. // 搜索所有的字幕,找到相关的字幕进行修改
  48. for _, one := range movieFullPathList {
  49. found := false
  50. var fitMovieNameSubList = make([]string, 0)
  51. found, _, fitMovieNameSubList, err = movieHelper.MovieHasChineseSub(one)
  52. if err != nil || found == false {
  53. continue
  54. }
  55. // 判断是否是符合要求
  56. for _, fitSubName := range fitMovieNameSubList {
  57. bFix, _, newSubFileName := old.IsOldVersionSubPrefixName(fitSubName)
  58. if bFix == false {
  59. continue
  60. }
  61. err = os.Rename(fitSubName, newSubFileName)
  62. if err != nil {
  63. outStruct.ErrFiles = append(outStruct.ErrFiles, fitSubName)
  64. continue
  65. }
  66. outStruct.RenamedFiles = append(outStruct.RenamedFiles, newSubFileName)
  67. }
  68. }
  69. // 连续剧
  70. var seriesSubFiles = make([]string, 0)
  71. for _, oneSeriesDir := range seriesDirList {
  72. seriesSubFiles, err = sub_helper.SearchMatchedSubFileByDir(oneSeriesDir)
  73. if err != nil {
  74. return outStruct, err
  75. }
  76. // 判断是否是符合要求
  77. for _, fitSubName := range seriesSubFiles {
  78. bFix, _, newSubFileName := old.IsOldVersionSubPrefixName(fitSubName)
  79. if bFix == false {
  80. continue
  81. }
  82. err = os.Rename(fitSubName, newSubFileName)
  83. if err != nil {
  84. outStruct.ErrFiles = append(outStruct.ErrFiles, fitSubName)
  85. continue
  86. }
  87. outStruct.RenamedFiles = append(outStruct.RenamedFiles, newSubFileName)
  88. }
  89. }
  90. return outStruct, nil
  91. }
  92. type OutStruct001 struct {
  93. RenamedFiles []string
  94. ErrFiles []string
  95. }