Pārlūkot izejas kodu

修复,某些情况下, global_value.go 执行顺序导致变量没有赋值的问题(Log_helper 类似的全局用法导致,后续再找时间慢慢重构)

Signed-off-by: allan716 <[email protected]>
allan716 3 gadi atpakaļ
vecāks
revīzija
77c75489a3
31 mainītis faili ar 260 papildinājumiem un 158 dzēšanām
  1. 2 2
      cmd/chinesesubfinder/main.go
  2. 1 1
      internal/backend/controllers/base/system_status.go
  3. 2 1
      internal/dao/init.go
  4. 3 2
      internal/logic/downloader_helper/downloader_helper.go
  5. 2 1
      internal/logic/forced_scan_and_down_sub/forced_scan_and_down_sub.go
  6. 3 6
      internal/logic/pre_download_process/pre_download_proces.go
  7. 2 1
      internal/logic/restore_fix_timeline_bk/restore_fix_timeline_bk.go
  8. 3 2
      internal/logic/scan_played_video_subinfo/scan_played_video_subinfo.go
  9. 2 2
      internal/logic/series_helper/seriesHelper.go
  10. 1 1
      internal/logic/sub_supplier/shooter/shooter.go
  11. 4 4
      internal/logic/sub_supplier/subhd/subhd.go
  12. 1 1
      internal/logic/sub_supplier/xunlei/xunlei.go
  13. 2 2
      internal/logic/sub_supplier/zimuku/zimuku.go
  14. 6 5
      internal/pkg/downloader/downloader.go
  15. 3 3
      internal/pkg/downloader/downloader_things.go
  16. 2 1
      internal/pkg/ffmpeg_helper/ffmpeg_helper.go
  17. 2 1
      internal/pkg/ffmpeg_helper/ffmpeg_info.go
  18. 97 15
      internal/pkg/global_value/global_value.go
  19. 1 1
      internal/pkg/hot_fix/hot_fix_001.go
  20. 8 2
      internal/pkg/log_helper/log_hub.go
  21. 6 6
      internal/pkg/log_helper/loghelper.go
  22. 45 46
      internal/pkg/my_folder/folder.go
  23. 1 1
      internal/pkg/my_folder/folder_test.go
  24. 43 38
      internal/pkg/my_util/util.go
  25. 5 4
      internal/pkg/rod_helper/rodHelper.go
  26. 1 1
      internal/pkg/settings/settings.go
  27. 3 2
      internal/pkg/something_static/something_static.go
  28. 1 1
      internal/pkg/sub_formatter/sub_format_changer.go
  29. 3 2
      internal/pkg/sub_helper/sub_helper.go
  30. 3 2
      internal/pkg/sub_helper/sub_helper_test.go
  31. 2 1
      internal/pkg/sub_share_center/share_sub_cache_helper.go

+ 2 - 2
cmd/chinesesubfinder/main.go

@@ -16,9 +16,9 @@ func init() {
 
 	log_helper.GetLogger().Infoln("ChineseSubFinder Version:", AppVersion)
 
-	global_value.AppVersion = AppVersion
+	global_value.SetAppVersion(AppVersion)
 
-	global_value.ExtEnCode = ExtEnCode
+	global_value.SetExtEnCode(ExtEnCode)
 
 	if my_util.OSCheck() == false {
 		log_helper.GetLogger().Panicln(`You should search runtime.GOOS in the project, Implement unimplemented function`)

+ 1 - 1
internal/backend/controllers/base/system_status.go

@@ -25,6 +25,6 @@ func (cb ControllerBase) SystemStatusHandler(c *gin.Context) {
 
 	c.JSON(http.StatusOK, backend.ReplySystemStatus{
 		IsSetup: isSetup,
-		Version: global_value.AppVersion,
+		Version: global_value.AppVersion(),
 	})
 }

+ 2 - 1
internal/dao/init.go

@@ -5,6 +5,7 @@ import (
 	"fmt"
 	"github.com/allanpk716/ChineseSubFinder/internal/models"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_folder"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"gorm.io/driver/sqlite"
 	"gorm.io/gorm"
@@ -76,7 +77,7 @@ func InitDb() error {
 }
 
 func getDbName() string {
-	return filepath.Join(my_util.GetConfigRootDirFPath(), dbFileName)
+	return filepath.Join(my_folder.GetConfigRootDirFPath(), dbFileName)
 }
 
 var (

+ 3 - 2
internal/logic/downloader_helper/downloader_helper.go

@@ -5,6 +5,7 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/downloader"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/global_value"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_folder"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/notify_center"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/rod_helper"
@@ -41,7 +42,7 @@ func (d *DownloaderHelper) Start() error {
 	defer func() {
 		d.logger.Infoln("Download One End...")
 		notify_center.Notify.Send()
-		my_util.CloseChrome()
+		my_util.CloseChrome(d.logger)
 		rod_helper.Clear()
 	}()
 
@@ -90,7 +91,7 @@ func (d *DownloaderHelper) Start() error {
 	}
 	d.logger.Infoln("Will Scan SubFixCache Folder, Clear files that are more than 7 * 24 hours old")
 	// 清理多天没有使用的时间轴字幕校正缓存文件
-	err = my_util.ClearIdleSubFixCacheFolder(global_value.DefSubFixCacheFolder, 7*24*time.Hour)
+	err = my_folder.ClearIdleSubFixCacheFolder(d.logger, global_value.DefSubFixCacheFolder(), 7*24*time.Hour)
 	if err != nil {
 		d.logger.Errorln("ClearIdleSubFixCacheFolder", err)
 		return err

+ 2 - 1
internal/logic/forced_scan_and_down_sub/forced_scan_and_down_sub.go

@@ -3,6 +3,7 @@ package forced_scan_and_down_sub
 import (
 	"errors"
 	"fmt"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_folder"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"os"
 	"path/filepath"
@@ -30,7 +31,7 @@ you needd implement getSpeFileName() in internal/logic/forced_scan_and_down_sub/
 
 func getSpeFileName() string {
 
-	return filepath.Join(my_util.GetConfigRootDirFPath(), specialFileNameWindows)
+	return filepath.Join(my_folder.GetConfigRootDirFPath(), specialFileNameWindows)
 }
 
 /*

+ 3 - 6
internal/logic/pre_download_process/pre_download_proces.go

@@ -9,9 +9,9 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/subhd"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/xunlei"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/zimuku"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/global_value"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/hot_fix"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_folder"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/notify_center"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/rod_helper"
@@ -47,9 +47,6 @@ func (p *PreDownloadProcess) Init() *PreDownloadProcess {
 	}()
 	log_helper.GetLogger().Infoln("PreDownloadProcess.Init() Start...")
 
-	// ------------------------------------------------------------------------
-	// 初始化全局变量
-	global_value.Init(settings.GetSettings().AdvancedSettings.CustomVideoExts)
 	// ------------------------------------------------------------------------
 	// 初始化通知缓存模块
 	notify_center.Notify = notify_center.NewNotifyCenter(settings.GetSettings().DeveloperSettings.BarkServerAddress)
@@ -59,7 +56,7 @@ func (p *PreDownloadProcess) Init() *PreDownloadProcess {
 	// 获取验证码
 	nowTT := time.Now()
 	nowTimeFileNamePrix := fmt.Sprintf("%d%d%d", nowTT.Year(), nowTT.Month(), nowTT.Day())
-	updateTimeString, code, err := something_static.GetCodeFromWeb(nowTimeFileNamePrix)
+	updateTimeString, code, err := something_static.GetCodeFromWeb(log_helper.GetLogger(), nowTimeFileNamePrix)
 	if err != nil {
 		notify_center.Notify.Add("GetSubhdCode", "GetCodeFromWeb,"+err.Error())
 		log_helper.GetLogger().Errorln("something_static.GetCodeFromWeb", err)
@@ -101,7 +98,7 @@ func (p *PreDownloadProcess) Init() *PreDownloadProcess {
 	}
 	// ------------------------------------------------------------------------
 	// 清理自定义的 rod 缓存目录
-	err = my_util.ClearRodTmpRootFolder()
+	err = my_folder.ClearRodTmpRootFolder()
 	if err != nil {
 		p.gError = errors.New("ClearRodTmpRootFolder " + err.Error())
 		return p

+ 2 - 1
internal/logic/restore_fix_timeline_bk/restore_fix_timeline_bk.go

@@ -1,6 +1,7 @@
 package restore_fix_timeline_bk
 
 import (
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_folder"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"os"
 	"path/filepath"
@@ -24,7 +25,7 @@ func CheckSpeFile() (bool, error) {
 }
 
 func getSpeFileName() string {
-	return filepath.Join(my_util.GetConfigRootDirFPath(), specialFileName)
+	return filepath.Join(my_folder.GetConfigRootDirFPath(), specialFileName)
 }
 
 /*

+ 3 - 2
internal/logic/scan_played_video_subinfo/scan_played_video_subinfo.go

@@ -14,6 +14,7 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/imdb_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/language"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_folder"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/settings"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_file_hash"
@@ -74,7 +75,7 @@ func NewScanPlayedVideoSubInfo(_settings settings.Settings) (*ScanPlayedVideoSub
 	// 字幕命名格式解析器
 	scanPlayedVideoSubInfo.subFormatter = emby.NewFormatter()
 	// 缓存目录的根目录
-	shareRootDir, err := my_util.GetShareSubRootFolder()
+	shareRootDir, err := my_folder.GetShareSubRootFolder()
 	if err != nil {
 		return nil, err
 	}
@@ -230,7 +231,7 @@ func (s *ScanPlayedVideoSubInfo) scan(ctx context.Context, inData interface{}) e
 	s.log.Infoln("-----------------------------------------------")
 	s.log.Infoln("ScanPlayedVideoSubInfo", videoTypes, "Sub Start...")
 
-	shareRootDir, err := my_util.GetShareSubRootFolder()
+	shareRootDir, err := my_folder.GetShareSubRootFolder()
 	if err != nil {
 		return err
 	}

+ 2 - 2
internal/logic/series_helper/seriesHelper.go

@@ -34,7 +34,7 @@ func ReadSeriesInfoFromDir(seriesDir string, imdbInfo *models.IMDBInfo, forcedSc
 		return nil, err
 	}
 	// 搜索所有的视频
-	videoFiles, err := my_util.SearchMatchedVideoFile(seriesDir)
+	videoFiles, err := my_util.SearchMatchedVideoFile(log_helper.GetLogger(), seriesDir)
 	if err != nil {
 		return nil, err
 	}
@@ -266,7 +266,7 @@ func GetSeriesListFromDirs(dirs []string) (*treemap.Map, error) {
 func GetSeriesList(dir string) ([]string, error) {
 
 	// 需要把所有 tvshow.nfo 搜索出来,那么这些文件对应的目录就是目标连续剧的目录
-	tvNFOs, err := my_util.SearchTVNfo(dir)
+	tvNFOs, err := my_util.SearchTVNfo(log_helper.GetLogger(), dir)
 	if err != nil {
 		return nil, err
 	}

+ 1 - 1
internal/logic/sub_supplier/shooter/shooter.go

@@ -128,7 +128,7 @@ func (s Supplier) getSubListFromFile(filePath string) ([]supplier.SubInfo, error
 				subExt = "." + subExt
 			}
 
-			data, _, err := my_util.DownFile(file.Link)
+			data, _, err := my_util.DownFile(s.log, file.Link)
 			if err != nil {
 				s.log.Error(err)
 				continue

+ 4 - 4
internal/logic/sub_supplier/subhd/subhd.go

@@ -207,7 +207,7 @@ func (s Supplier) getSubListFromFile4Movie(filePath string) ([]supplier.SubInfo,
 		}
 	}
 	// 如果没有,那么就用文件名查找
-	searchKeyword := my_util.VideoNameSearchKeywordMaker(info.Title, imdbInfo.Year)
+	searchKeyword := my_util.VideoNameSearchKeywordMaker(s.log, info.Title, imdbInfo.Year)
 	subInfoList, err = s.getSubListFromKeyword4Movie(searchKeyword)
 	if err != nil {
 		s.log.Errorln(s.GetSupplierName(), "keyword:", searchKeyword)
@@ -491,7 +491,7 @@ func (s Supplier) downloadSubFile(browser *rod.Browser, page *rod.Page) (bool, *
 	fileName := ""
 	fileByte := []byte{0}
 	err = rod.Try(func() {
-		tmpDir := filepath.Join(global_value.DefTmpFolder, "downloads")
+		tmpDir := filepath.Join(global_value.DefTmpFolder(), "downloads")
 		wait := browser.WaitDownload(tmpDir)
 		getDownloadFile := func() ([]byte, string, error) {
 			info := wait()
@@ -604,7 +604,7 @@ func (s Supplier) passWaterWall(page *rod.Page) {
 	shadowbg := slideBgEl.MustResource()
 	// 取得原始圖像
 	src := slideBgEl.MustProperty("src")
-	fullbg, _, err := my_util.DownFile(strings.Replace(src.String(), "img_index=1", "img_index=0", 1))
+	fullbg, _, err := my_util.DownFile(s.log, strings.Replace(src.String(), "img_index=1", "img_index=0", 1))
 	if err != nil {
 		panic(err)
 	}
@@ -674,7 +674,7 @@ search:
 
 	if s.debugMode == true {
 		//截圖保存
-		page.MustScreenshot(global_value.DefDebugFolder, "result.png")
+		page.MustScreenshot(global_value.DefDebugFolder(), "result.png")
 	}
 }
 

+ 1 - 1
internal/logic/sub_supplier/xunlei/xunlei.go

@@ -151,7 +151,7 @@ func (s Supplier) getSubListFromFile(filePath string) ([]supplier.SubInfo, error
 	// 再开始下载字幕
 	for i, v := range tmpXunLeiSubListChinese {
 		tmpLang := language.LangConverter4Sub_Supplier(v.Language)
-		data, filename, err := my_util.DownFile(v.Surl)
+		data, filename, err := my_util.DownFile(s.log, v.Surl)
 		if err != nil {
 			s.log.Errorln("xunlei pkg.DownFile:", err)
 			continue

+ 2 - 2
internal/logic/sub_supplier/zimuku/zimuku.go

@@ -239,7 +239,7 @@ func (s Supplier) getSubListFromMovie(browser *rod.Browser, fileFPath string) ([
 		}
 	}
 	// 如果没有,那么就用文件名查找
-	searchKeyword := my_util.VideoNameSearchKeywordMaker(info.Title, imdbInfo.Year)
+	searchKeyword := my_util.VideoNameSearchKeywordMaker(s.log, info.Title, imdbInfo.Year)
 
 	s.log.Debugln(s.GetSupplierName(), fileFPath, "VideoNameSearchKeywordMaker Keyword:", searchKeyword)
 
@@ -605,7 +605,7 @@ func (s Supplier) step3(browser *rod.Browser, subDownloadPageUrl string) (string
 	fileByte := []byte{0}
 	downloadSuccess := false
 	err = rod.Try(func() {
-		tmpDir := filepath.Join(global_value.DefTmpFolder, "downloads")
+		tmpDir := filepath.Join(global_value.DefTmpFolder(), "downloads")
 		wait := browser.WaitDownload(tmpDir)
 		getDownloadFile := func() ([]byte, string, error) {
 			info := wait()

+ 6 - 5
internal/pkg/downloader/downloader.go

@@ -14,6 +14,7 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_timeline_fixer"
 	pkgcommon "github.com/allanpk716/ChineseSubFinder/internal/pkg/common"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_folder"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/settings"
 	subCommon "github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_formatter/common"
@@ -201,7 +202,7 @@ func (d *Downloader) RefreshEmbySubList() error {
 func (d *Downloader) DownloadSub4Movie() error {
 	defer func() {
 		// 所有的电影字幕下载完成,抉择完成,需要清理缓存目录
-		err := my_util.ClearRootTmpFolder()
+		err := my_folder.ClearRootTmpFolder()
 		if err != nil {
 			d.log.Error("ClearRootTmpFolder", err)
 		}
@@ -223,7 +224,7 @@ func (d *Downloader) DownloadSub4Movie() error {
 	// 优先判断特殊的操作
 	if d.needForcedScanAndDownSub == true {
 		// 全扫描
-		d.movieFileFullPathList, err = my_util.SearchMatchedVideoFileFromDirs(d.settings.CommonSettings.MoviePaths)
+		d.movieFileFullPathList, err = my_util.SearchMatchedVideoFileFromDirs(d.log, d.settings.CommonSettings.MoviePaths)
 		if err != nil {
 			return err
 		}
@@ -231,7 +232,7 @@ func (d *Downloader) DownloadSub4Movie() error {
 		// 是否是通过 emby_helper api 获取的列表
 		if d.embyHelper == nil {
 			// 没有填写 emby_helper api 的信息,那么就走常规的全文件扫描流程
-			d.movieFileFullPathList, err = my_util.SearchMatchedVideoFileFromDirs(d.settings.CommonSettings.MoviePaths)
+			d.movieFileFullPathList, err = my_util.SearchMatchedVideoFileFromDirs(d.log, d.settings.CommonSettings.MoviePaths)
 			if err != nil {
 				return err
 			}
@@ -291,13 +292,13 @@ func (d *Downloader) DownloadSub4Series() error {
 	var err error
 	defer func() {
 		// 所有的连续剧字幕下载完成,抉择完成,需要清理缓存目录
-		err := my_util.ClearRootTmpFolder()
+		err := my_folder.ClearRootTmpFolder()
 		if err != nil {
 			d.log.Error("ClearRootTmpFolder", err)
 		}
 		d.log.Infoln("Download Series Sub End...")
 
-		my_util.CloseChrome()
+		my_util.CloseChrome(d.log)
 		d.log.Infoln("CloseChrome")
 	}()
 	d.log.Infoln("Download Series Sub Started...")

+ 3 - 3
internal/pkg/downloader/downloader_things.go

@@ -4,6 +4,7 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/change_file_encode"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/chs_cht_changer"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/decode"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_folder"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	subcommon "github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_formatter/common"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_helper"
@@ -28,7 +29,7 @@ func (d *Downloader) oneVideoSelectBestSub(oneVideoFullPath string, organizeSubF
 	// 调试缓存,把下载好的字幕写到对应的视频目录下,方便调试
 	if d.settings.AdvancedSettings.DebugMode == true {
 
-		err = my_util.CopyFiles2DebugFolder([]string{videoFileName}, organizeSubFiles)
+		err = my_folder.CopyFiles2DebugFolder([]string{videoFileName}, organizeSubFiles)
 		if err != nil {
 			d.log.Errorln("copySubFile2DesFolder", err)
 		}
@@ -130,7 +131,7 @@ func (d *Downloader) saveFullSeasonSub(seriesInfo *series.SeriesInfo, organizeSu
 		for _, sub := range subs {
 			subFileName := filepath.Base(sub)
 
-			newSeasonSubRootPath, err := my_util.GetDebugFolderByName([]string{
+			newSeasonSubRootPath, err := my_folder.GetDebugFolderByName([]string{
 				filepath.Base(seriesInfo.DirPath),
 				"Sub_" + seasonKey})
 			if err != nil {
@@ -217,7 +218,6 @@ func (d *Downloader) writeSubFile2VideoPath(videoFileFullPath string, finalSubFi
 	// 测试了先转 UTF-8 进行简繁转换然后再转 GBK,有些时候会出错,所以还是不支持这样先
 	if d.settings.ExperimentalFunction.AutoChangeSubEncode.Enable == true &&
 		d.settings.ExperimentalFunction.AutoChangeSubEncode.DesEncodeType == 0 &&
-
 		d.settings.ExperimentalFunction.ChsChtChanger.Enable == true {
 		d.log.Infoln("----------------------------------")
 		d.log.Infoln("chs_cht_changer to", d.settings.ExperimentalFunction.ChsChtChanger.GetDesChineseLanguageTypeString())

+ 2 - 1
internal/pkg/ffmpeg_helper/ffmpeg_helper.go

@@ -9,6 +9,7 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/srt"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/language"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_folder"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_parser_hub"
 	"github.com/tidwall/gjson"
@@ -96,7 +97,7 @@ func (f *FFMPEGHelper) GetFFMPEGInfo(videoFileFullPath string, exportType Export
 		// 说明缓存不存在,需要导出,这里需要注意,如果导出失败了,这个文件夹要清理掉
 		if my_util.IsDir(nowCacheFolderPath) == true {
 			// 如果存在则,先清空一个这个文件夹
-			err = my_util.ClearFolder(nowCacheFolderPath)
+			err = my_folder.ClearFolder(nowCacheFolderPath)
 			if err != nil {
 				bok = false
 				return bok, nil, err

+ 2 - 1
internal/pkg/ffmpeg_helper/ffmpeg_info.go

@@ -3,6 +3,7 @@ package ffmpeg_helper
 import (
 	"github.com/allanpk716/ChineseSubFinder/internal/common"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_folder"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_parser_hub"
@@ -32,7 +33,7 @@ func NewFFMPEGInfo(videoFullPath string) *FFMPEGInfo {
 // csf-cache/当前的视频文件名(不带后缀)
 func (f *FFMPEGInfo) GetCacheFolderFPath() (string, error) {
 	noExtVideoName := strings.ReplaceAll(filepath.Base(f.VideoFullPath), filepath.Ext(f.VideoFullPath), "")
-	return my_util.GetSubFixCacheFolderByName(noExtVideoName)
+	return my_folder.GetSubFixCacheFolderByName(noExtVideoName)
 }
 
 // IsExported 是否已经导出过,如果没有导出或者导出不完整为 false

+ 97 - 15
internal/pkg/global_value/global_value.go

@@ -1,23 +1,105 @@
 package global_value
 
-func Init(customExts []string) {
+import (
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_folder"
+)
+
+// SetAppVersion ---------------------------------------------
+func SetAppVersion(appVersion string) {
+	_appVersion = appVersion
+}
+
+func AppVersion() string {
+	return _appVersion
+}
+
+// SetExtEnCode ---------------------------------------------
+func SetExtEnCode(extEnCode string) {
+	_extEnCode = extEnCode
+}
+
+func ExtEnCode() string {
+	return _extEnCode
+}
+
+// ConfigRootDirFPath ---------------------------------------------
+func ConfigRootDirFPath() string {
+
+	if _configRootDirFPath == "" {
+		_configRootDirFPath = my_folder.GetConfigRootDirFPath()
+	}
+	return _configRootDirFPath
+}
+
+func DefDebugFolder() string {
+	var err error
+	if _defDebugFolder == "" {
+		_defDebugFolder, err = my_folder.GetRootDebugFolder()
+		if err != nil {
+			panic(err)
+		}
+	}
+
+	return _defDebugFolder
+}
+
+func DefTmpFolder() string {
+	var err error
+	if _defTmpFolder == "" {
+		_defTmpFolder, err = my_folder.GetRootTmpFolder()
+		if err != nil {
+			panic(err)
+		}
+	}
+
+	return _defTmpFolder
+}
+
+func DefRodTmpRootFolder() string {
+	var err error
+	if _defRodTmpRootFolder == "" {
+		_defRodTmpRootFolder, err = my_folder.GetRodTmpRootFolder()
+		if err != nil {
+			panic(err)
+		}
+	}
+
+	return _defRodTmpRootFolder
+}
+
+func DefSubFixCacheFolder() string {
+	var err error
+	if _defSubFixCacheFolder == "" {
+		_defSubFixCacheFolder, err = my_folder.GetRootSubFixCacheFolder()
+		if err != nil {
+			panic(err)
+		}
+	}
+
+	return _defSubFixCacheFolder
+}
+
+func AdblockTmpFolder() string {
+	var err error
+	if _adblockTmpFolder == "" {
+		_adblockTmpFolder, err = my_folder.GetPluginFolderByName(my_folder.Plugin_Adblock)
+		if err != nil {
+			panic(err)
+		}
+	}
 
-	WantedExtMap = make(map[string]string) // 人工确认的需要监控的视频后缀名
-	DefExtMap = make(map[string]string)    // 内置支持的视频后缀名列表
-	CustomVideoExts = customExts           // 用户额外自定义的视频后缀名列表
+	return _adblockTmpFolder
 }
 
+// ---------------------------------------------
 // util.go
 var (
-	AppVersion           = "" // 程序的版本号
-	ExtEnCode            = "" // 扩展加密部分
-	ConfigRootDirFPath   = ""
-	DefDebugFolder       = ""
-	DefTmpFolder         = ""
-	DefRodTmpRootFolder  = ""
-	DefSubFixCacheFolder = ""
-	AdblockTmpFolder     = ""
-	WantedExtMap         = make(map[string]string) // 人工确认的需要监控的视频后缀名
-	DefExtMap            = make(map[string]string) // 内置支持的视频后缀名列表
-	CustomVideoExts      = make([]string, 0)       // 用户额外自定义的视频后缀名列表
+	_appVersion           = "" // 程序的版本号
+	_extEnCode            = "" // 扩展加密部分
+	_configRootDirFPath   = ""
+	_defDebugFolder       = ""
+	_defTmpFolder         = ""
+	_defRodTmpRootFolder  = ""
+	_defSubFixCacheFolder = ""
+	_adblockTmpFolder     = ""
 )

+ 1 - 1
internal/pkg/hot_fix/hot_fix_001.go

@@ -88,7 +88,7 @@ func (h HotFix001) fixMovie(movieRootDir string) (OutStruct001, error) {
 	}
 	// 先找出有那些电影文件夹和连续剧文件夹
 	var movieFullPathList = make([]string, 0)
-	movieFullPathList, err = my_util.SearchMatchedVideoFile(movieRootDir)
+	movieFullPathList, err = my_util.SearchMatchedVideoFile(log_helper.GetLogger(), movieRootDir)
 	if err != nil {
 		return outStruct, err
 	}

+ 8 - 2
internal/pkg/log_helper/log_hub.go

@@ -164,7 +164,7 @@ func newOnceLogger() *logrus.Logger {
 		LogFormat:       "[%lvl%]: %time% - %msg%\n",
 	}
 	nowTime := time.Now()
-	pathRoot := filepath.Join(global_value.ConfigRootDirFPath, "Logs")
+	pathRoot := filepath.Join(global_value.ConfigRootDirFPath(), "Logs")
 	fileName := fmt.Sprintf(onceLogPrefix+"%v.log", nowTime.Unix())
 	fileAbsPath := filepath.Join(pathRoot, fileName)
 
@@ -195,13 +195,19 @@ func cleanAndLoadOnceLogs() {
 
 	onceLogs = make([]log_hub.OnceLog, 0)
 
-	pathRoot := filepath.Join(global_value.ConfigRootDirFPath, "Logs")
+	pathRoot := filepath.Join(global_value.ConfigRootDirFPath(), "Logs")
+
+	GetLogger().Infoln("ConfigRootDirFPath", pathRoot)
+
 	// 扫描当前日志存储目录下有多少个符合要求的 Once- 日志
 	// 确保有且仅有最近的 20 次扫描日志记录存在即可
 	matches, err := filepath.Glob(filepath.Join(pathRoot, onceLogPrefix+"*.log"))
 	if err != nil {
 		GetLogger().Panicln("cleanAndLoadOnceLogs.Glob", err)
 	}
+
+	GetLogger().Infoln("matches logs:", len(matches))
+
 	if len(matches) > onceLogMaxCount {
 		// 需要清理多余的
 		// 保存的文件名是 Once-unixTime.log 做为前提

+ 6 - 6
internal/pkg/log_helper/loghelper.go

@@ -19,7 +19,7 @@ func NewLogHelper(appName string, level logrus.Level, maxAge time.Duration, rota
 		TimestampFormat: "2006-01-02 15:04:05",
 		LogFormat:       "[%lvl%]: %time% - %msg%\n",
 	}
-	pathRoot := filepath.Join(global_value.ConfigRootDirFPath, "Logs")
+	pathRoot := filepath.Join(global_value.ConfigRootDirFPath(), "Logs")
 	fileAbsPath := filepath.Join(pathRoot, appName+".log")
 	// 下面配置日志每隔 X 分钟轮转一个新文件,保留最近 X 分钟的日志文件,多余的自动清理掉。
 	writer, _ := rotatelogs.New(
@@ -63,7 +63,7 @@ func logInit() {
 	var level logrus.Level
 	// 之前是读取配置文件,现在改为,读取当前目录下,是否有一个特殊的文件,有则启动 Debug 日志级别
 	// 那么怎么写入这个文件,就靠额外的逻辑控制了
-	if isFile(filepath.Join(global_value.ConfigRootDirFPath, DebugFileName)) == true {
+	if isFile(filepath.Join(global_value.ConfigRootDirFPath(), DebugFileName)) == true {
 		level = logrus.DebugLevel
 	} else {
 		level = logrus.InfoLevel
@@ -89,10 +89,10 @@ func isFile(filePath string) bool {
 
 // WriteDebugFile 写入开启 Debug 级别日志记录的特殊文件,注意这个最好是在主程序中调用,这样就跟主程序在一个目录下生成,log 去检测是否存在才有意义
 func WriteDebugFile() error {
-	if isFile(filepath.Join(global_value.ConfigRootDirFPath, DebugFileName)) == true {
+	if isFile(filepath.Join(global_value.ConfigRootDirFPath(), DebugFileName)) == true {
 		return nil
 	}
-	f, err := os.Create(filepath.Join(global_value.ConfigRootDirFPath, DebugFileName))
+	f, err := os.Create(filepath.Join(global_value.ConfigRootDirFPath(), DebugFileName))
 	defer func() {
 		_ = f.Close()
 	}()
@@ -105,10 +105,10 @@ func WriteDebugFile() error {
 // DeleteDebugFile 删除开启 Debug 级别日志记录的特殊文件
 func DeleteDebugFile() error {
 
-	if isFile(filepath.Join(global_value.ConfigRootDirFPath, DebugFileName)) == false {
+	if isFile(filepath.Join(global_value.ConfigRootDirFPath(), DebugFileName)) == false {
 		return nil
 	}
-	err := os.Remove(filepath.Join(global_value.ConfigRootDirFPath, DebugFileName))
+	err := os.Remove(filepath.Join(global_value.ConfigRootDirFPath(), DebugFileName))
 	if err != nil {
 		return err
 	}

+ 45 - 46
internal/pkg/my_util/folder.go → internal/pkg/my_folder/folder.go

@@ -1,57 +1,16 @@
-package my_util
+package my_folder
 
 import (
 	"fmt"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/get_access_time"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/global_value"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
+	"github.com/sirupsen/logrus"
+	"io"
 	"os"
 	"path/filepath"
 	"runtime"
 	"time"
 )
 
-func init() {
-	err := Init()
-	if err != nil {
-		log_helper.GetLogger().Panicln("my_util.Init", err)
-	}
-}
-
-func Init() error {
-
-	var err error
-
-	global_value.ConfigRootDirFPath = GetConfigRootDirFPath()
-
-	global_value.DefDebugFolder, err = GetRootDebugFolder()
-	if err != nil {
-		log_helper.GetLogger().Panicln("GetRootDebugFolder", err)
-	}
-
-	global_value.DefTmpFolder, err = GetRootTmpFolder()
-	if err != nil {
-		log_helper.GetLogger().Panicln("GetRootTmpFolder", err)
-	}
-
-	global_value.DefRodTmpRootFolder, err = GetRodTmpRootFolder()
-	if err != nil {
-		log_helper.GetLogger().Panicln("GetRodTmpRootFolder", err)
-	}
-
-	global_value.DefSubFixCacheFolder, err = GetRootSubFixCacheFolder()
-	if err != nil {
-		log_helper.GetLogger().Panicln("GetRootTmpFolder", err)
-	}
-
-	global_value.AdblockTmpFolder, err = GetPluginFolderByName(Plugin_Adblock)
-	if err != nil {
-		log_helper.GetLogger().Panicln("GetPluginFolderByName", Plugin_Adblock, err)
-	}
-
-	return nil
-}
-
 // --------------------------------------------------------------
 // Debug
 // --------------------------------------------------------------
@@ -411,7 +370,7 @@ func GetConfigRootDirFPath() string {
 }
 
 // ClearIdleSubFixCacheFolder 清理闲置的字幕修正缓存文件夹
-func ClearIdleSubFixCacheFolder(rootSubFixCacheFolder string, outOfDate time.Duration) error {
+func ClearIdleSubFixCacheFolder(l *logrus.Logger, rootSubFixCacheFolder string, outOfDate time.Duration) error {
 
 	/*
 		从 GetRootSubFixCacheFolder 目录下,遍历第一级目录中的文件夹
@@ -469,7 +428,7 @@ func ClearIdleSubFixCacheFolder(rootSubFixCacheFolder string, outOfDate time.Dur
 	}
 	// 统一清理过期的文件夹
 	for _, s := range wait2DeleteFolder {
-		log_helper.GetLogger().Infoln("Try 2 clear SubFixCache Folder:", s)
+		l.Infoln("Try 2 clear SubFixCache Folder:", s)
 		err := os.RemoveAll(s)
 		if err != nil {
 			return err
@@ -479,6 +438,46 @@ func ClearIdleSubFixCacheFolder(rootSubFixCacheFolder string, outOfDate time.Dur
 	return nil
 }
 
+// CopyFile copies a single file from src to dst
+func CopyFile(src, dst string) error {
+	var err error
+	var srcFd *os.File
+	var dstFd *os.File
+	var srcInfo os.FileInfo
+
+	if srcFd, err = os.Open(src); err != nil {
+		return err
+	}
+	defer func() {
+		_ = srcFd.Close()
+	}()
+
+	if dstFd, err = os.Create(dst); err != nil {
+		return err
+	}
+	defer func() {
+		_ = dstFd.Close()
+	}()
+
+	if _, err = io.Copy(dstFd, srcFd); err != nil {
+		return err
+	}
+	if srcInfo, err = os.Stat(src); err != nil {
+		return err
+	}
+	return os.Chmod(dst, srcInfo.Mode())
+}
+
+func Time2SecondNumber(inTime time.Time) float64 {
+	outSecond := 0.0
+	outSecond += float64(inTime.Hour() * 60 * 60)
+	outSecond += float64(inTime.Minute() * 60)
+	outSecond += float64(inTime.Second())
+	outSecond += float64(inTime.Nanosecond()) / 1000 / 1000 / 1000
+
+	return outSecond
+}
+
 // 缓存文件的位置信息,都是在程序的根目录下的 cache 中
 const (
 	cacheRootFolderName = "cache"             // 缓存文件夹总名称

+ 1 - 1
internal/pkg/my_util/folder_test.go → internal/pkg/my_folder/folder_test.go

@@ -1,4 +1,4 @@
-package my_util
+package my_folder
 
 import (
 	"testing"

+ 43 - 38
internal/pkg/my_util/util.go

@@ -7,13 +7,12 @@ import (
 	"fmt"
 	"github.com/allanpk716/ChineseSubFinder/internal/common"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/decode"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/global_value"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/regex_things"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/settings"
 	browser "github.com/allanpk716/fake-useragent"
 	"github.com/go-resty/resty/v2"
 	"github.com/google/uuid"
+	"github.com/sirupsen/logrus"
 	"io"
 	"math"
 	"net/http"
@@ -72,7 +71,7 @@ func NewHttpClient(_proxySettings ...settings.ProxySettings) *resty.Client {
 }
 
 // DownFile 从指定的 url 下载文件
-func DownFile(urlStr string, _proxySettings ...settings.ProxySettings) ([]byte, string, error) {
+func DownFile(l *logrus.Logger, urlStr string, _proxySettings ...settings.ProxySettings) ([]byte, string, error) {
 	var proxySettings settings.ProxySettings
 	if len(_proxySettings) > 0 {
 		proxySettings = _proxySettings[0]
@@ -82,17 +81,17 @@ func DownFile(urlStr string, _proxySettings ...settings.ProxySettings) ([]byte,
 	if err != nil {
 		return nil, "", err
 	}
-	filename := GetFileName(resp.RawResponse)
+	filename := GetFileName(l, resp.RawResponse)
 
 	if filename == "" {
-		log_helper.GetLogger().Warningln("DownFile.GetFileName is string.empty", urlStr)
+		l.Warningln("DownFile.GetFileName is string.empty", urlStr)
 	}
 
 	return resp.Body(), filename, nil
 }
 
 // GetFileName 获取下载文件的文件名
-func GetFileName(resp *http.Response) string {
+func GetFileName(l *logrus.Logger, resp *http.Response) string {
 	contentDisposition := resp.Header.Get("Content-Disposition")
 	if len(contentDisposition) == 0 {
 		return ""
@@ -100,7 +99,7 @@ func GetFileName(resp *http.Response) string {
 	re := regexp.MustCompile(`filename=["]*([^"]+)["]*`)
 	matched := re.FindStringSubmatch(contentDisposition)
 	if matched == nil || len(matched) == 0 || len(matched[0]) == 0 {
-		log_helper.GetLogger().Errorln("GetFileName.Content-Disposition", contentDisposition)
+		l.Errorln("GetFileName.Content-Disposition", contentDisposition)
 		return ""
 	}
 	return matched[1]
@@ -133,11 +132,11 @@ func IsFile(filePath string) bool {
 }
 
 // VideoNameSearchKeywordMaker 拼接视频搜索的 title 和 年份
-func VideoNameSearchKeywordMaker(title string, year string) string {
+func VideoNameSearchKeywordMaker(l *logrus.Logger, title string, year string) string {
 	iYear, err := strconv.Atoi(year)
 	if err != nil {
 		// 允许的错误
-		log_helper.GetLogger().Errorln("VideoNameSearchKeywordMaker", "year to int", err)
+		l.Errorln("VideoNameSearchKeywordMaker", "year to int", err)
 		iYear = 0
 	}
 	searchKeyword := title
@@ -149,12 +148,12 @@ func VideoNameSearchKeywordMaker(title string, year string) string {
 }
 
 // SearchMatchedVideoFileFromDirs 搜索符合后缀名的视频文件
-func SearchMatchedVideoFileFromDirs(dirs []string) ([]string, error) {
+func SearchMatchedVideoFileFromDirs(l *logrus.Logger, dirs []string) ([]string, error) {
 
 	var fileFullPathList = make([]string, 0)
 	for _, dir := range dirs {
 
-		matchedVideoFile, err := SearchMatchedVideoFile(dir)
+		matchedVideoFile, err := SearchMatchedVideoFile(l, dir)
 		if err != nil {
 			return nil, err
 		}
@@ -166,7 +165,7 @@ func SearchMatchedVideoFileFromDirs(dirs []string) ([]string, error) {
 }
 
 // SearchMatchedVideoFile 搜索符合后缀名的视频文件,现在也会把 BDMV 的文件搜索出来,但是这个并不是一个视频文件,需要在后续特殊处理
-func SearchMatchedVideoFile(dir string) ([]string, error) {
+func SearchMatchedVideoFile(l *logrus.Logger, dir string) ([]string, error) {
 
 	var fileFullPathList = make([]string, 0)
 	pathSep := string(os.PathSeparator)
@@ -178,7 +177,7 @@ func SearchMatchedVideoFile(dir string) ([]string, error) {
 		fullPath := dir + pathSep + curFile.Name()
 		if curFile.IsDir() {
 			// 内层的错误就无视了
-			oneList, _ := SearchMatchedVideoFile(fullPath)
+			oneList, _ := SearchMatchedVideoFile(l, fullPath)
 			if oneList != nil {
 				fileFullPathList = append(fileFullPathList, oneList...)
 			}
@@ -198,11 +197,11 @@ func SearchMatchedVideoFile(dir string) ([]string, error) {
 				// 跳过不符合的文件,比如 MAC OS 下可能有缓存文件,见 #138
 				fi, err := curFile.Info()
 				if err != nil {
-					log_helper.GetLogger().Debugln("SearchMatchedVideoFile, file.Info:", fullPath, err)
+					l.Debugln("SearchMatchedVideoFile, file.Info:", fullPath, err)
 					continue
 				}
 				if fi.Size() == 4096 && strings.HasPrefix(curFile.Name(), "._") == true {
-					log_helper.GetLogger().Debugln("SearchMatchedVideoFile file.Size() == 4096 && Prefix Name == ._*", fullPath)
+					l.Debugln("SearchMatchedVideoFile file.Size() == 4096 && Prefix Name == ._*", fullPath)
 					continue
 				}
 				fileFullPathList = append(fileFullPathList, fullPath)
@@ -237,7 +236,7 @@ func FileNameIsBDMV(id_bdmv_fileFPath string) (bool, string) {
 	return false, ""
 }
 
-func SearchTVNfo(dir string) ([]string, error) {
+func SearchTVNfo(l *logrus.Logger, dir string) ([]string, error) {
 
 	var fileFullPathList = make([]string, 0)
 	pathSep := string(os.PathSeparator)
@@ -249,7 +248,7 @@ func SearchTVNfo(dir string) ([]string, error) {
 		fullPath := dir + pathSep + curFile.Name()
 		if curFile.IsDir() {
 			// 内层的错误就无视了
-			oneList, _ := SearchTVNfo(fullPath)
+			oneList, _ := SearchTVNfo(l, fullPath)
 			if oneList != nil {
 				fileFullPathList = append(fileFullPathList, oneList...)
 			}
@@ -262,11 +261,11 @@ func SearchTVNfo(dir string) ([]string, error) {
 				// 跳过不符合的文件,比如 MAC OS 下可能有缓存文件,见 #138
 				fi, err := curFile.Info()
 				if err != nil {
-					log_helper.GetLogger().Debugln("SearchTVNfo, file.Info:", fullPath, err)
+					l.Debugln("SearchTVNfo, file.Info:", fullPath, err)
 					continue
 				}
 				if fi.Size() == 4096 && strings.HasPrefix(curFile.Name(), "._") == true {
-					log_helper.GetLogger().Debugln("SearchTVNfo file.Size() == 4096 && Prefix Name == ._*", fullPath)
+					l.Debugln("SearchTVNfo file.Size() == 4096 && Prefix Name == ._*", fullPath)
 					continue
 				}
 				fileFullPathList = append(fileFullPathList, fullPath)
@@ -279,25 +278,25 @@ func SearchTVNfo(dir string) ([]string, error) {
 // IsWantedVideoExtDef 后缀名是否符合规则
 func IsWantedVideoExtDef(fileName string) bool {
 
-	if len(global_value.WantedExtMap) < 1 {
-		global_value.DefExtMap[common.VideoExtMp4] = common.VideoExtMp4
-		global_value.DefExtMap[common.VideoExtMkv] = common.VideoExtMkv
-		global_value.DefExtMap[common.VideoExtRmvb] = common.VideoExtRmvb
-		global_value.DefExtMap[common.VideoExtIso] = common.VideoExtIso
-		global_value.DefExtMap[common.VideoExtM2ts] = common.VideoExtM2ts
-
-		global_value.WantedExtMap[common.VideoExtMp4] = common.VideoExtMp4
-		global_value.WantedExtMap[common.VideoExtMkv] = common.VideoExtMkv
-		global_value.WantedExtMap[common.VideoExtRmvb] = common.VideoExtRmvb
-		global_value.WantedExtMap[common.VideoExtIso] = common.VideoExtIso
-		global_value.WantedExtMap[common.VideoExtM2ts] = common.VideoExtM2ts
-
-		for _, videoExt := range global_value.CustomVideoExts {
-			global_value.WantedExtMap[videoExt] = videoExt
+	if len(_wantedExtMap) < 1 {
+		_defExtMap[common.VideoExtMp4] = common.VideoExtMp4
+		_defExtMap[common.VideoExtMkv] = common.VideoExtMkv
+		_defExtMap[common.VideoExtRmvb] = common.VideoExtRmvb
+		_defExtMap[common.VideoExtIso] = common.VideoExtIso
+		_defExtMap[common.VideoExtM2ts] = common.VideoExtM2ts
+
+		_wantedExtMap[common.VideoExtMp4] = common.VideoExtMp4
+		_wantedExtMap[common.VideoExtMkv] = common.VideoExtMkv
+		_wantedExtMap[common.VideoExtRmvb] = common.VideoExtRmvb
+		_wantedExtMap[common.VideoExtIso] = common.VideoExtIso
+		_wantedExtMap[common.VideoExtM2ts] = common.VideoExtM2ts
+
+		for _, videoExt := range _customVideoExts {
+			_wantedExtMap[videoExt] = videoExt
 		}
 	}
 	fileExt := strings.ToLower(filepath.Ext(fileName))
-	_, bFound := global_value.WantedExtMap[fileExt]
+	_, bFound := _wantedExtMap[fileExt]
 	return bFound
 }
 
@@ -370,7 +369,7 @@ func CopyDir(src string, dst string) error {
 }
 
 // CloseChrome 强行结束没有关闭的 Chrome 进程
-func CloseChrome() {
+func CloseChrome(l *logrus.Logger) {
 
 	cmdString := ""
 	var command *exec.Cmd
@@ -392,12 +391,12 @@ func CloseChrome() {
 		command = exec.Command("osascript", "-s", "h", "-e", cmdString)
 	}
 	if cmdString == "" || command == nil {
-		log_helper.GetLogger().Errorln("CloseChrome OS:", sysType)
+		l.Errorln("CloseChrome OS:", sysType)
 		return
 	}
 	err := command.Run()
 	if err != nil {
-		log_helper.GetLogger().Warningln("CloseChrome", err)
+		l.Warningln("CloseChrome", err)
 	}
 }
 
@@ -680,3 +679,9 @@ func GetFileSHA1String(fileFPath string) (string, error) {
 
 	return fmt.Sprintf("%x", md5.Sum(hashBytes)), nil
 }
+
+var (
+	_wantedExtMap    = make(map[string]string) // 人工确认的需要监控的视频后缀名
+	_defExtMap       = make(map[string]string) // 内置支持的视频后缀名列表
+	_customVideoExts = make([]string, 0)       // 用户额外自定义的视频后缀名列表
+)

+ 5 - 4
internal/pkg/rod_helper/rodHelper.go

@@ -6,6 +6,7 @@ import (
 	"errors"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/global_value"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_folder"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/random_useragent"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/settings"
@@ -52,7 +53,7 @@ func NewBrowser(httpProxyURL string, loadAdblock bool, preLoadUrl ...string) (*r
 	})
 
 	// 随机的 rod 子文件夹名称
-	nowUserData := filepath.Join(global_value.DefRodTmpRootFolder, my_util.RandStringBytesMaskImprSrcSB(20))
+	nowUserData := filepath.Join(global_value.DefRodTmpRootFolder(), my_util.RandStringBytesMaskImprSrcSB(20))
 	var browser *rod.Browser
 	err = rod.Try(func() {
 		purl := ""
@@ -265,7 +266,7 @@ func Clear() {
 		defer browser.MustClose()
 	})
 
-	err := my_util.ClearRodTmpRootFolder()
+	err := my_folder.ClearRodTmpRootFolder()
 	if err != nil {
 		log_helper.GetLogger().Errorln("ClearRodTmpRootFolder", err)
 		return
@@ -291,14 +292,14 @@ func releaseAdblock() (string, error) {
 
 	log_helper.GetLogger().Infoln("releaseAdblock start")
 
-	adblockFolderPath := global_value.AdblockTmpFolder
+	adblockFolderPath := global_value.AdblockTmpFolder()
 	err := os.MkdirAll(filepath.Join(adblockFolderPath), os.ModePerm)
 	if err != nil {
 		return "", err
 	}
 	desPath := filepath.Join(adblockFolderPath, "RunAdblock")
 	// 清理之前缓存的信息
-	_ = my_util.ClearFolder(desPath)
+	_ = my_folder.ClearFolder(desPath)
 	// 具体把 adblock zip 解压下载到哪里
 	outZipFileFPath := filepath.Join(adblockFolderPath, "adblock.zip")
 	adblockZipFile, err := os.Create(outZipFileFPath)

+ 1 - 1
internal/pkg/settings/settings.go

@@ -68,7 +68,7 @@ func SetFullNewSettings(inSettings *Settings) error {
 
 func NewSettings() *Settings {
 
-	nowConfigFPath := filepath.Join(global_value.ConfigRootDirFPath, configName)
+	nowConfigFPath := filepath.Join(global_value.ConfigRootDirFPath(), configName)
 
 	return &Settings{
 		configFPath:           nowConfigFPath,

+ 3 - 2
internal/pkg/something_static/something_static.go

@@ -4,6 +4,7 @@ import (
 	b64 "encoding/base64"
 	"github.com/allanpk716/ChineseSubFinder/internal/common"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
+	"github.com/sirupsen/logrus"
 	"os"
 	"path/filepath"
 )
@@ -74,13 +75,13 @@ func writeFile(saveFileFPath, enString, nowTime string) error {
 	return nil
 }
 
-func GetCodeFromWeb(nowTimeFileNamePrix string) (string, string, error) {
+func GetCodeFromWeb(l *logrus.Logger, nowTimeFileNamePrix string) (string, string, error) {
 	const baseCodeFileUrl = "https://cdn.jsdelivr.net/gh/"
 	const whichProject = "allanpk716/SomeThingsStatic/"
 
 	desUrl := baseCodeFileUrl + whichProject + nowTimeFileNamePrix + common.StaticFileName00
 
-	fileBytes, _, err := my_util.DownFile(desUrl)
+	fileBytes, _, err := my_util.DownFile(l, desUrl)
 	if err != nil {
 		return "", "", err
 	}

+ 1 - 1
internal/pkg/sub_formatter/sub_format_changer.go

@@ -85,7 +85,7 @@ func (s SubFormatChanger) autoDetectMovieThenChangeTo(outStruct *RenameResults,
 	}
 	// 先找出有那些电影文件夹和连续剧文件夹
 	var movieFullPathList = make([]string, 0)
-	movieFullPathList, err = my_util.SearchMatchedVideoFile(movieRootDir)
+	movieFullPathList, err = my_util.SearchMatchedVideoFile(log_helper.GetLogger(), movieRootDir)
 	// fmt.Println("No. of Movies: ", len(movieFullPathList), "  dir:  ", s.movieRootDir)
 	if err != nil {
 		return err

+ 3 - 2
internal/pkg/sub_helper/sub_helper.go

@@ -7,6 +7,7 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/decode"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/language"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_folder"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/regex_things"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_parser_hub"
@@ -27,7 +28,7 @@ func OrganizeDlSubFiles(tmpFolderName string, subInfos []supplier.SubInfo) (map[
 	// 缓存列表,整理后的字幕列表
 	// SxEx - []string 字幕的路径
 	var siteSubInfoDict = make(map[string][]string)
-	tmpFolderFullPath, err := my_util.GetTmpFolderByName(tmpFolderName)
+	tmpFolderFullPath, err := my_folder.GetTmpFolderByName(tmpFolderName)
 	if err != nil {
 		return nil, err
 	}
@@ -348,7 +349,7 @@ func SearchVideoMatchSubFileAndRemoveExtMark(oneVideoFullPath string) error {
 // DeleteOneSeasonSubCacheFolder 删除一个连续剧中的所有一季字幕的缓存文件夹
 func DeleteOneSeasonSubCacheFolder(seriesDir string) error {
 
-	debugFolderByName, err := my_util.GetDebugFolderByName([]string{filepath.Base(seriesDir)})
+	debugFolderByName, err := my_folder.GetDebugFolderByName([]string{filepath.Base(seriesDir)})
 	if err != nil {
 		return err
 	}

+ 3 - 2
internal/pkg/sub_helper/sub_helper_test.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/ass"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/srt"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_folder"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_parser_hub"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/unit_test_helper"
@@ -15,11 +16,11 @@ func TestDeleteOneSeasonSubCacheFolder(t *testing.T) {
 	const testSerName = "XXX"
 	const needDelFolderName = "Sub_S1E0"
 	testRootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"sub_helper", "org", needDelFolderName}, 4, false)
-	desSerFullPath, err := my_util.GetDebugFolderByName([]string{testSerName})
+	desSerFullPath, err := my_folder.GetDebugFolderByName([]string{testSerName})
 	if err != nil {
 		t.Fatal(err)
 	}
-	desSeasonFullPath, err := my_util.GetDebugFolderByName([]string{testSerName, filepath.Base(testRootDir)})
+	desSeasonFullPath, err := my_folder.GetDebugFolderByName([]string{testSerName, filepath.Base(testRootDir)})
 	if err != nil {
 		t.Fatal(err)
 	}

+ 2 - 1
internal/pkg/sub_share_center/share_sub_cache_helper.go

@@ -2,6 +2,7 @@ package sub_share_center
 
 import (
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_folder"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"os"
 	"path/filepath"
@@ -10,7 +11,7 @@ import (
 // CopySub2Cache 检测原有字幕是否存在,然后放到缓存目录中
 func CopySub2Cache(orgSubFileFPath, imdbID string, year int) (bool, string) {
 
-	nowFolderDir, err := my_util.GetShareFolderByYear(year)
+	nowFolderDir, err := my_folder.GetShareFolderByYear(year)
 	if err != nil {
 		log_helper.GetLogger().Errorln("CheckOrgSubFileExistAndCopy2Cache.GetShareFolderByYear", err)
 		return false, ""