Ver código fonte

重构项目结构

Signed-off-by: allan716 <[email protected]>
allan716 4 anos atrás
pai
commit
ed24aeb0b0
40 arquivos alterados com 513 adições e 499 exclusões
  1. 1 0
      .gitignore
  2. 54 51
      internal/downloader.go
  3. 14 11
      internal/downloader_test.go
  4. 1 1
      internal/ifaces/iSubParser.go
  5. 1 1
      internal/ifaces/iSupplier.go
  6. 19 18
      internal/logic/emby_helper/embyhelper.go
  7. 2 18
      internal/logic/emby_helper/embyhelper_test.go
  8. 15 14
      internal/logic/mark_system/markingsystem.go
  9. 32 29
      internal/logic/movie_helper/moviehelper.go
  10. 40 36
      internal/logic/series_helper/seriesHelper.go
  11. 6 6
      internal/logic/sub_parser/ass/ass.go
  12. 6 6
      internal/logic/sub_parser/srt/srt.go
  13. 8 7
      internal/logic/sub_supplier/shooter/shooter.go
  14. 19 18
      internal/logic/sub_supplier/subSupplierHub.go
  15. 34 29
      internal/logic/sub_supplier/subhd/subhd.go
  16. 14 11
      internal/logic/sub_supplier/xunlei/xunlei.go
  17. 35 30
      internal/logic/sub_supplier/zimuku/zimuku.go
  18. 1 1
      internal/pkg/archive_helper/unarchiveFile.go
  19. 1 1
      internal/pkg/archive_helper/unarchiveFile_test.go
  20. 28 6
      internal/pkg/config.go
  21. 0 28
      internal/pkg/deal_sub.go
  22. 10 9
      internal/pkg/decode/decode.go
  23. 1 1
      internal/pkg/decode/decode_test.go
  24. 14 13
      internal/pkg/emby_helper/emby.go
  25. 7 22
      internal/pkg/emby_helper/emby_test.go
  26. 5 3
      internal/pkg/imdb_helper/imdb.go
  27. 1 1
      internal/pkg/imdb_helper/imdb_test.go
  28. 5 5
      internal/pkg/language/language.go
  29. 3 3
      internal/pkg/log_helper/loghelper.go
  30. 3 2
      internal/pkg/notify_center/NotifyCenter.go
  31. 3 11
      internal/pkg/notify_center/NotifyCenter_test.go
  32. 5 3
      internal/pkg/pass_water_wall/pass_water_wall.go
  33. 1 1
      internal/pkg/pass_water_wall/pass_water_wall_test.go
  34. 1 1
      internal/pkg/rod_helper/rodHelper.go
  35. 1 1
      internal/pkg/rod_helper/rodHelper_test.go
  36. 16 14
      internal/pkg/sub_helper/subParserHub.go
  37. 79 20
      internal/pkg/sub_helper/sub_helper.go
  38. 17 45
      internal/pkg/util.go
  39. 1 1
      internal/types/language.go
  40. 9 21
      main.go

+ 1 - 0
.gitignore

@@ -17,3 +17,4 @@
 /dist
 /internal/logic/emby_helper/config.yaml
 /emby_helper/Logs/*.log
+/internal/config.yaml

+ 54 - 51
downloader.go → internal/downloader.go

@@ -1,16 +1,19 @@
-package main
+package internal
 
 import (
-	common2 "github.com/allanpk716/ChineseSubFinder/internal/common"
-	emby_helper2 "github.com/allanpk716/ChineseSubFinder/internal/logic/emby_helper"
-	mark_system2 "github.com/allanpk716/ChineseSubFinder/internal/logic/mark_system"
-	series_helper2 "github.com/allanpk716/ChineseSubFinder/internal/logic/series_helper"
-	sub_supplier2 "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier"
-	shooter2 "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/shooter"
-	subhd2 "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/subhd"
-	xunlei2 "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/xunlei"
-	zimuku2 "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/zimuku"
+	"github.com/allanpk716/ChineseSubFinder/internal/common"
+	embyHelper "github.com/allanpk716/ChineseSubFinder/internal/logic/emby_helper"
+	markSystem "github.com/allanpk716/ChineseSubFinder/internal/logic/mark_system"
+	seriesHelper "github.com/allanpk716/ChineseSubFinder/internal/logic/series_helper"
+	subSupplier "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier"
+	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/shooter"
+	"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"
+	"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/types"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/emby"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/series"
@@ -30,9 +33,9 @@ import (
 type Downloader struct {
 	reqParam           types.ReqParam
 	log                *logrus.Logger
-	topic              int                         // 最多能够下载 Top 几的字幕,每一个网站
-	mk                 *mark_system2.MarkingSystem // MarkingSystem
-	embyHelper         *emby_helper2.EmbyHelper
+	topic              int                       // 最多能够下载 Top 几的字幕,每一个网站
+	mk                 *markSystem.MarkingSystem // MarkingSystem
+	embyHelper         *embyHelper.EmbyHelper
 	movieDirList       []string                           //  多个需要搜索字幕的电影目录
 	seriesSubNeedDlMap map[string][]emby.EmbyMixInfo //  多个需要搜索字幕的连续剧目录
 }
@@ -40,8 +43,8 @@ type Downloader struct {
 func NewDownloader(_reqParam ...types.ReqParam) *Downloader {
 
 	var downloader Downloader
-	downloader.log = pkg.GetLogger()
-	downloader.topic = common2.DownloadSubsPerSite
+	downloader.log = log_helper.GetLogger()
+	downloader.topic = common.DownloadSubsPerSite
 	if len(_reqParam) > 0 {
 		downloader.reqParam = _reqParam[0]
 		if downloader.reqParam.Topic > 0 && downloader.reqParam.Topic != downloader.topic {
@@ -55,7 +58,7 @@ func NewDownloader(_reqParam ...types.ReqParam) *Downloader {
 		}
 		// 初始化 Emby API 接口
 		if downloader.reqParam.EmbyConfig.Url != "" && downloader.reqParam.EmbyConfig.ApiKey != "" {
-			downloader.embyHelper = emby_helper2.NewEmbyHelper(downloader.reqParam.EmbyConfig)
+			downloader.embyHelper = embyHelper.NewEmbyHelper(downloader.reqParam.EmbyConfig)
 		}
 	} else {
 		downloader.reqParam = *types.NewReqParam()
@@ -63,11 +66,11 @@ func NewDownloader(_reqParam ...types.ReqParam) *Downloader {
 
 	var sitesSequence = make([]string, 0)
 	// TODO 这里写固定了抉择字幕的顺序
-	sitesSequence = append(sitesSequence, common2.SubSiteZiMuKu)
-	sitesSequence = append(sitesSequence, common2.SubSiteSubHd)
-	sitesSequence = append(sitesSequence, common2.SubSiteXunLei)
-	sitesSequence = append(sitesSequence, common2.SubSiteShooter)
-	downloader.mk = mark_system2.NewMarkingSystem(sitesSequence, downloader.reqParam.SubTypePriority)
+	sitesSequence = append(sitesSequence, common.SubSiteZiMuKu)
+	sitesSequence = append(sitesSequence, common.SubSiteSubHd)
+	sitesSequence = append(sitesSequence, common.SubSiteXunLei)
+	sitesSequence = append(sitesSequence, common.SubSiteShooter)
+	downloader.mk = markSystem.NewMarkingSystem(sitesSequence, downloader.reqParam.SubTypePriority)
 
 	downloader.movieDirList = make([]string, 0)
 	downloader.seriesSubNeedDlMap = make(map[string][]emby.EmbyMixInfo)
@@ -122,22 +125,22 @@ func (d Downloader) DownloadSub4Movie(dir string) error {
 		if err != nil {
 			d.log.Error("ClearRootTmpFolder", err)
 		}
-		log.Infoln("Download Movie Sub End...")
+		d.log.Infoln("Download Movie Sub End...")
 	}()
 	var err error
-	log.Infoln("Download Movie Sub Started...")
-	// 是否是通过 emby api 获取的列表
+	d.log.Infoln("Download Movie Sub Started...")
+	// 是否是通过 emby_helper api 获取的列表
 	if d.embyHelper == nil {
-		// 没有填写 emby api 的信息,那么就走常规的全文件扫描流程
+		// 没有填写 emby_helper api 的信息,那么就走常规的全文件扫描流程
 		d.movieDirList, err = pkg.SearchMatchedVideoFile(dir)
 		if err != nil {
 			return err
 		}
 	} else {
-		// 进过 emby api 的信息读取
-		log.Infoln("Movie Sub Dl From Emby API...")
+		// 进过 emby_helper api 的信息读取
+		d.log.Infoln("Movie Sub Dl From Emby API...")
 		if len(d.movieDirList) < 1 {
-			log.Infoln("Movie Sub Dl From Emby API no movie need Dl sub")
+			d.log.Infoln("Movie Sub Dl From Emby API no movie need Dl sub")
 			return nil
 		}
 	}
@@ -146,11 +149,11 @@ func (d Downloader) DownloadSub4Movie(dir string) error {
 		inData := i.(InputData)
 		// -----------------------------------------------------
 		// 构建每个字幕站点下载者的实例
-		var subSupplierHub = sub_supplier2.NewSubSupplierHub(
-			subhd2.NewSupplier(d.reqParam),
-			zimuku2.NewSupplier(d.reqParam),
-			xunlei2.NewSupplier(d.reqParam),
-			shooter2.NewSupplier(d.reqParam),
+		var subSupplierHub = subSupplier.NewSubSupplierHub(
+			subhd.NewSupplier(d.reqParam),
+			zimuku.NewSupplier(d.reqParam),
+			xunlei.NewSupplier(d.reqParam),
+			shooter.NewSupplier(d.reqParam),
 		)
 		// 字幕都下载缓存好了,需要抉择存哪一个,优先选择中文双语的,然后到中文
 		organizeSubFiles, err := subSupplierHub.DownloadSub4Movie(inData.OneVideoFullPath, inData.Index)
@@ -170,7 +173,7 @@ func (d Downloader) DownloadSub4Movie(dir string) error {
 	p, err := ants.NewPoolWithFunc(d.reqParam.Threads, func(inData interface{}) {
 		data := inData.(InputData)
 		defer data.Wg.Done()
-		ctx, cancel := context.WithTimeout(context.Background(), common2.OneVideoProcessTimeOut)
+		ctx, cancel := context.WithTimeout(context.Background(), common.OneVideoProcessTimeOut)
 		defer cancel()
 
 		done := make(chan error, 1)
@@ -221,25 +224,25 @@ func (d Downloader) DownloadSub4Series(dir string) error {
 		if err != nil {
 			d.log.Error("ClearRootTmpFolder", err)
 		}
-		log.Infoln("Download Series Sub End...")
+		d.log.Infoln("Download Series Sub End...")
 	}()
-	log.Infoln("Download Series Sub Started...")
+	d.log.Infoln("Download Series Sub Started...")
 
 	// 并发控制
 	seriesDlFunc := func(i interface{}) error {
 		inData := i.(InputData)
 		// 构建每个字幕站点下载者的实例
-		var subSupplierHub *sub_supplier2.SubSupplierHub
-		subSupplierHub = sub_supplier2.NewSubSupplierHub(
-			zimuku2.NewSupplier(d.reqParam),
-			subhd2.NewSupplier(d.reqParam),
-			xunlei2.NewSupplier(d.reqParam),
-			shooter2.NewSupplier(d.reqParam),
+		var subSupplierHub *subSupplier.SubSupplierHub
+		subSupplierHub = subSupplier.NewSubSupplierHub(
+			zimuku.NewSupplier(d.reqParam),
+			subhd.NewSupplier(d.reqParam),
+			xunlei.NewSupplier(d.reqParam),
+			shooter.NewSupplier(d.reqParam),
 		)
 		// 这里拿到了这一部连续剧的所有的剧集信息,以及所有下载到的字幕信息
 		var seriesInfo *series.SeriesInfo
 		var organizeSubFiles map[string][]string
-		// 是否是通过 emby api 获取的列表
+		// 是否是通过 emby_helper api 获取的列表
 		if d.embyHelper == nil {
 			seriesInfo, organizeSubFiles, err = subSupplierHub.DownloadSub4Series(inData.OneVideoFullPath, inData.Index)
 			if err != nil {
@@ -247,7 +250,7 @@ func (d Downloader) DownloadSub4Series(dir string) error {
 				return err
 			}
 		} else {
-			// 先进性 emby api 的操作,读取需要更新字幕的项目
+			// 先进性 emby_helper api 的操作,读取需要更新字幕的项目
 			seriesInfo, organizeSubFiles, err = subSupplierHub.DownloadSub4SeriesFromEmby(
 				path.Join(dir, inData.OneVideoFullPath),
 				d.seriesSubNeedDlMap[inData.OneVideoFullPath], inData.Index)
@@ -285,7 +288,7 @@ func (d Downloader) DownloadSub4Series(dir string) error {
 	p, err := ants.NewPoolWithFunc(d.reqParam.Threads, func(inData interface{}) {
 		data := inData.(InputData)
 		defer data.Wg.Done()
-		ctx, cancel := context.WithTimeout(context.Background(), common2.OneVideoProcessTimeOut)
+		ctx, cancel := context.WithTimeout(context.Background(), common.OneVideoProcessTimeOut)
 		defer cancel()
 
 		done := make(chan error, 1)
@@ -315,11 +318,11 @@ func (d Downloader) DownloadSub4Series(dir string) error {
 	}
 	defer p.Release()
 
-	// 是否是通过 emby api 获取的列表
+	// 是否是通过 emby_helper api 获取的列表
 	var seriesDirList = make([]string, 0)
 	if d.embyHelper == nil {
 		// 遍历连续剧总目录下的第一层目录
-		seriesDirList, err = series_helper2.GetSeriesList(dir)
+		seriesDirList, err = seriesHelper.GetSeriesList(dir)
 		if err != nil {
 			return err
 		}
@@ -409,7 +412,7 @@ func (d Downloader) saveFullSeasonSub(seriesInfo *series.SeriesInfo, organizeSub
 				continue
 			}
 			// 从字幕的文件名推断是 哪一季 的 那一集
-			_, gusSeason, gusEpisode, err := pkg.GetSeasonAndEpisodeFromSubFileName(subFileName)
+			_, gusSeason, gusEpisode, err := decode.GetSeasonAndEpisodeFromSubFileName(subFileName)
 			if err != nil {
 				return nil
 			}
@@ -430,8 +433,8 @@ func (d Downloader) saveFullSeasonSub(seriesInfo *series.SeriesInfo, organizeSub
 // 在前面需要进行语言的筛选、排序,这里仅仅是存储
 func (d Downloader) writeSubFile2VideoPath(videoFileFullPath string, finalSubFile subparser.FileInfo, extraSubPreName string) error {
 	videoRootPath := filepath.Dir(videoFileFullPath)
-	embyLanExtName := pkg.Lang2EmbyName(finalSubFile.Lang)
-	// 构建视频文件加 emby 的字幕预研要求名称
+	embyLanExtName := language.Lang2EmbyName(finalSubFile.Lang)
+	// 构建视频文件加 emby_helper 的字幕预研要求名称
 	videoFileNameWithOutExt := strings.ReplaceAll(filepath.Base(videoFileFullPath),
 		filepath.Ext(videoFileFullPath), "")
 	if extraSubPreName != "" {
@@ -454,7 +457,7 @@ func (d Downloader) copySubFile2DesFolder(desFolder string, subFiles []string) e
 
 	// 需要进行字幕文件的缓存
 	// 把缓存的文件夹新建出来
-	desFolderFullPath := path.Join(desFolder, common2.SubTmpFolderName)
+	desFolderFullPath := path.Join(desFolder, common.SubTmpFolderName)
 	err := os.MkdirAll(desFolderFullPath, os.ModePerm)
 	if err != nil {
 		return err

+ 14 - 11
downloader_test.go → internal/downloader_test.go

@@ -1,9 +1,10 @@
-package main
+package internal
 
 import (
-	ass2 "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/ass"
-	srt2 "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/srt"
+	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/ass"
+	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/srt"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	"testing"
 )
@@ -18,11 +19,11 @@ func TestDownloader_DownloadSub4Movie(t *testing.T) {
 	//dirRoot := "X:\\电影\\送你一朵小红花 (2020)"
 	//dirRoot := "X:\\电影\\冰海陷落 (2018)"
 	//dirRoot := "X:\\电影"
-
+	config := pkg.GetConfig()
 	dl := NewDownloader(types.ReqParam{
-		SaveMultiSub: true,
+		SaveMultiSub:    true,
 		SubTypePriority: 1,
-		EmbyConfig: config.EmbyConfig,
+		EmbyConfig:      config.EmbyConfig,
 	})
 	err = dl.GetUpdateVideoListFromEmby(config.MovieFolder, config.SeriesFolder)
 	if err != nil {
@@ -48,11 +49,12 @@ func TestDownloader_DownloadSub4Series(t *testing.T) {
 	//dirRoot := "X:\\连续剧\\黄石 (2018)"
 	dirRoot := "X:\\连续剧"
 
+	config := pkg.GetConfig()
 	// 如果需要调试 Emby 一定需要 dirRoot := "X:\\连续剧"
 	dl := NewDownloader(types.ReqParam{
-		SaveMultiSub: true,
+		SaveMultiSub:    true,
 		SubTypePriority: 1,
-		EmbyConfig: config.EmbyConfig,
+		EmbyConfig:      config.EmbyConfig,
 	})
 	err = dl.GetUpdateVideoListFromEmby(config.MovieFolder, config.SeriesFolder)
 	if err != nil {
@@ -66,10 +68,11 @@ func TestDownloader_DownloadSub4Series(t *testing.T) {
 
 func TestDownloader_GetUpdateVideoListFromEmby(t *testing.T) {
 	var err error
+	config := pkg.GetConfig()
 	dl := NewDownloader(types.ReqParam{
-		SaveMultiSub: true,
+		SaveMultiSub:    true,
 		SubTypePriority: 1,
-		EmbyConfig: config.EmbyConfig,
+		EmbyConfig:      config.EmbyConfig,
 	})
 	err = dl.GetUpdateVideoListFromEmby(config.MovieFolder, config.SeriesFolder)
 	if err != nil {
@@ -84,6 +87,6 @@ func TestDownloader_SubParserHub(t *testing.T) {
 	//subFile := "X:\\连续剧\\瑞克和莫蒂 (2013)\\Season 4\\瑞克和莫蒂 - S04E01 - Rick and Morty.zh.srt"
 	subFile := "X:\\连续剧\\黑钱胜地 (2017)\\Sub_S3E0\\[subhd]_0_Ozark.S03E07.iNTERNAL.720p.WEB.x264-GHOSTS.chs.eng.ass"
 
-	subParserHub := pkg.NewSubParserHub(ass2.NewParser(), srt2.NewParser())
+	subParserHub := sub_helper.NewSubParserHub(ass.NewParser(), srt.NewParser())
 	subParserHub.IsSubHasChinese(subFile)
 }

+ 1 - 1
internal/interface/iSubParser.go → internal/ifaces/iSubParser.go

@@ -1,4 +1,4 @@
-package _interface
+package ifaces
 
 import (
 	"github.com/allanpk716/ChineseSubFinder/internal/types/subparser"

+ 1 - 1
internal/interface/iSupplier.go → internal/ifaces/iSupplier.go

@@ -1,4 +1,4 @@
-package _interface
+package ifaces
 
 import (
 	"github.com/allanpk716/ChineseSubFinder/internal/types"

+ 19 - 18
internal/logic/emby_helper/embyhelper.go

@@ -1,8 +1,9 @@
 package emby_helper
 
 import (
-	common2 "github.com/allanpk716/ChineseSubFinder/internal/common"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	"github.com/allanpk716/ChineseSubFinder/internal/common"
+	embyHelper "github.com/allanpk716/ChineseSubFinder/internal/pkg/emby_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/emby"
 	"github.com/panjf2000/ants/v2"
@@ -15,7 +16,7 @@ import (
 )
 
 type EmbyHelper struct {
-	embyApi    *pkg.EmbyApi
+	embyApi    *embyHelper.EmbyApi
 	EmbyConfig emby.EmbyConfig
 	threads    int
 	timeOut    time.Duration
@@ -24,7 +25,7 @@ type EmbyHelper struct {
 
 func NewEmbyHelper(embyConfig emby.EmbyConfig) *EmbyHelper {
 	em := EmbyHelper{EmbyConfig: embyConfig}
-	em.embyApi = pkg.NewEmbyHelper(embyConfig)
+	em.embyApi = embyHelper.NewEmbyHelper(embyConfig)
 	em.threads = 6
 	em.timeOut = 5 * time.Second
 	return &em
@@ -46,10 +47,10 @@ func (em *EmbyHelper) GetRecentlyAddVideoList(movieRootDir, seriesRootDir string
 	// 分类
 	for _, item := range items.Items {
 		if item.Type == "Episode" {
-			// 这个里面可能混有其他的内容,比如目标是连续剧,但是 emby 其实会把其他的混合内容也标记进去
+			// 这个里面可能混有其他的内容,比如目标是连续剧,但是 emby_helper 其实会把其他的混合内容也标记进去
 			EpisodeIdList = append(EpisodeIdList, item.Id)
 		} else if item.Type == "Movie" {
-			// 这个里面可能混有其他的内容,比如目标是连续剧,但是 emby 其实会把其他的混合内容也标记进去
+			// 这个里面可能混有其他的内容,比如目标是连续剧,但是 emby_helper 其实会把其他的混合内容也标记进去
 			MovieIdList = append(MovieIdList, item.Id)
 		}
 	}
@@ -181,7 +182,7 @@ func (em *EmbyHelper) filterEmbyVideoList(videoFolderName string, videoIdList []
 		case outData := <- done:
 			// 收到结果,需要加锁
 			if outData.Err != nil {
-				pkg.GetLogger().Errorln("filterEmbyVideoList.NewPoolWithFunc got Err", outData.Err)
+				log_helper.GetLogger().Errorln("filterEmbyVideoList.NewPoolWithFunc got Err", outData.Err)
 				return
 			}
 			if outData.Info == nil {
@@ -192,9 +193,9 @@ func (em *EmbyHelper) filterEmbyVideoList(videoFolderName string, videoIdList []
 			em.listLock.Unlock()
 			return
 		case p := <- panicChan:
-			pkg.GetLogger().Errorln("filterEmbyVideoList.NewPoolWithFunc got panic", p)
+			log_helper.GetLogger().Errorln("filterEmbyVideoList.NewPoolWithFunc got panic", p)
 		case <-ctx.Done():
-			pkg.GetLogger().Errorln("filterEmbyVideoList.NewPoolWithFunc got time out", ctx.Err())
+			log_helper.GetLogger().Errorln("filterEmbyVideoList.NewPoolWithFunc got time out", ctx.Err())
 			return
 		}
 	})
@@ -208,7 +209,7 @@ func (em *EmbyHelper) filterEmbyVideoList(videoFolderName string, videoIdList []
 		wg.Add(1)
 		err = p.Invoke(InputData{Id: m, Wg: &wg})
 		if err != nil {
-			pkg.GetLogger().Errorln("filterEmbyVideoList ants.Invoke", err)
+			log_helper.GetLogger().Errorln("filterEmbyVideoList ants.Invoke", err)
 		}
 	}
 	wg.Wait()
@@ -218,8 +219,8 @@ func (em *EmbyHelper) filterEmbyVideoList(videoFolderName string, videoIdList []
 
 func (em *EmbyHelper) filterNoChineseSubVideoList(videoList []emby.EmbyMixInfo) ([]emby.EmbyMixInfo, error) {
 	currentTime := time.Now()
-	dayRange_3Months, _ := time.ParseDuration(common2.DownloadSubDuring3Months)
-	dayRange_7Days, _ := time.ParseDuration(common2.DownloadSubDuring7Days)
+	dayRange3Months, _ := time.ParseDuration(common.DownloadSubDuring3Months)
+	dayRange7Days, _ := time.ParseDuration(common.DownloadSubDuring7Days)
 
 	var noSubVideoList = make([]emby.EmbyMixInfo, 0)
 	// TODO 这里有一种情况需要考虑的,如果内置有中文的字幕,那么是否需要跳过,目前暂定的一定要有外置的字幕
@@ -227,7 +228,7 @@ func (em *EmbyHelper) filterNoChineseSubVideoList(videoList []emby.EmbyMixInfo)
 
 		needDlSub3Month := false
 		// 3个月内,或者没有字幕都要进行下载
-		if info.VideoInfo.PremiereDate.Add(dayRange_3Months).After(currentTime) == true {
+		if info.VideoInfo.PremiereDate.Add(dayRange3Months).After(currentTime) == true {
 			// 需要下载的
 			needDlSub3Month = true
 		}
@@ -257,11 +258,11 @@ func (em *EmbyHelper) filterNoChineseSubVideoList(videoList []emby.EmbyMixInfo)
 		// 比如,创建的时间在3个月内,然后没有额外下载的中文字幕,都符合要求
 		if haveExternalChineseSub == false {
 			// 如果创建了7天,且有内置的中文字幕,那么也不进行下载了
-			if info.VideoInfo.DateCreated.Add(dayRange_7Days).After(currentTime) == false && haveInsideChineseSub == true {
+			if info.VideoInfo.DateCreated.Add(dayRange7Days).After(currentTime) == false && haveInsideChineseSub == true {
 				continue
 			}
 			// 如果创建了三个月,还是没有字幕,那么也不进行下载了
-			if info.VideoInfo.DateCreated.Add(dayRange_3Months).After(currentTime) == false {
+			if info.VideoInfo.DateCreated.Add(dayRange3Months).After(currentTime) == false {
 				continue
 			}
 			// 没有中文字幕就加入下载列表
@@ -319,9 +320,9 @@ func (em *EmbyHelper) langStringOK(inLang string) bool {
 func (em *EmbyHelper) subTypeStringOK(inSubType string) bool {
 
 	tmpString := strings.ToLower(inSubType)
-	if tmpString == common2.SubTypeSRT ||
-		tmpString == common2.SubTypeASS ||
-		tmpString == common2.SubTypeSSA {
+	if tmpString == common.SubTypeSRT ||
+		tmpString == common.SubTypeASS ||
+		tmpString == common.SubTypeSSA {
 		return true
 	}
 

+ 2 - 18
internal/logic/emby_helper/embyhelper_test.go

@@ -2,24 +2,11 @@ package emby_helper
 
 import (
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
-	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	"testing"
 )
 
-func init() {
-	var err error
-	configViper, err := pkg.InitConfigure()
-	if err != nil {
-		return
-	}
-	config, err = pkg.ReadConfig(configViper)
-	if err != nil {
-		return
-	}
-}
-
 func TestEmbyHelper_GetRecentlyAddVideoList(t *testing.T) {
-
+	config := pkg.GetConfig()
 	em := NewEmbyHelper(config.EmbyConfig)
 	movieList, seriesList, err := em.GetRecentlyAddVideoList(config.MovieFolder, config.SeriesFolder)
 	if err != nil {
@@ -29,11 +16,8 @@ func TestEmbyHelper_GetRecentlyAddVideoList(t *testing.T) {
 	println(len(movieList), len(seriesList))
 }
 
-var (
-	config *types.Config
-)
-
 func TestEmbyHelper_RefreshEmbySubList(t *testing.T) {
+	config := pkg.GetConfig()
 	em := NewEmbyHelper(config.EmbyConfig)
 	bok, err := em.RefreshEmbySubList()
 	if err != nil {

+ 15 - 14
internal/logic/mark_system/markingsystem.go

@@ -1,9 +1,10 @@
 package mark_system
 
 import (
-	ass2 "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/ass"
-	srt2 "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/srt"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/ass"
+	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/srt"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/subparser"
 	"github.com/sirupsen/logrus"
 )
@@ -13,14 +14,14 @@ type MarkingSystem struct {
 	log *logrus.Logger
 	subSiteSequence []string			// 网站的优先级,从高到低
 	SubTypePriority int					// 字幕格式的优先级
-	subParserHub *pkg.SubParserHub
+	subParserHub *sub_helper.SubParserHub
 }
 
 func NewMarkingSystem(subSiteSequence []string, subTypePriority int) *MarkingSystem {
 	mk := MarkingSystem{subSiteSequence: subSiteSequence,
-		log:             pkg.GetLogger(),
+		log:             log_helper.GetLogger(),
 		SubTypePriority: subTypePriority,
-		subParserHub:    pkg.NewSubParserHub(ass2.NewParser(), srt2.NewParser())}
+		subParserHub:    sub_helper.NewSubParserHub(ass.NewParser(), srt.NewParser())}
 	return &mk
 }
 
@@ -41,13 +42,13 @@ func (m MarkingSystem) SelectOneSubFile(organizeSubFiles []string) *subparser.Fi
 				continue
 			}
 			if i == 0 {
-				finalSubFile = pkg.SelectChineseBestBilingualSubtitle(infos, m.SubTypePriority)
+				finalSubFile = sub_helper.SelectChineseBestBilingualSubtitle(infos, m.SubTypePriority)
 			} else if i == 1 {
-				finalSubFile = pkg.SelectChineseBestSubtitle(infos, m.SubTypePriority)
+				finalSubFile = sub_helper.SelectChineseBestSubtitle(infos, m.SubTypePriority)
 			} else if i == 2 {
-				finalSubFile = pkg.SelectChineseBestBilingualSubtitle(infos, 0)
+				finalSubFile = sub_helper.SelectChineseBestBilingualSubtitle(infos, 0)
 			} else if i == 3 {
-				finalSubFile = pkg.SelectChineseBestSubtitle(infos, 0)
+				finalSubFile = sub_helper.SelectChineseBestSubtitle(infos, 0)
 			}
 			if finalSubFile != nil {
 				return finalSubFile
@@ -73,13 +74,13 @@ func (m MarkingSystem) SelectEachSiteTop1SubFile(organizeSubFiles []string) ([]s
 		for siteName, infos := range subInfoDict {
 			// 每个网站保存一个
 			if i == 0 {
-				finalSubFile = pkg.SelectChineseBestBilingualSubtitle(infos, m.SubTypePriority)
+				finalSubFile = sub_helper.SelectChineseBestBilingualSubtitle(infos, m.SubTypePriority)
 			} else if i == 1 {
-				finalSubFile = pkg.SelectChineseBestSubtitle(infos, m.SubTypePriority)
+				finalSubFile = sub_helper.SelectChineseBestSubtitle(infos, m.SubTypePriority)
 			} else if i == 2 {
-				finalSubFile = pkg.SelectChineseBestBilingualSubtitle(infos, 0)
+				finalSubFile = sub_helper.SelectChineseBestBilingualSubtitle(infos, 0)
 			} else if i == 3 {
-				finalSubFile = pkg.SelectChineseBestSubtitle(infos, 0)
+				finalSubFile = sub_helper.SelectChineseBestSubtitle(infos, 0)
 			}
 			if finalSubFile != nil {
 				outSiteName = append(outSiteName, siteName)

+ 32 - 29
internal/logic/movie_helper/moviehelper.go

@@ -1,11 +1,14 @@
 package movie_helper
 
 import (
-	common2 "github.com/allanpk716/ChineseSubFinder/internal/common"
-	_interface2 "github.com/allanpk716/ChineseSubFinder/internal/interface"
-	ass2 "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/ass"
-	srt2 "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/srt"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	"github.com/allanpk716/ChineseSubFinder/internal/common"
+	"github.com/allanpk716/ChineseSubFinder/internal/ifaces"
+	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/ass"
+	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/srt"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/decode"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/imdb_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/supplier"
 	"github.com/jinzhu/now"
@@ -16,17 +19,17 @@ import (
 )
 
 // OneMovieDlSubInAllSite 一部电影在所有的网站下载相应的字幕
-func OneMovieDlSubInAllSite(Suppliers []_interface2.ISupplier, oneVideoFullPath string, i int) []supplier.SubInfo {
+func OneMovieDlSubInAllSite(Suppliers []ifaces.ISupplier, oneVideoFullPath string, i int) []supplier.SubInfo {
 	var outSUbInfos = make([]supplier.SubInfo, 0)
 	// 同时进行查询
 	subInfosChannel := make(chan []supplier.SubInfo)
-	pkg.GetLogger().Infoln("DlSub Start", oneVideoFullPath)
-	for _, supplier := range Suppliers {
-		supplier := supplier
+	log_helper.GetLogger().Infoln("DlSub Start", oneVideoFullPath)
+	for _, oneSupplier := range Suppliers {
+		nowSupplier := oneSupplier
 		go func() {
-			subInfos, err := OneMovieDlSubInOneSite(oneVideoFullPath, i, supplier)
+			subInfos, err := OneMovieDlSubInOneSite(oneVideoFullPath, i, nowSupplier)
 			if err != nil {
-				pkg.GetLogger().Errorln(supplier.GetSupplierName(), "oneMovieDlSubInOneSite", err)
+				log_helper.GetLogger().Errorln(nowSupplier.GetSupplierName(), "oneMovieDlSubInOneSite", err)
 			}
 			subInfosChannel <- subInfos
 		}()
@@ -37,22 +40,22 @@ func OneMovieDlSubInAllSite(Suppliers []_interface2.ISupplier, oneVideoFullPath
 			outSUbInfos = append(outSUbInfos, v...)
 		}
 	}
-	pkg.GetLogger().Infoln("DlSub End", oneVideoFullPath)
+	log_helper.GetLogger().Infoln("DlSub End", oneVideoFullPath)
 	return outSUbInfos
 }
 
 // OneMovieDlSubInOneSite 一部电影在一个站点下载字幕
-func OneMovieDlSubInOneSite(oneVideoFullPath string, i int, supplier _interface2.ISupplier) ([]supplier.SubInfo, error) {
+func OneMovieDlSubInOneSite(oneVideoFullPath string, i int, supplier ifaces.ISupplier) ([]supplier.SubInfo, error) {
 	defer func() {
-		pkg.GetLogger().Infoln(i, supplier.GetSupplierName(), "End...")
+		log_helper.GetLogger().Infoln(i, supplier.GetSupplierName(), "End...")
 	}()
-	pkg.GetLogger().Infoln(i, supplier.GetSupplierName(), "Start...")
+	log_helper.GetLogger().Infoln(i, supplier.GetSupplierName(), "Start...")
 	subInfos, err := supplier.GetSubListFromFile4Movie(oneVideoFullPath)
 	if err != nil {
 		return nil, err
 	}
 	// 把后缀名给改好
-	pkg.ChangeVideoExt2SubExt(subInfos)
+	sub_helper.ChangeVideoExt2SubExt(subInfos)
 
 	return subInfos, nil
 }
@@ -69,11 +72,11 @@ func MovieHasSub(videoFilePath string) (bool, error) {
 			continue
 		} else {
 			// 文件
-			if pkg.IsSubExtWanted(curFile.Name()) == false {
+			if sub_helper.IsSubExtWanted(curFile.Name()) == false {
 				continue
 			}
 			// 字幕文件是否包含中文
-			if pkg.NewSubParserHub(ass2.NewParser(), srt2.NewParser()).IsSubHasChinese(filepath.Join(dir, curFile.Name())) == true {
+			if sub_helper.NewSubParserHub(ass.NewParser(), srt.NewParser()).IsSubHasChinese(filepath.Join(dir, curFile.Name())) == true {
 				return true, nil
 			}
 		}
@@ -87,16 +90,16 @@ func SkipChineseMovie(videoFullPath string, _reqParam ...types.ReqParam) (bool,
 	if len(_reqParam) > 0 {
 		reqParam = _reqParam[0]
 	}
-	imdbInfo, err := pkg.GetImdbInfo4Movie(videoFullPath)
+	imdbInfo, err := decode.GetImdbInfo4Movie(videoFullPath)
 	if err != nil {
 		return false, err
 	}
-	t, err := pkg.GetVideoInfoFromIMDB(imdbInfo.ImdbId, reqParam)
+	t, err := imdb_helper.GetVideoInfoFromIMDB(imdbInfo.ImdbId, reqParam)
 	if err != nil {
 		return false, err
 	}
 	if len(t.Languages) > 0 && strings.ToLower(t.Languages[0]) == "chinese" {
-		pkg.GetLogger().Infoln("Skip", videoFullPath, "Sub Download, because movie is Chinese")
+		log_helper.GetLogger().Infoln("Skip", videoFullPath, "Sub Download, because movie is Chinese")
 		return true, nil
 	}
 	return false, nil
@@ -110,8 +113,8 @@ func MovieNeedDlSub(videoFullPath string) (bool, error) {
 	}
 	// 资源下载的时间后的多少天内都进行字幕的自动下载,替换原有的字幕
 	currentTime := time.Now()
-	dayRange, _ := time.ParseDuration(common2.DownloadSubDuring3Months)
-	mInfo, modifyTime, err := pkg.GetVideoInfoFromFileFullPath(videoFullPath)
+	dayRange, _ := time.ParseDuration(common.DownloadSubDuring3Months)
+	mInfo, modifyTime, err := decode.GetVideoInfoFromFileFullPath(videoFullPath)
 	if err != nil {
 		return false, err
 	}
@@ -122,14 +125,14 @@ func MovieNeedDlSub(videoFullPath string) (bool, error) {
 			return true, nil
 		} else {
 			// 有字幕了,没必要每次都刷新,跳过
-			pkg.GetLogger().Infoln("Skip", filepath.Base(videoFullPath), "Sub Download, because movie has sub and published more than 2 years")
+			log_helper.GetLogger().Infoln("Skip", filepath.Base(videoFullPath), "Sub Download, because movie has sub and published more than 2 years")
 			return false, nil
 		}
 	} else {
 		// 读取不到 IMDB 信息也能接受
-		videoIMDBInfo, err := pkg.GetImdbInfo4Movie(videoFullPath)
+		videoIMDBInfo, err := decode.GetImdbInfo4Movie(videoFullPath)
 		if err != nil {
-			pkg.GetLogger().Errorln("MovieNeedDlSub.GetImdbInfo4Movie", err)
+			log_helper.GetLogger().Errorln("MovieNeedDlSub.GetImdbInfo4Movie", err)
 		}
 		// 如果播出时间能够读取到,那么就以这个完后推算 3个月
 		// 如果读取不到 Aired Time 那么,下载后的 ModifyTime 3个月天内,都进行字幕的下载
@@ -137,7 +140,7 @@ func MovieNeedDlSub(videoFullPath string) (bool, error) {
 		if videoIMDBInfo.ReleaseDate != "" {
 			baseTime, err = now.Parse(videoIMDBInfo.ReleaseDate)
 			if err != nil {
-				pkg.GetLogger().Errorln("Movie parse AiredTime", err)
+				log_helper.GetLogger().Errorln("Movie parse AiredTime", err)
 				baseTime = modifyTime
 			}
 		} else {
@@ -150,11 +153,11 @@ func MovieNeedDlSub(videoFullPath string) (bool, error) {
 			return true, nil
 		} else {
 			if baseTime.Add(dayRange).After(currentTime) == false {
-				pkg.GetLogger().Infoln("Skip", filepath.Base(videoFullPath), "Sub Download, because movie has sub and downloaded or aired more than 3 months")
+				log_helper.GetLogger().Infoln("Skip", filepath.Base(videoFullPath), "Sub Download, because movie has sub and downloaded or aired more than 3 months")
 				return false, nil
 			}
 			if found == true {
-				pkg.GetLogger().Infoln("Skip", filepath.Base(videoFullPath), "Sub Download, because sub file found")
+				log_helper.GetLogger().Infoln("Skip", filepath.Base(videoFullPath), "Sub Download, because sub file found")
 				return false, nil
 			}
 

+ 40 - 36
internal/logic/series_helper/seriesHelper.go

@@ -2,11 +2,15 @@ package series_helper
 
 import (
 	"github.com/StalkR/imdb"
-	common2 "github.com/allanpk716/ChineseSubFinder/internal/common"
-	_interface2 "github.com/allanpk716/ChineseSubFinder/internal/interface"
-	ass2 "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/ass"
-	srt2 "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/srt"
+	"github.com/allanpk716/ChineseSubFinder/internal/common"
+	"github.com/allanpk716/ChineseSubFinder/internal/ifaces"
+	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/ass"
+	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/srt"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/decode"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/imdb_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/emby"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/series"
@@ -23,7 +27,7 @@ import (
 // ReadSeriesInfoFromDir 读取剧集的信息,只有那些 Eps 需要下载字幕的 NeedDlEpsKeyList
 func ReadSeriesInfoFromDir(seriesDir string, imdbInfo *imdb.Title) (*series.SeriesInfo, error) {
 
-	subParserHub := pkg.NewSubParserHub(ass2.NewParser(), srt2.NewParser())
+	subParserHub := sub_helper.NewSubParserHub(ass.NewParser(), srt.NewParser())
 
 	seriesInfo, err := getSeriesInfoFromDir(seriesDir, imdbInfo)
 	if err != nil {
@@ -35,7 +39,7 @@ func ReadSeriesInfoFromDir(seriesDir string, imdbInfo *imdb.Title) (*series.Seri
 		return nil, err
 	}
 	// 搜索所有的字幕
-	subFiles, err := pkg.SearchMatchedSubFile(seriesDir)
+	subFiles, err := sub_helper.SearchMatchedSubFile(seriesDir)
 	if err != nil {
 		return nil, err
 	}
@@ -46,19 +50,19 @@ func ReadSeriesInfoFromDir(seriesDir string, imdbInfo *imdb.Title) (*series.Seri
 		if subParserHub.IsSubHasChinese(subFile) == false {
 			continue
 		}
-		info, _, err := pkg.GetVideoInfoFromFileFullPath(subFile)
+		info, _, err := decode.GetVideoInfoFromFileFullPath(subFile)
 		if err != nil {
-			pkg.GetLogger().Errorln(err)
+			log_helper.GetLogger().Errorln(err)
 			continue
 		}
 		subParserFileInfo, err := subParserHub.DetermineFileTypeFromFile(subFile)
 		if err != nil {
-			pkg.GetLogger().Errorln(err)
+			log_helper.GetLogger().Errorln(err)
 			continue
 		}
 		if subParserFileInfo == nil {
 			// 说明这个字幕无法解析
-			pkg.GetLogger().Warnln("ReadSeriesInfoFromDir", seriesInfo.DirPath, "DetermineFileTypeFromFile is nil")
+			log_helper.GetLogger().Warnln("ReadSeriesInfoFromDir", seriesInfo.DirPath, "DetermineFileTypeFromFile is nil")
 			continue
 		}
 		epsKey := pkg.GetEpisodeKeyName(info.Season, info.Episode)
@@ -124,51 +128,51 @@ func SkipChineseSeries(seriesRootPath string, _reqParam ...types.ReqParam) (bool
 	if len(_reqParam) > 0 {
 		reqParam = _reqParam[0]
 	}
-	imdbInfo, err := pkg.GetImdbInfo4SeriesDir(seriesRootPath)
+	imdbInfo, err := decode.GetImdbInfo4SeriesDir(seriesRootPath)
 	if err != nil {
 		return false, nil, err
 	}
-	t, err := pkg.GetVideoInfoFromIMDB(imdbInfo.ImdbId, reqParam)
+	t, err := imdb_helper.GetVideoInfoFromIMDB(imdbInfo.ImdbId, reqParam)
 	if err != nil {
 		return false, nil, err
 	}
 	if len(t.Languages) > 0 && strings.ToLower(t.Languages[0]) == "chinese" {
-		pkg.GetLogger().Infoln("Skip", filepath.Base(seriesRootPath), "Sub Download, because series is Chinese")
+		log_helper.GetLogger().Infoln("Skip", filepath.Base(seriesRootPath), "Sub Download, because series is Chinese")
 		return true, t, nil
 	}
 	return false, t, nil
 }
 
 // OneSeriesDlSubInAllSite 一部连续剧在所有的网站下载相应的字幕
-func OneSeriesDlSubInAllSite(Suppliers []_interface2.ISupplier, seriesInfo *series.SeriesInfo, i int) []supplier.SubInfo {
+func OneSeriesDlSubInAllSite(Suppliers []ifaces.ISupplier, seriesInfo *series.SeriesInfo, i int) []supplier.SubInfo {
 	defer func() {
-		pkg.GetLogger().Infoln("DlSub End", seriesInfo.DirPath)
+		log_helper.GetLogger().Infoln("DlSub End", seriesInfo.DirPath)
 	}()
-	pkg.GetLogger().Infoln("DlSub Start", seriesInfo.DirPath)
-	pkg.GetLogger().Debugln(seriesInfo.Name, "IMDB ID:", seriesInfo.ImdbId, "NeedDownloadSubs:", len(seriesInfo.NeedDlEpsKeyList))
+	log_helper.GetLogger().Infoln("DlSub Start", seriesInfo.DirPath)
+	log_helper.GetLogger().Debugln(seriesInfo.Name, "IMDB ID:", seriesInfo.ImdbId, "NeedDownloadSubs:", len(seriesInfo.NeedDlEpsKeyList))
 	var outSUbInfos = make([]supplier.SubInfo, 0)
 	if len(seriesInfo.NeedDlEpsKeyList) < 1 {
 		return outSUbInfos
 	}
 	for key, _ := range seriesInfo.NeedDlEpsKeyList {
-		pkg.GetLogger().Debugln(key)
+		log_helper.GetLogger().Debugln(key)
 	}
 	// 同时进行查询
 	subInfosChannel := make(chan []supplier.SubInfo)
-	for _, supplier := range Suppliers {
-		supplier := supplier
+	for _, oneSupplier := range Suppliers {
+		nowSupplier := oneSupplier
 		go func() {
 			defer func() {
-				pkg.GetLogger().Infoln(i, supplier.GetSupplierName(), "End...")
+				log_helper.GetLogger().Infoln(i, nowSupplier.GetSupplierName(), "End...")
 			}()
-			pkg.GetLogger().Infoln(i, supplier.GetSupplierName(), "Start...")
+			log_helper.GetLogger().Infoln(i, nowSupplier.GetSupplierName(), "Start...")
 			// 一次性把这一部连续剧的所有字幕下载完
-			subInfos, err := supplier.GetSubListFromFile4Series(seriesInfo)
+			subInfos, err := nowSupplier.GetSubListFromFile4Series(seriesInfo)
 			if err != nil {
-				pkg.GetLogger().Errorln(supplier.GetSupplierName(), "GetSubListFromFile4Series", err)
+				log_helper.GetLogger().Errorln(nowSupplier.GetSupplierName(), "GetSubListFromFile4Series", err)
 			}
 			// 把后缀名给改好
-			pkg.ChangeVideoExt2SubExt(subInfos)
+			sub_helper.ChangeVideoExt2SubExt(subInfos)
 
 			subInfosChannel <- subInfos
 		}()
@@ -195,7 +199,7 @@ func GetSeriesList(dir string) ([]string, error) {
 		if curFile.IsDir() == false {
 
 			// 如果发现有 tvshow.nfo 文件,那么就任务这个目录就是剧集的目录
-			if strings.ToLower(curFile.Name()) == pkg.MetadateTVNfo {
+			if strings.ToLower(curFile.Name()) == decode.MetadateTVNfo {
 				seriesDirList = make([]string, 0)
 				seriesDirList = append(seriesDirList, dir)
 				return seriesDirList, nil
@@ -215,7 +219,7 @@ func whichSeasonEpsNeedDownloadSub(seriesInfo *series.SeriesInfo) (map[string]se
 	var needDlSeasonList = make(map[int]int, 0)
 	currentTime := time.Now()
 	// 3个月
-	dayRange, _ := time.ParseDuration(common2.DownloadSubDuring3Months)
+	dayRange, _ := time.ParseDuration(common.DownloadSubDuring3Months)
 	for _, epsInfo := range seriesInfo.EpList {
 		// 如果没有字幕,则加入下载列表
 		// 如果每一集的播出时间能够读取到,那么就以这个完后推算 3个月
@@ -225,7 +229,7 @@ func whichSeasonEpsNeedDownloadSub(seriesInfo *series.SeriesInfo) (map[string]se
 		if epsInfo.AiredTime != "" {
 			baseTime, err = now.Parse(epsInfo.AiredTime)
 			if err != nil {
-				pkg.GetLogger().Errorln("SeriesInfo parse AiredTime", err)
+				log_helper.GetLogger().Errorln("SeriesInfo parse AiredTime", err)
 				baseTime = epsInfo.ModifyTime
 			}
 		} else {
@@ -239,9 +243,9 @@ func whichSeasonEpsNeedDownloadSub(seriesInfo *series.SeriesInfo) (map[string]se
 			needDlSeasonList[epsInfo.Season] = epsInfo.Season
 		} else {
 			if len(epsInfo.SubAlreadyDownloadedList) > 0 {
-				pkg.GetLogger().Infoln("Skip because find sub file and downloaded or aired over 3 months,", epsInfo.Title, epsInfo.Season, epsInfo.Episode)
+				log_helper.GetLogger().Infoln("Skip because find sub file and downloaded or aired over 3 months,", epsInfo.Title, epsInfo.Season, epsInfo.Episode)
 			} else if baseTime.Add(dayRange).After(currentTime) == false {
-				pkg.GetLogger().Infoln("Skip because 3 months pass,", epsInfo.Title, epsInfo.Season, epsInfo.Episode)
+				log_helper.GetLogger().Infoln("Skip because 3 months pass,", epsInfo.Title, epsInfo.Season, epsInfo.Episode)
 			}
 		}
 	}
@@ -251,7 +255,7 @@ func whichSeasonEpsNeedDownloadSub(seriesInfo *series.SeriesInfo) (map[string]se
 func getSeriesInfoFromDir(seriesDir string, imdbInfo *imdb.Title) (*series.SeriesInfo, error) {
 	seriesInfo := series.SeriesInfo{}
 	// 只考虑 IMDB 去查询,文件名目前发现可能会跟电影重复,导致很麻烦,本来也有前置要求要削刮器处理的
-	videoInfo, err := pkg.GetImdbInfo4SeriesDir(seriesDir)
+	videoInfo, err := decode.GetImdbInfo4SeriesDir(seriesDir)
 	if err != nil {
 		return nil, err
 	}
@@ -268,7 +272,7 @@ func getSeriesInfoFromDir(seriesDir string, imdbInfo *imdb.Title) (*series.Serie
 		if err != nil {
 			// 不是必须的
 			seriesInfo.Year = 0
-			pkg.GetLogger().Warnln("ReadSeriesInfoFromDir.GetImdbInfo4SeriesDir.strconv.Atoi", err)
+			log_helper.GetLogger().Warnln("ReadSeriesInfoFromDir.GetImdbInfo4SeriesDir.strconv.Atoi", err)
 		} else {
 			seriesInfo.Year = iYear
 		}
@@ -282,14 +286,14 @@ func getSeriesInfoFromDir(seriesDir string, imdbInfo *imdb.Title) (*series.Serie
 
 func getEpsInfoAndSubDic(videoFile string, EpisodeDict map[string]series.EpisodeInfo, SubDict map[string][]series.SubInfo) {
 	// 正常来说,一集只有一个格式的视频,也就是 S01E01 只有一个,如果有多个则会只保存第一个
-	info, modifyTime, err := pkg.GetVideoInfoFromFileFullPath(videoFile)
+	info, modifyTime, err := decode.GetVideoInfoFromFileFullPath(videoFile)
 	if err != nil {
-		pkg.GetLogger().Errorln("model.GetVideoInfoFromFileFullPath", err)
+		log_helper.GetLogger().Errorln("model.GetVideoInfoFromFileFullPath", err)
 		return
 	}
-	episodeInfo, err := pkg.GetImdbInfo4OneSeriesEpisode(videoFile)
+	episodeInfo, err := decode.GetImdbInfo4OneSeriesEpisode(videoFile)
 	if err != nil {
-		pkg.GetLogger().Errorln("model.GetImdbInfo4OneSeriesEpisode", err)
+		log_helper.GetLogger().Errorln("model.GetImdbInfo4OneSeriesEpisode", err)
 		return
 	}
 	epsKey := pkg.GetEpisodeKeyName(info.Season, info.Episode)

+ 6 - 6
internal/logic/sub_parser/ass/ass.go

@@ -1,8 +1,8 @@
 package ass
 
 import (
-	common2 "github.com/allanpk716/ChineseSubFinder/internal/common"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	"github.com/allanpk716/ChineseSubFinder/internal/common"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/language"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/subparser"
 	"io/ioutil"
 	"path/filepath"
@@ -25,14 +25,14 @@ func (p Parser) GetParserName() string {
 // DetermineFileTypeFromFile 确定字幕文件的类型,是双语字幕或者某一种语言等等信息
 func (p Parser) DetermineFileTypeFromFile(filePath string) (*subparser.FileInfo, error) {
 	nowExt := filepath.Ext(filePath)
-	if strings.ToLower(nowExt) != common2.SubExtASS && strings.ToLower(nowExt) != common2.SubExtSSA {
+	if strings.ToLower(nowExt) != common.SubExtASS && strings.ToLower(nowExt) != common.SubExtSSA {
 		return nil ,nil
 	}
 	fBytes, err := ioutil.ReadFile(filePath)
 	if err != nil {
 		return nil ,err
 	}
-	inBytes, err := pkg.ChangeFileCoding2UTF8(fBytes)
+	inBytes, err := language.ChangeFileCoding2UTF8(fBytes)
 	if err != nil {
 		return nil, err
 	}
@@ -119,10 +119,10 @@ func (p Parser) DetermineFileTypeFromBytes(inBytes []byte, nowExt string) (*subp
 	langDict = make(map[int]int)
 	var chLines = make([]string, 0)
 	for _, dialogue := range subFileInfo.Dialogues {
-		pkg.DetectSubLangAndStatistics(dialogue.Lines, langDict, &chLines)
+		language.DetectSubLangAndStatistics(dialogue.Lines, langDict, &chLines)
 	}
 	// 从统计出来的字典,找出 Top 1 或者 2 的出来,然后计算出是什么语言的字幕
-	detectLang := pkg.SubLangStatistics2SubLangType(float32(countLineFeed), float32(usefullDialogueCount), langDict, chLines)
+	detectLang := language.SubLangStatistics2SubLangType(float32(countLineFeed), float32(usefullDialogueCount), langDict, chLines)
 	subFileInfo.Lang = detectLang
 	subFileInfo.Data = inBytes
 	return &subFileInfo, nil

+ 6 - 6
internal/logic/sub_parser/srt/srt.go

@@ -1,8 +1,8 @@
 package srt
 
 import (
-	common2 "github.com/allanpk716/ChineseSubFinder/internal/common"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	"github.com/allanpk716/ChineseSubFinder/internal/common"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/language"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/subparser"
 	"io/ioutil"
 	"path/filepath"
@@ -25,14 +25,14 @@ func (p Parser) GetParserName() string {
 // DetermineFileTypeFromFile 确定字幕文件的类型,是双语字幕或者某一种语言等等信息
 func (p Parser) DetermineFileTypeFromFile(filePath string) (*subparser.FileInfo, error) {
 	nowExt := filepath.Ext(filePath)
-	if strings.ToLower(nowExt) != common2.SubExtSRT {
+	if strings.ToLower(nowExt) != common.SubExtSRT {
 		return nil ,nil
 	}
 	fBytes, err := ioutil.ReadFile(filePath)
 	if err != nil {
 		return nil ,err
 	}
-	inBytes, err := pkg.ChangeFileCoding2UTF8(fBytes)
+	inBytes, err := language.ChangeFileCoding2UTF8(fBytes)
 	if err != nil {
 		return nil, err
 	}
@@ -82,10 +82,10 @@ func (p Parser) DetermineFileTypeFromBytes(inBytes []byte, nowExt string) (*subp
 	langDict = make(map[int]int)
 	var chLines = make([]string, 0)
 	for _, dialogue := range subFileInfo.Dialogues {
-		pkg.DetectSubLangAndStatistics(dialogue.Lines, langDict, &chLines)
+		language.DetectSubLangAndStatistics(dialogue.Lines, langDict, &chLines)
 	}
 	// 从统计出来的字典,找出 Top 1 或者 2 的出来,然后计算出是什么语言的字幕
-	detectLang := pkg.SubLangStatistics2SubLangType(float32(countLineFeed), float32(len(matched)), langDict, chLines)
+	detectLang := language.SubLangStatistics2SubLangType(float32(countLineFeed), float32(len(matched)), langDict, chLines)
 	subFileInfo.Lang = detectLang
 	subFileInfo.Data = inBytes
 	return &subFileInfo, nil

+ 8 - 7
internal/logic/sub_supplier/shooter/shooter.go

@@ -3,8 +3,9 @@ package shooter
 import (
 	"crypto/md5"
 	"fmt"
-	common2 "github.com/allanpk716/ChineseSubFinder/internal/common"
+	"github.com/allanpk716/ChineseSubFinder/internal/common"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/series"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/supplier"
@@ -24,8 +25,8 @@ type Supplier struct {
 func NewSupplier(_reqParam ...types.ReqParam) *Supplier {
 
 	sup := Supplier{}
-	sup.log = pkg.GetLogger()
-	sup.topic = common2.DownloadSubsPerSite
+	sup.log = log_helper.GetLogger()
+	sup.topic = common.DownloadSubsPerSite
 	if len(_reqParam) > 0 {
 		sup.reqParam = _reqParam[0]
 		if sup.reqParam.Topic > 0 && sup.reqParam.Topic != sup.topic {
@@ -36,7 +37,7 @@ func NewSupplier(_reqParam ...types.ReqParam) *Supplier {
 }
 
 func (s Supplier) GetSupplierName() string {
-	return common2.SubSiteShooter
+	return common.SubSiteShooter
 }
 
 func (s Supplier) GetReqParam() types.ReqParam {
@@ -67,7 +68,7 @@ func (s Supplier) getSubListFromFile(filePath string) ([]supplier.SubInfo, error
 		return nil, err
 	}
 	if hash == "" {
-		return nil, common2.ShooterFileHashIsEmpty
+		return nil, common.ShooterFileHashIsEmpty
 	}
 
 	fileName := filepath.Base(filePath)
@@ -82,7 +83,7 @@ func (s Supplier) getSubListFromFile(filePath string) ([]supplier.SubInfo, error
 			"lang": qLan,
 		}).
 		SetResult(&jsonList).
-		Post(common2.SubShooterRootUrl)
+		Post(common.SubShooterRootUrl)
 	if err != nil {
 		return nil, err
 	}
@@ -129,7 +130,7 @@ func (s Supplier) computeFileHash(filePath string) (string, error) {
 	}
 	size := float64(stat.Size())
 	if size < 0xF000 {
-		return "", common2.VideoFileIsTooSmall
+		return "", common.VideoFileIsTooSmall
 	}
 	samplePositions := [4]int64{
 		4 * 1024,

+ 19 - 18
internal/logic/sub_supplier/subSupplierHub.go

@@ -1,10 +1,11 @@
 package sub_supplier
 
 import (
-	_interface2 "github.com/allanpk716/ChineseSubFinder/internal/interface"
-	movie_helper2 "github.com/allanpk716/ChineseSubFinder/internal/logic/movie_helper"
-	series_helper2 "github.com/allanpk716/ChineseSubFinder/internal/logic/series_helper"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	"github.com/allanpk716/ChineseSubFinder/internal/ifaces"
+	movieHelper "github.com/allanpk716/ChineseSubFinder/internal/logic/movie_helper"
+	seriesHelper "github.com/allanpk716/ChineseSubFinder/internal/logic/series_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/emby"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/series"
 	"github.com/sirupsen/logrus"
@@ -13,15 +14,15 @@ import (
 )
 
 type SubSupplierHub struct {
-	Suppliers []_interface2.ISupplier
+	Suppliers []ifaces.ISupplier
 
 	log *logrus.Logger
 }
 
-func NewSubSupplierHub(one _interface2.ISupplier,_inSupplier ..._interface2.ISupplier) *SubSupplierHub {
+func NewSubSupplierHub(one ifaces.ISupplier,_inSupplier ...ifaces.ISupplier) *SubSupplierHub {
 	s := SubSupplierHub{}
-	s.log = pkg.GetLogger()
-	s.Suppliers = make([]_interface2.ISupplier, 0)
+	s.log = log_helper.GetLogger()
+	s.Suppliers = make([]ifaces.ISupplier, 0)
 	s.Suppliers = append(s.Suppliers, one)
 	if len(_inSupplier) > 0 {
 		for _, supplier := range _inSupplier {
@@ -36,7 +37,7 @@ func NewSubSupplierHub(one _interface2.ISupplier,_inSupplier ..._interface2.ISup
 func (d SubSupplierHub) DownloadSub4Movie(videoFullPath string, index int) ([]string, error) {
 
 	// 跳过中文的电影,不是一定要跳过的
-	skip, err := movie_helper2.SkipChineseMovie(videoFullPath, d.Suppliers[0].GetReqParam())
+	skip, err := movieHelper.SkipChineseMovie(videoFullPath, d.Suppliers[0].GetReqParam())
 	if err != nil {
 		d.log.Warnln("SkipChineseMovie", videoFullPath, err)
 	}
@@ -44,16 +45,16 @@ func (d SubSupplierHub) DownloadSub4Movie(videoFullPath string, index int) ([]st
 		return nil, nil
 	}
 
-	needDlSub, err := movie_helper2.MovieNeedDlSub(videoFullPath)
+	needDlSub, err := movieHelper.MovieNeedDlSub(videoFullPath)
 	if err != nil {
 		return nil, errors.Newf("MovieNeedDlSub %v %v", videoFullPath , err)
 	}
 	if needDlSub == true {
 		// 需要下载字幕
 		// 下载所有字幕
-		subInfos := movie_helper2.OneMovieDlSubInAllSite(d.Suppliers, videoFullPath, index)
+		subInfos := movieHelper.OneMovieDlSubInAllSite(d.Suppliers, videoFullPath, index)
 		// 整理字幕,比如解压什么的
-		organizeSubFiles, err := pkg.OrganizeDlSubFiles(filepath.Base(videoFullPath), subInfos)
+		organizeSubFiles, err := sub_helper.OrganizeDlSubFiles(filepath.Base(videoFullPath), subInfos)
 		if err != nil {
 			return nil, errors.Newf("OrganizeDlSubFiles %v %v", videoFullPath , err)
 		}
@@ -73,7 +74,7 @@ func (d SubSupplierHub) DownloadSub4Movie(videoFullPath string, index int) ([]st
 func (d SubSupplierHub) DownloadSub4Series(seriesDirPath string, index int) (*series.SeriesInfo, map[string][]string, error) {
 
 	// 跳过中文的连续剧,不是一定要跳过的
-	skip, imdbInfo, err := series_helper2.SkipChineseSeries(seriesDirPath, d.Suppliers[0].GetReqParam())
+	skip, imdbInfo, err := seriesHelper.SkipChineseSeries(seriesDirPath, d.Suppliers[0].GetReqParam())
 	if err != nil {
 		d.log.Warnln("SkipChineseSeries", seriesDirPath, err)
 	}
@@ -81,7 +82,7 @@ func (d SubSupplierHub) DownloadSub4Series(seriesDirPath string, index int) (*se
 		return nil, nil, nil
 	}
 	// 读取本地的视频和字幕信息
-	seriesInfo, err := series_helper2.ReadSeriesInfoFromDir(seriesDirPath, imdbInfo)
+	seriesInfo, err := seriesHelper.ReadSeriesInfoFromDir(seriesDirPath, imdbInfo)
 	if err != nil {
 		return nil, nil, errors.Newf("ReadSeriesInfoFromDir %v %v", seriesDirPath , err)
 	}
@@ -96,7 +97,7 @@ func (d SubSupplierHub) DownloadSub4Series(seriesDirPath string, index int) (*se
 func (d SubSupplierHub) DownloadSub4SeriesFromEmby(seriesDirPath string, seriesList []emby.EmbyMixInfo, index int) (*series.SeriesInfo, map[string][]string, error) {
 
 	// 跳过中文的连续剧,不是一定要跳过的
-	skip, imdbInfo, err := series_helper2.SkipChineseSeries(seriesDirPath, d.Suppliers[0].GetReqParam())
+	skip, imdbInfo, err := seriesHelper.SkipChineseSeries(seriesDirPath, d.Suppliers[0].GetReqParam())
 	if err != nil {
 		d.log.Warnln("SkipChineseSeries", seriesDirPath, err)
 	}
@@ -104,7 +105,7 @@ func (d SubSupplierHub) DownloadSub4SeriesFromEmby(seriesDirPath string, seriesL
 		return nil, nil, nil
 	}
 	// 读取本地的视频和字幕信息
-	seriesInfo, err := series_helper2.ReadSeriesInfoFromEmby(seriesDirPath, imdbInfo, seriesList)
+	seriesInfo, err := seriesHelper.ReadSeriesInfoFromEmby(seriesDirPath, imdbInfo, seriesList)
 	if err != nil {
 		return nil, nil, errors.Newf("ReadSeriesInfoFromDir %v %v", seriesDirPath , err)
 	}
@@ -117,10 +118,10 @@ func (d SubSupplierHub) DownloadSub4SeriesFromEmby(seriesDirPath string, seriesL
 
 func (d SubSupplierHub) dlSubFromSeriesInfo(seriesDirPath string, index int, seriesInfo *series.SeriesInfo, err error) (map[string][]string, error) {
 	// 下载好的字幕
-	subInfos := series_helper2.OneSeriesDlSubInAllSite(d.Suppliers, seriesInfo, index)
+	subInfos := seriesHelper.OneSeriesDlSubInAllSite(d.Suppliers, seriesInfo, index)
 	// 整理字幕,比如解压什么的
 	// 每一集 SxEx - 对应解压整理后的字幕列表
-	organizeSubFiles, err := pkg.OrganizeDlSubFiles(filepath.Base(seriesDirPath), subInfos)
+	organizeSubFiles, err := sub_helper.OrganizeDlSubFiles(filepath.Base(seriesDirPath), subInfos)
 	if err != nil {
 		return nil, errors.Newf("OrganizeDlSubFiles %v %v", seriesDirPath, err)
 	}

+ 34 - 29
internal/logic/sub_supplier/subhd/subhd.go

@@ -5,8 +5,13 @@ import (
 	"fmt"
 	"github.com/PuerkitoBio/goquery"
 	"github.com/Tnze/go.num/v2/zh"
-	common2 "github.com/allanpk716/ChineseSubFinder/internal/common"
+	"github.com/allanpk716/ChineseSubFinder/internal/common"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/decode"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/notify_center"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/rod_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/series"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/supplier"
@@ -37,8 +42,8 @@ type Supplier struct {
 func NewSupplier(_reqParam ...types.ReqParam) *Supplier {
 
 	sup := Supplier{}
-	sup.log = pkg.GetLogger()
-	sup.topic = common2.DownloadSubsPerSite
+	sup.log = log_helper.GetLogger()
+	sup.topic = common.DownloadSubsPerSite
 	if len(_reqParam) > 0 {
 		sup.reqParam = _reqParam[0]
 		if sup.reqParam.Topic > 0 && sup.reqParam.Topic != sup.topic {
@@ -49,7 +54,7 @@ func NewSupplier(_reqParam ...types.ReqParam) *Supplier {
 }
 
 func (s Supplier) GetSupplierName() string {
-	return common2.SubSiteSubHd
+	return common.SubSiteSubHd
 }
 
 func (s Supplier) GetReqParam() types.ReqParam {
@@ -102,7 +107,7 @@ func (s Supplier) GetSubListFromFile4Series(seriesInfo *series.SeriesInfo) ([]su
 	// 下载字幕
 	var browser *rod.Browser
 	// 是用本地的 Browser 还是远程的,推荐是远程的
-	browser, err := pkg.NewBrowser(s.reqParam.HttpProxy)
+	browser, err := rod_helper.NewBrowser(s.reqParam.HttpProxy)
 	if err != nil {
 		return nil, err
 	}
@@ -113,7 +118,7 @@ func (s Supplier) GetSubListFromFile4Series(seriesInfo *series.SeriesInfo) ([]su
 			s.log.Errorln("subhd step2Ex", err)
 			continue
 		}
-		oneSubInfo := supplier.NewSubInfo(s.GetSupplierName(), int64(i), hdContent.Filename, types.ChineseSimple, pkg.AddBaseUrl(common2.SubSubHDRootUrl, item.Url), 0,
+		oneSubInfo := supplier.NewSubInfo(s.GetSupplierName(), int64(i), hdContent.Filename, types.ChineseSimple, pkg.AddBaseUrl(common.SubSubHDRootUrl, item.Url), 0,
 			0, hdContent.Ext, hdContent.Data)
 		oneSubInfo.Season = item.Season
 		oneSubInfo.Episode = item.Episode
@@ -135,14 +140,14 @@ func (s Supplier) getSubListFromFile4Movie(filePath string) ([]supplier.SubInfo,
 		如果找不到,再靠文件名提取影片名称去查找
 	*/
 	// 得到这个视频文件名中的信息
-	info, _, err := pkg.GetVideoInfoFromFileFullPath(filePath)
+	info, _, err := decode.GetVideoInfoFromFileFullPath(filePath)
 	if err != nil {
 		return nil, err
 	}
 	// 找到这个视频文件,尝试得到 IMDB ID
 	// 目前测试来看,加入 年 这个关键词去搜索,对 2020 年后的影片有利,因为网站有统一的详细页面了,而之前的,没有,会影响识别
 	// 所以,year >= 2020 年,则可以多加一个关键词(年)去搜索影片
-	imdbInfo, err := pkg.GetImdbInfo4Movie(filePath)
+	imdbInfo, err := decode.GetImdbInfo4Movie(filePath)
 	if err != nil {
 		// 允许的错误,跳过,继续进行文件名的搜索
 		s.log.Errorln("model.GetImdbInfo", err)
@@ -191,7 +196,7 @@ func (s Supplier) getSubListFromKeyword4Movie(keyword string) ([]supplier.SubInf
 
 	var browser *rod.Browser
 	// 是用本地的 Browser 还是远程的,推荐是远程的
-	browser, err = pkg.NewBrowser(s.reqParam.HttpProxy)
+	browser, err = rod_helper.NewBrowser(s.reqParam.HttpProxy)
 	if err != nil {
 		return nil, err
 	}
@@ -204,7 +209,7 @@ func (s Supplier) getSubListFromKeyword4Movie(keyword string) ([]supplier.SubInf
 			s.log.Errorln("step2Ex", err)
 			return nil, err
 		}
-		subInfos = append(subInfos, *supplier.NewSubInfo(s.GetSupplierName(), int64(i), hdContent.Filename, types.ChineseSimple, pkg.AddBaseUrl(common2.SubSubHDRootUrl, item.Url), 0, 0, hdContent.Ext, hdContent.Data))
+		subInfos = append(subInfos, *supplier.NewSubInfo(s.GetSupplierName(), int64(i), hdContent.Filename, types.ChineseSimple, pkg.AddBaseUrl(common.SubSubHDRootUrl, item.Url), 0, 0, hdContent.Ext, hdContent.Data))
 	}
 
 	return subInfos, nil
@@ -217,7 +222,7 @@ func (s Supplier) whichEpisodeNeedDownloadSub(seriesInfo *series.SeriesInfo, all
 	// 全季的字幕列表
 	var oneSeasonSubDict  = make(map[string][]HdListItem)
 	for _, subInfo := range allSubList {
-		_, season, episode, err := pkg.GetSeasonAndEpisodeFromSubFileName(subInfo.Title)
+		_, season, episode, err := decode.GetSeasonAndEpisodeFromSubFileName(subInfo.Title)
 		if err != nil {
 			s.log.Errorln("whichEpisodeNeedDownloadSub.GetVideoInfoFromFileFullPath", subInfo.Title, err)
 			continue
@@ -269,11 +274,11 @@ func (s Supplier) step0(keyword string) (string, error) {
 	var err error
 	defer func() {
 		if err != nil {
-			pkg.Notify.Add("subhd_step0", err.Error())
+			notify_center.Notify.Add("subhd_step0", err.Error())
 		}
 	}()
 
-	result, err := s.httpGet(fmt.Sprintf(common2.SubSubHDSearchUrl, url.QueryEscape(keyword)))
+	result, err := s.httpGet(fmt.Sprintf(common.SubSubHDSearchUrl, url.QueryEscape(keyword)))
 	if err != nil {
 		return "", err
 	}
@@ -281,9 +286,9 @@ func (s Supplier) step0(keyword string) (string, error) {
 	re := regexp.MustCompile(`共\s*(\d+)\s*条`)
 	matched := re.FindAllStringSubmatch(result, -1)
 	if len(matched) < 1 {
-		return "", common2.SubHDStep0SubCountElementNotFound
+		return "", common.SubHDStep0SubCountElementNotFound
 	}
-	subCount, err := pkg.GetNumber2int(matched[0][0])
+	subCount, err := decode.GetNumber2int(matched[0][0])
 	if err != nil {
 		return "", err
 	}
@@ -301,7 +306,7 @@ func (s Supplier) step0(keyword string) (string, error) {
 	if ok == true{
 
 		if len(imgSelection.Nodes) < 2 {
-			return "", common2.SubHDStep0ImgParentLessThan2
+			return "", common.SubHDStep0ImgParentLessThan2
 		}
 		step1Url := ""
 		if imgSelection.Nodes[0].Parent.Data == "a" {
@@ -322,7 +327,7 @@ func (s Supplier) step0(keyword string) (string, error) {
 			}
 		}
 		if step1Url == "" {
-			return "", common2.SubHDStep0HrefIsNull
+			return "", common.SubHDStep0HrefIsNull
 		}
 		return step1Url, nil
 		//imgName := filepath.Base(imgUrl)
@@ -334,7 +339,7 @@ func (s Supplier) step0(keyword string) (string, error) {
 		//	return "/d/" + strings.ReplaceAll(imgName, imgExt, ""), nil
 		//}
 	} else{
-		return "", common2.SubHDStep0HrefIsNull
+		return "", common.SubHDStep0HrefIsNull
 	}
 	//re = regexp.MustCompile(`<a\shref="(/d/[\w]+)">\s?<img`)
 	//matched = re.FindAllStringSubmatch(result, -1)
@@ -349,10 +354,10 @@ func (s Supplier) step1(detailPageUrl string, isMovieOrSeries bool) ([]HdListIte
 	var err error
 	defer func() {
 		if err != nil {
-			pkg.Notify.Add("subhd_step1", err.Error())
+			notify_center.Notify.Add("subhd_step1", err.Error())
 		}
 	}()
-	detailPageUrl = pkg.AddBaseUrl(common2.SubSubHDRootUrl, detailPageUrl)
+	detailPageUrl = pkg.AddBaseUrl(common.SubSubHDRootUrl, detailPageUrl)
 	result, err := s.httpGet(detailPageUrl)
 	if err != nil {
 		return nil, err
@@ -381,18 +386,18 @@ func (s Supplier) step1(detailPageUrl string, isMovieOrSeries bool) ([]HdListIte
 		title := strings.TrimSpace(tr.Find(oneSubTrTitleKeyword).Text())
 		// 字幕类型
 		insideSubType := tr.Find(oneSubLangAndTypeKeyword).Text()
-		if pkg.IsSubTypeWanted(insideSubType) == false {
+		if sub_helper.IsSubTypeWanted(insideSubType) == false {
 			return true
 		}
 		// 下载的次数
-		downCount, err := pkg.GetNumber2int(tr.Find(oneSubTrDownloadCountKeyword).Eq(1).Text())
+		downCount, err := decode.GetNumber2int(tr.Find(oneSubTrDownloadCountKeyword).Eq(1).Text())
 		if err != nil {
 			return true
 		}
 
 		listItem := HdListItem{}
 		listItem.Url = downUrl
-		listItem.BaseUrl = common2.SubSubHDRootUrl
+		listItem.BaseUrl = common.SubSubHDRootUrl
 		listItem.Title = title
 		listItem.DownCount = downCount
 
@@ -416,16 +421,16 @@ func (s Supplier) step2Ex(browser *rod.Browser, subDownloadPageUrl string) (*HdC
 	var err error
 	defer func() {
 		if err != nil {
-			pkg.Notify.Add("subhd_step2Ex", err.Error())
+			notify_center.Notify.Add("subhd_step2Ex", err.Error())
 		}
 	}()
-	subDownloadPageUrl = pkg.AddBaseUrl(common2.SubSubHDRootUrl, subDownloadPageUrl)
+	subDownloadPageUrl = pkg.AddBaseUrl(common.SubSubHDRootUrl, subDownloadPageUrl)
 	// 默认超时是 60s,如果是调试模式则是 5 min
-	tt := common2.HTMLTimeOut
+	tt := common.HTMLTimeOut
 	if s.reqParam.DebugMode == true {
-		tt = common2.OneVideoProcessTimeOut
+		tt = common.OneVideoProcessTimeOut
 	}
-	page, err := pkg.NewPageNavigate(browser, subDownloadPageUrl, tt, 5)
+	page, err := rod_helper.NewPageNavigate(browser, subDownloadPageUrl, tt, 5)
 	if err != nil {
 		return nil, err
 	}
@@ -454,7 +459,7 @@ func (s Supplier) step2Ex(browser *rod.Browser, subDownloadPageUrl string) (*HdC
 
 	if hasWaterWall == false && hasDownBtn == false {
 		// 都没有,则返回故障,无法下载
-		return nil, common2.SubHDStep2ExCannotFindDownloadBtn
+		return nil, common.SubHDStep2ExCannotFindDownloadBtn
 	}
 	// 下载字幕
 	content, err := s.downloadSubFile(browser, page, hasWaterWall, BtnElemenString)

+ 14 - 11
internal/logic/sub_supplier/xunlei/xunlei.go

@@ -3,8 +3,11 @@ package xunlei
 import (
 	"crypto/sha1"
 	"fmt"
-	common2 "github.com/allanpk716/ChineseSubFinder/internal/common"
+	"github.com/allanpk716/ChineseSubFinder/internal/common"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/language"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/series"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/supplier"
@@ -23,8 +26,8 @@ type Supplier struct {
 func NewSupplier(_reqParam ...types.ReqParam) *Supplier {
 
 	sup := Supplier{}
-	sup.log = pkg.GetLogger()
-	sup.topic = common2.DownloadSubsPerSite
+	sup.log = log_helper.GetLogger()
+	sup.topic = common.DownloadSubsPerSite
 	if len(_reqParam) > 0 {
 		sup.reqParam = _reqParam[0]
 		if sup.reqParam.Topic > 0 && sup.reqParam.Topic != sup.topic {
@@ -35,7 +38,7 @@ func NewSupplier(_reqParam ...types.ReqParam) *Supplier {
 }
 
 func (s Supplier) GetSupplierName() string {
-	return common2.SubSiteXunLei
+	return common.SubSiteXunLei
 }
 
 func (s Supplier) GetReqParam() types.ReqParam {
@@ -61,12 +64,12 @@ func (s Supplier) getSubListFromFile(filePath string) ([]supplier.SubInfo, error
 	var tmpXunLeiSubListChinese = make([]SublistXunLei, 0)
 	var outSubList []supplier.SubInfo
 	if len(cid) == 0 {
-		return outSubList, common2.XunLeiCIdIsEmpty
+		return outSubList, common.XunLeiCIdIsEmpty
 	}
 	httpClient := pkg.NewHttpClient(s.reqParam)
 	_, err = httpClient.R().
 		SetResult(&jsonList).
-		Get(fmt.Sprintf(common2.SubXunLeiRootUrl, cid))
+		Get(fmt.Sprintf(common.SubXunLeiRootUrl, cid))
 	if err != nil {
 		return outSubList, err
 	}
@@ -74,8 +77,8 @@ func (s Supplier) getSubListFromFile(filePath string) ([]supplier.SubInfo, error
 	for _, v := range jsonList.Sublist {
 		if len(v.Scid) > 0 && v.Scid != "" {
 			// 符合中文语言的先加入列表
-			tmpLang := pkg.LangConverter(v.Language)
-			if pkg.HasChineseLang(tmpLang) == true && pkg.IsSubTypeWanted(v.Sname) == true {
+			tmpLang := language.LangConverter(v.Language)
+			if language.HasChineseLang(tmpLang) == true && sub_helper.IsSubTypeWanted(v.Sname) == true {
 				tmpXunLeiSubListChinese = append(tmpXunLeiSubListChinese, v)
 			}
 		}
@@ -88,8 +91,8 @@ func (s Supplier) getSubListFromFile(filePath string) ([]supplier.SubInfo, error
 				break
 			}
 			if len(v.Scid) > 0 && v.Scid != "" {
-				tmpLang := pkg.LangConverter(v.Language)
-				if pkg.HasChineseLang(tmpLang) == false {
+				tmpLang := language.LangConverter(v.Language)
+				if language.HasChineseLang(tmpLang) == false {
 					tmpXunLeiSubListChinese = append(tmpXunLeiSubListChinese, v)
 				}
 			}
@@ -97,7 +100,7 @@ func (s Supplier) getSubListFromFile(filePath string) ([]supplier.SubInfo, error
 	}
 	// 再开始下载字幕
 	for i, v := range tmpXunLeiSubListChinese {
-		tmpLang := pkg.LangConverter(v.Language)
+		tmpLang := language.LangConverter(v.Language)
 		data, filename, err := pkg.DownFile(v.Surl)
 		if err != nil {
 			s.log.Error(err)

+ 35 - 30
internal/logic/sub_supplier/zimuku/zimuku.go

@@ -4,8 +4,13 @@ import (
 	"fmt"
 	"github.com/PuerkitoBio/goquery"
 	"github.com/Tnze/go.num/v2/zh"
-	common2 "github.com/allanpk716/ChineseSubFinder/internal/common"
+	"github.com/allanpk716/ChineseSubFinder/internal/common"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	"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/notify_center"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/series"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/supplier"
@@ -25,8 +30,8 @@ type Supplier struct {
 func NewSupplier(_reqParam ...types.ReqParam) *Supplier {
 
 	sup := Supplier{}
-	sup.log = pkg.GetLogger()
-	sup.topic = common2.DownloadSubsPerSite
+	sup.log = log_helper.GetLogger()
+	sup.topic = common.DownloadSubsPerSite
 	if len(_reqParam) > 0 {
 		sup.reqParam = _reqParam[0]
 		if sup.reqParam.Topic > 0 && sup.reqParam.Topic != sup.topic {
@@ -37,7 +42,7 @@ func NewSupplier(_reqParam ...types.ReqParam) *Supplier {
 }
 
 func (s Supplier) GetSupplierName() string {
-	return common2.SubSiteZiMuKu
+	return common.SubSiteZiMuKu
 }
 
 func (s Supplier) GetReqParam() types.ReqParam {
@@ -66,7 +71,7 @@ func (s Supplier) GetSubListFromFile4Series(seriesInfo *series.SeriesInfo) ([]su
 		if err != nil {
 			s.log.Errorln(keyword)
 			// 如果只是搜索不到,则继续换关键词
-			if err != common2.ZiMuKuSearchKeyWordStep0DetailPageUrlNotFound {
+			if err != common.ZiMuKuSearchKeyWordStep0DetailPageUrlNotFound {
 				return nil, err
 			}
 			keyword := seriesInfo.Name
@@ -114,14 +119,14 @@ func (s Supplier) getSubListFromMovie(fileFPath string) ([]supplier.SubInfo, err
 		如果找不到,再靠文件名提取影片名称去查找
 	*/
 	// 得到这个视频文件名中的信息
-	info, _, err := pkg.GetVideoInfoFromFileFullPath(fileFPath)
+	info, _, err := decode.GetVideoInfoFromFileFullPath(fileFPath)
 	if err != nil {
 		return nil, err
 	}
 	// 找到这个视频文件,尝试得到 IMDB ID
 	// 目前测试来看,加入 年 这个关键词去搜索,对 2020 年后的影片有利,因为网站有统一的详细页面了,而之前的,没有,会影响识别
 	// 所以,year >= 2020 年,则可以多加一个关键词(年)去搜索影片
-	imdbInfo, err := pkg.GetImdbInfo4Movie(fileFPath)
+	imdbInfo, err := decode.GetImdbInfo4Movie(fileFPath)
 	if err != nil {
 		// 允许的错误,跳过,继续进行文件名的搜索
 		s.log.Errorln("model.GetImdbInfo", err)
@@ -182,7 +187,7 @@ func (s Supplier) whichEpisodeNeedDownloadSub(seriesInfo *series.SeriesInfo, All
 	// 全季的字幕列表
 	var oneSeasonSubDict  = make(map[string]SubInfos)
 	for _, subInfo := range AllSeasonSubResult.SubInfos {
-		_, season, episode, err := pkg.GetSeasonAndEpisodeFromSubFileName(subInfo.Name)
+		_, season, episode, err := decode.GetSeasonAndEpisodeFromSubFileName(subInfo.Name)
 		if err != nil {
 			s.log.Errorln("whichEpisodeNeedDownloadSub.GetVideoInfoFromFileFullPath", subInfo.Name, err)
 			continue
@@ -244,8 +249,8 @@ func (s Supplier) whichSubInfoNeedDownload(subInfos SubInfos, err error) []suppl
 	// 首先过滤出中文的字幕,同时需要满足是支持的字幕
 	var tmpSubInfo = make([]SubInfo, 0)
 	for _, subInfo := range subInfos {
-		tmpLang := pkg.LangConverter(subInfo.Lang)
-		if pkg.HasChineseLang(tmpLang) == true && pkg.IsSubTypeWanted(subInfo.Ext) == true {
+		tmpLang := language.LangConverter(subInfo.Lang)
+		if language.HasChineseLang(tmpLang) == true && sub_helper.IsSubTypeWanted(subInfo.Ext) == true {
 			tmpSubInfo = append(tmpSubInfo, subInfo)
 		}
 	}
@@ -255,8 +260,8 @@ func (s Supplier) whichSubInfoNeedDownload(subInfos SubInfos, err error) []suppl
 			if len(tmpSubInfo) >= s.topic {
 				break
 			}
-			tmpLang := pkg.LangConverter(subInfo.Lang)
-			if pkg.HasChineseLang(tmpLang) == false {
+			tmpLang := language.LangConverter(subInfo.Lang)
+			if language.HasChineseLang(tmpLang) == false {
 				tmpSubInfo = append(tmpSubInfo, subInfo)
 			}
 		}
@@ -271,7 +276,7 @@ func (s Supplier) whichSubInfoNeedDownload(subInfos SubInfos, err error) []suppl
 		}
 		// 默认都是包含中文字幕的,然后具体使用的时候再进行区分
 
-		oneSubInfo := supplier.NewSubInfo(s.GetSupplierName(), int64(i), fileName, types.ChineseSimple, pkg.AddBaseUrl(common2.SubZiMuKuRootUrl, subInfo.SubDownloadPageUrl), 0,
+		oneSubInfo := supplier.NewSubInfo(s.GetSupplierName(), int64(i), fileName, types.ChineseSimple, pkg.AddBaseUrl(common.SubZiMuKuRootUrl, subInfo.SubDownloadPageUrl), 0,
 			0, filepath.Ext(fileName), data)
 
 		oneSubInfo.Season = subInfo.Season
@@ -288,7 +293,7 @@ func (s Supplier) step0(keyword string) (string, error) {
 	var err error
 	defer func() {
 		if err != nil {
-			pkg.Notify.Add("zimuku_step0", err.Error())
+			notify_center.Notify.Add("zimuku_step0", err.Error())
 		}
 	}()
 	httpClient := pkg.NewHttpClient(s.reqParam)
@@ -297,7 +302,7 @@ func (s Supplier) step0(keyword string) (string, error) {
 		SetQueryParams(map[string]string{
 			"q": keyword,
 		}).
-		Get(common2.SubZiMuKuSearchUrl)
+		Get(common.SubZiMuKuSearchUrl)
 	if err != nil {
 		return "", err
 	}
@@ -305,7 +310,7 @@ func (s Supplier) step0(keyword string) (string, error) {
 	re := regexp.MustCompile(`<p\s+class="tt\s+clearfix"><a\s+href="(/subs/[\w]+\.html)"\s+target="_blank"><b>(.*?)</b></a></p>`)
 	matched := re.FindAllStringSubmatch(resp.String(), -1)
 	if len(matched) < 1 {
-		return "", common2.ZiMuKuSearchKeyWordStep0DetailPageUrlNotFound
+		return "", common.ZiMuKuSearchKeyWordStep0DetailPageUrlNotFound
 	}
 	// 影片的详情界面 url
 	filmDetailPageUrl := matched[0][1]
@@ -317,10 +322,10 @@ func (s Supplier) step1(filmDetailPageUrl string) (SubResult, error) {
 	var err error
 	defer func() {
 		if err != nil {
-			pkg.Notify.Add("zimuku_step1", err.Error())
+			notify_center.Notify.Add("zimuku_step1", err.Error())
 		}
 	}()
-	filmDetailPageUrl = pkg.AddBaseUrl(common2.SubZiMuKuRootUrl, filmDetailPageUrl)
+	filmDetailPageUrl = pkg.AddBaseUrl(common.SubZiMuKuRootUrl, filmDetailPageUrl)
 	httpClient := pkg.NewHttpClient(s.reqParam)
 	resp, err := httpClient.R().
 		Get(filmDetailPageUrl)
@@ -375,7 +380,7 @@ func (s Supplier) step1(filmDetailPageUrl string) (SubResult, error) {
 		if !exists {
 			rate = ""
 		}
-		vote, err := pkg.GetNumber2Float(rate)
+		vote, err := decode.GetNumber2Float(rate)
 		if err != nil {
 			return
 		}
@@ -383,13 +388,13 @@ func (s Supplier) step1(filmDetailPageUrl string) (SubResult, error) {
 		downCountNub := 0
 		downCount := tr.Find("td").Eq(counterIndex).Text()
 		if strings.Contains(downCount, "万") {
-			fNumb, err := pkg.GetNumber2Float(downCount)
+			fNumb, err := decode.GetNumber2Float(downCount)
 			if err != nil {
 				return
 			}
 			downCountNub = int(fNumb * 10000)
 		} else {
-			downCountNub, err = pkg.GetNumber2int(downCount)
+			downCountNub, err = decode.GetNumber2int(downCount)
 			if err != nil {
 				return
 			}
@@ -418,10 +423,10 @@ func (s Supplier) step2(subInfo *SubInfo) error {
 	var err error
 	defer func() {
 		if err != nil {
-			pkg.Notify.Add("zimuku_step2", err.Error())
+			notify_center.Notify.Add("zimuku_step2", err.Error())
 		}
 	}()
-	detailUrl := pkg.AddBaseUrl(common2.SubZiMuKuRootUrl, subInfo.DetailUrl)
+	detailUrl := pkg.AddBaseUrl(common.SubZiMuKuRootUrl, subInfo.DetailUrl)
 	httpClient := pkg.NewHttpClient(s.reqParam)
 	resp, err := httpClient.R().
 		Get(detailUrl)
@@ -433,12 +438,12 @@ func (s Supplier) step2(subInfo *SubInfo) error {
 	matched := re.FindAllStringSubmatch(resp.String(), -1)
 	if matched == nil || len(matched) == 0 || len(matched[0]) == 0 {
 		s.log.Debug(detailUrl)
-		return common2.ZiMuKuDownloadUrlStep2NotFound
+		return common.ZiMuKuDownloadUrlStep2NotFound
 	}
 	if strings.Contains(matched[0][1], "://") {
 		subInfo.SubDownloadPageUrl = matched[0][1]
 	} else {
-		subInfo.SubDownloadPageUrl = fmt.Sprintf("%s%s", common2.SubZiMuKuRootUrl, matched[0][1])
+		subInfo.SubDownloadPageUrl = fmt.Sprintf("%s%s", common.SubZiMuKuRootUrl, matched[0][1])
 	}
 	return nil
 }
@@ -448,10 +453,10 @@ func (s Supplier) step3(subDownloadPageUrl string) (string, []byte, error) {
 	var err error
 	defer func() {
 		if err != nil {
-			pkg.Notify.Add("zimuku_step3", err.Error())
+			notify_center.Notify.Add("zimuku_step3", err.Error())
 		}
 	}()
-	subDownloadPageUrl = pkg.AddBaseUrl(common2.SubZiMuKuRootUrl, subDownloadPageUrl)
+	subDownloadPageUrl = pkg.AddBaseUrl(common.SubZiMuKuRootUrl, subDownloadPageUrl)
 	httpClient := pkg.NewHttpClient(s.reqParam)
 	resp, err := httpClient.R().
 		Get(subDownloadPageUrl)
@@ -462,14 +467,14 @@ func (s Supplier) step3(subDownloadPageUrl string) (string, []byte, error) {
 	matched := re.FindAllStringSubmatch(resp.String(), -1)
 	if matched == nil || len(matched) == 0 || len(matched[0]) == 0 {
 		s.log.Debug(subDownloadPageUrl)
-		return "", nil, common2.ZiMuKuDownloadUrlStep3NotFound
+		return "", nil, common.ZiMuKuDownloadUrlStep3NotFound
 	}
 	var filename string
 	var data []byte
 
 	s.reqParam.Referer = subDownloadPageUrl
 	for i := 0; i < len(matched); i++ {
-		data, filename, err = pkg.DownFile(pkg.AddBaseUrl(common2.SubZiMuKuRootUrl, matched[i][1]), s.reqParam)
+		data, filename, err = pkg.DownFile(pkg.AddBaseUrl(common.SubZiMuKuRootUrl, matched[i][1]), s.reqParam)
 		if err != nil {
 			s.log.Errorln("ZiMuKu step3 DownloadFile", err)
 			continue
@@ -477,7 +482,7 @@ func (s Supplier) step3(subDownloadPageUrl string) (string, []byte, error) {
 		return filename, data, nil
 	}
 	s.log.Debug(subDownloadPageUrl)
-	return "", nil, common2.ZiMuKuDownloadUrlStep3AllFailed
+	return "", nil, common.ZiMuKuDownloadUrlStep3AllFailed
 }
 
 type SubResult struct {

+ 1 - 1
internal/pkg/unarchiveFile.go → internal/pkg/archive_helper/unarchiveFile.go

@@ -1,4 +1,4 @@
-package pkg
+package archive_helper
 
 import (
 	"archive/zip"

+ 1 - 1
internal/pkg/unarchiveFile_test.go → internal/pkg/archive_helper/unarchiveFile_test.go

@@ -1,4 +1,4 @@
-package pkg
+package archive_helper
 
 import (
 	"testing"

+ 28 - 6
internal/pkg/config.go

@@ -1,13 +1,29 @@
 package pkg
 
 import (
+	"errors"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	"github.com/spf13/viper"
+	"sync"
 )
-import "errors"
 
-// InitConfigure 初始化配置文件实例
-func InitConfigure() (*viper.Viper, error) {
+// GetConfig 统一获取配置的接口
+func GetConfig() *types.Config {
+	configOnce.Do(func() {
+		configViper, err := initConfigure()
+		if err != nil {
+			panic("GetConfig - initConfigure " + err.Error())
+		}
+		config, err = readConfig(configViper)
+		if err != nil {
+			panic("GetConfig - readConfig " + err.Error())
+		}
+	})
+	return config
+}
+
+// initConfigure 初始化配置文件实例
+func initConfigure() (*viper.Viper, error) {
 	v := viper.New()
 	v.SetConfigName("config") // 设置文件名称(无后缀)
 	v.SetConfigType("yaml")   // 设置后缀名 {"1.6以后的版本可以不设置该后缀"}
@@ -20,12 +36,18 @@ func InitConfigure() (*viper.Viper, error) {
 
 	return v, nil
 }
-// ReadConfig 读取配置文件
-func ReadConfig(viper *viper.Viper) (*types.Config, error) {
+
+// readConfig 读取配置文件
+func readConfig(viper *viper.Viper) (*types.Config, error) {
 	conf := &types.Config{}
 	err := viper.Unmarshal(conf)
 	if err != nil {
 		return nil, err
 	}
 	return conf, nil
-}
+}
+
+var(
+	config *types.Config
+	configOnce sync.Once
+)

+ 0 - 28
internal/pkg/deal_sub.go

@@ -1,28 +0,0 @@
-package pkg
-
-import (
-	"github.com/allanpk716/ChineseSubFinder/internal/types/supplier"
-	"path/filepath"
-	"strconv"
-)
-
-// GetFrontNameAndOrgName 返回的名称包含,那个网站下载的,这个网站中排名第几,文件名
-func GetFrontNameAndOrgName(info *supplier.SubInfo) string {
-
-	infoName := ""
-	path, err := GetVideoInfoFromFileName(info.Name)
-	if err != nil {
-		GetLogger().Warnln("", err)
-		infoName = info.Name
-	} else {
-		infoName = path.Title + "_S" + strconv.Itoa(path.Season) + "E" + strconv.Itoa(path.Episode) + filepath.Ext(info.Name)
-	}
-	info.Name = infoName
-
-	return "[" + info.FromWhere + "]_" + strconv.FormatInt(info.TopN,10) + "_" + infoName
-}
-
-// AddFrontName 添加文件的前缀
-func AddFrontName(info supplier.SubInfo, orgName string) string {
-	return "[" + info.FromWhere + "]_" + strconv.FormatInt(info.TopN,10) + "_" + orgName
-}

+ 10 - 9
internal/pkg/decode.go → internal/pkg/decode/decode.go

@@ -1,8 +1,9 @@
-package pkg
+package decode
 
 import (
 	"errors"
-	common2 "github.com/allanpk716/ChineseSubFinder/internal/common"
+	"github.com/allanpk716/ChineseSubFinder/internal/common"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	"github.com/beevik/etree"
 	PTN "github.com/middelink/go-parse-torrent-name"
@@ -34,7 +35,7 @@ func getImdbAndYearMovieXml(movieFilePath string) (types.VideoIMDBInfo, error) {
 	if videoInfo.ImdbId != "" {
 		return videoInfo, nil
 	}
-	return videoInfo, common2.CanNotFindIMDBID
+	return videoInfo, common.CanNotFindIMDBID
 }
 
 func getImdbAndYearNfo(nfoFilePath string, rootKey string) (types.VideoIMDBInfo, error) {
@@ -86,7 +87,7 @@ func getImdbAndYearNfo(nfoFilePath string, rootKey string) (types.VideoIMDBInfo,
 	if imdbInfo.ImdbId != "" {
 		return imdbInfo, nil
 	}
-	return imdbInfo, common2.CanNotFindIMDBID
+	return imdbInfo, common.CanNotFindIMDBID
 }
 
 func GetImdbInfo4Movie(movieFileFullPath string) (types.VideoIMDBInfo, error) {
@@ -129,7 +130,7 @@ func GetImdbInfo4Movie(movieFileFullPath string) (types.VideoIMDBInfo, error) {
 	}
 	// 根据找到的开始解析
 	if movieNameNfoFPath == "" && movieXmlFPath == "" && nfoFilePath == "" {
-		return imdbInfo, common2.NoMetadataFile
+		return imdbInfo, common.NoMetadataFile
 	}
 	// 优先分析 movieName.nfo 文件
 	if movieNameNfoFPath != "" {
@@ -144,7 +145,7 @@ func GetImdbInfo4Movie(movieFileFullPath string) (types.VideoIMDBInfo, error) {
 	if movieXmlFPath != "" {
 		imdbInfo, err = getImdbAndYearMovieXml(movieXmlFPath)
 		if err != nil {
-			GetLogger().Errorln("getImdbAndYearMovieXml error, move on:", err)
+			log_helper.GetLogger().Errorln("getImdbAndYearMovieXml error, move on:", err)
 		} else {
 			return imdbInfo, nil
 		}
@@ -158,7 +159,7 @@ func GetImdbInfo4Movie(movieFileFullPath string) (types.VideoIMDBInfo, error) {
 		}
 	}
 
-	return imdbInfo, common2.CanNotFindIMDBID
+	return imdbInfo, common.CanNotFindIMDBID
 }
 
 func GetImdbInfo4SeriesDir(seriesDir string) (types.VideoIMDBInfo, error) {
@@ -187,7 +188,7 @@ func GetImdbInfo4SeriesDir(seriesDir string) (types.VideoIMDBInfo, error) {
 	}
 	// 根据找到的开始解析
 	if nfoFilePath == "" {
-		return imdbInfo, common2.NoMetadataFile
+		return imdbInfo, common.NoMetadataFile
 	}
 	imdbInfo, err = getImdbAndYearNfo(nfoFilePath, "tvshow")
 	if err != nil {
@@ -226,7 +227,7 @@ func GetImdbInfo4OneSeriesEpisode(oneEpFPath string) (types.VideoIMDBInfo, error
 	if imdbInfo.ReleaseDate != "" {
 		return imdbInfo, nil
 	}
-	return imdbInfo, common2.CanNotFindEpAiredTime
+	return imdbInfo, common.CanNotFindEpAiredTime
 }
 
 // GetVideoInfoFromFileName 从文件名推断文件信息

+ 1 - 1
internal/pkg/decode_test.go → internal/pkg/decode/decode_test.go

@@ -1,4 +1,4 @@
-package pkg
+package decode
 
 import (
 	"testing"

+ 14 - 13
internal/pkg/emby.go → internal/pkg/emby_helper/emby.go

@@ -1,8 +1,9 @@
-package pkg
+package emby_helper
 
 import (
 	"fmt"
-	common2 "github.com/allanpk716/ChineseSubFinder/internal/common"
+	"github.com/allanpk716/ChineseSubFinder/internal/common"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/emby"
 	"github.com/go-resty/resty/v2"
 	"github.com/panjf2000/ants/v2"
@@ -20,10 +21,10 @@ type EmbyApi struct {
 func NewEmbyHelper(embyConfig emby.EmbyConfig) *EmbyApi {
 	em := EmbyApi{}
 	em.embyConfig = embyConfig
-	if em.embyConfig.LimitCount < common2.EmbyApiGetItemsLimitMin ||
-		em.embyConfig.LimitCount > common2.EmbyApiGetItemsLimitMax {
+	if em.embyConfig.LimitCount < common.EmbyApiGetItemsLimitMin ||
+		em.embyConfig.LimitCount > common.EmbyApiGetItemsLimitMax {
 
-		em.embyConfig.LimitCount = common2.EmbyApiGetItemsLimitMin
+		em.embyConfig.LimitCount = common.EmbyApiGetItemsLimitMin
 	}
 	em.threads = 6
 	em.timeOut = 5 * time.Second
@@ -62,13 +63,13 @@ func (em EmbyApi) RefreshRecentlyVideoInfo() error {
 		select {
 		case err = <- done:
 			if err != nil {
-				GetLogger().Errorln("RefreshRecentlyVideoInfo.NewPoolWithFunc got error", err)
+				log_helper.GetLogger().Errorln("RefreshRecentlyVideoInfo.NewPoolWithFunc got error", err)
 			}
 			return
 		case p := <- panicChan:
-			GetLogger().Errorln("RefreshRecentlyVideoInfo.NewPoolWithFunc got panic", p)
+			log_helper.GetLogger().Errorln("RefreshRecentlyVideoInfo.NewPoolWithFunc got panic", p)
 		case <-ctx.Done():
-			GetLogger().Errorln("RefreshRecentlyVideoInfo.NewPoolWithFunc got time out", ctx.Err())
+			log_helper.GetLogger().Errorln("RefreshRecentlyVideoInfo.NewPoolWithFunc got time out", ctx.Err())
 			return
 		}
 	})
@@ -81,7 +82,7 @@ func (em EmbyApi) RefreshRecentlyVideoInfo() error {
 		wg.Add(1)
 		err = p.Invoke(InputData{Id: item.Id, Wg: &wg})
 		if err != nil {
-			GetLogger().Errorln("RefreshRecentlyVideoInfo ants.Invoke", err)
+			log_helper.GetLogger().Errorln("RefreshRecentlyVideoInfo ants.Invoke", err)
 		}
 	}
 	wg.Wait()
@@ -105,7 +106,7 @@ func (em EmbyApi) GetRecentlyItems() (emby.EmbyRecentlyItems, error) {
 			"SortBy":           "DateCreated",
 		}).
 		SetResult(&recItems).
-		Get(em.embyConfig.Url + "/emby/Items")
+		Get(em.embyConfig.Url + "/emby_helper/Items")
 	if err != nil {
 		return emby.EmbyRecentlyItems{}, err
 	}
@@ -123,7 +124,7 @@ func (em EmbyApi) GetItemAncestors(id string) ([]emby.EmbyItemsAncestors, error)
 			"api_key":          em.embyConfig.ApiKey,
 		}).
 		SetResult(&recItems).
-		Get(em.embyConfig.Url + "/emby/Items/" + id + "/Ancestors")
+		Get(em.embyConfig.Url + "/emby_helper/Items/" + id + "/Ancestors")
 	if err != nil {
 		return nil, err
 	}
@@ -141,7 +142,7 @@ func (em EmbyApi) GetItemVideoInfo(id string) (emby.EmbyVideoInfo, error) {
 			"api_key":          em.embyConfig.ApiKey,
 		}).
 		SetResult(&recItem).
-		Get(em.embyConfig.Url + "/emby/LiveTv/Programs/" + id)
+		Get(em.embyConfig.Url + "/emby_helper/LiveTv/Programs/" + id)
 	if err != nil {
 		return emby.EmbyVideoInfo{}, err
 	}
@@ -156,7 +157,7 @@ func (em EmbyApi) UpdateVideoSubList(id string) error {
 		SetQueryParams(map[string]string{
 			"api_key":          em.embyConfig.ApiKey,
 		}).
-		Post(em.embyConfig.Url + "/emby/Items/" + id + "/Refresh")
+		Post(em.embyConfig.Url + "/emby_helper/Items/" + id + "/Refresh")
 	if err != nil {
 		return err
 	}

+ 7 - 22
internal/pkg/emby_test.go → internal/pkg/emby_helper/emby_test.go

@@ -1,24 +1,13 @@
-package pkg
+package emby_helper
 
 import (
-	"github.com/allanpk716/ChineseSubFinder/internal/types"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
 	"testing"
 )
 
-func init() {
-	configViper, err := InitConfigure()
-	if err != nil {
-		return
-	}
-	config, err = ReadConfig(configViper)
-	if err != nil {
-		return
-	}
-}
-
 func TestEmbyHelper_GetRecentlyItems(t *testing.T) {
 
-	em := NewEmbyHelper(config.EmbyConfig)
+	em := NewEmbyHelper(pkg.GetConfig().EmbyConfig)
 	items, err := em.GetRecentlyItems()
 	if err != nil {
 		t.Fatal(err)
@@ -28,7 +17,7 @@ func TestEmbyHelper_GetRecentlyItems(t *testing.T) {
 }
 
 func TestEmbyHelper_GetItemsAncestors(t *testing.T) {
-	em := NewEmbyHelper(config.EmbyConfig)
+	em := NewEmbyHelper(pkg.GetConfig().EmbyConfig)
 	items, err := em.GetItemAncestors("96564")
 	if err != nil {
 		t.Fatal(err)
@@ -42,7 +31,7 @@ func TestEmbyHelper_GetItemsAncestors(t *testing.T) {
 }
 
 func TestEmbyHelper_GetItemVideoInfo(t *testing.T) {
-	em := NewEmbyHelper(config.EmbyConfig)
+	em := NewEmbyHelper(pkg.GetConfig().EmbyConfig)
 	// 95813 -- 命运夜
 	// 96564 -- The Bad Batch - S01E11
 	videoInfo, err := em.GetItemVideoInfo("95813")
@@ -54,15 +43,11 @@ func TestEmbyHelper_GetItemVideoInfo(t *testing.T) {
 }
 
 func TestEmbyHelper_UpdateVideoSubList(t *testing.T) {
-	em := NewEmbyHelper(config.EmbyConfig)
+	em := NewEmbyHelper(pkg.GetConfig().EmbyConfig)
 	// 95813 -- 命运夜
 	// 96564 -- The Bad Batch - S01E11
 	err := em.UpdateVideoSubList("95813")
 	if err != nil {
 		t.Fatal(err)
 	}
-}
-
-var (
-	config *types.Config
-)
+}

+ 5 - 3
internal/pkg/imdb.go → internal/pkg/imdb_helper/imdb.go

@@ -1,7 +1,9 @@
-package pkg
+package imdb_helper
 
 import (
 	"github.com/StalkR/imdb"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/notify_center"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
 )
 
@@ -11,9 +13,9 @@ func GetVideoInfoFromIMDB(imdbID string, _reqParam ...types.ReqParam) (*imdb.Tit
 	if len(_reqParam) > 0 {
 		reqParam = _reqParam[0]
 	}
-	t, err := imdb.NewTitle(NewHttpClient(reqParam).GetClient(), imdbID)
+	t, err := imdb.NewTitle(pkg.NewHttpClient(reqParam).GetClient(), imdbID)
 	if err != nil {
-		Notify.Add("imdb model - imdb.NewTitle :", err.Error())
+		notify_center.Notify.Add("imdb model - imdb.NewTitle :", err.Error())
 		return nil, err
 	}
 

+ 1 - 1
internal/pkg/imdb_test.go → internal/pkg/imdb_helper/imdb_test.go

@@ -1,4 +1,4 @@
-package pkg
+package imdb_helper
 
 import "testing"
 

+ 5 - 5
internal/pkg/language.go → internal/pkg/language/language.go

@@ -1,13 +1,13 @@
-package pkg
+package language
 
 import (
 	"github.com/abadojack/whatlanggo"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/charset"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	"github.com/axgle/mahonia"
 	"github.com/go-creed/sat"
-	chardet2 "github.com/nzlov/chardet"
-	//"github.com/qiniu/iconv"
+	nzlov "github.com/nzlov/chardet"
 	"github.com/saintfish/chardet"
 	"strings"
 )
@@ -344,7 +344,7 @@ func IsChineseSimpleOrTraditional(inputFileName string, orgLang types.Language)
 func ConvertToString(src string, srcCode string, tagCode string) string {
 	defer func() {
 		if err := recover(); err != nil {
-			GetLogger().Errorln("ConvertToString panic:", err)
+			log_helper.GetLogger().Errorln("ConvertToString panic:", err)
 		}
 	}()
 	srcCoder := mahonia.NewDecoder(srcCode)
@@ -365,7 +365,7 @@ func ChangeFileCoding2UTF8(inBytes []byte) ([]byte, error) {
 		return nil, err
 	}
 	if best.Confidence < 90 {
-		detectBest := chardet2.Mostlike(inBytes)
+		detectBest := nzlov.Mostlike(inBytes)
 		utf8String, err = charset.ToUTF8(charset.Charset(detectBest), string(inBytes))
 	} else {
 		utf8String, err = charset.ToUTF8(charset.Charset(best.Charset), string(inBytes))

+ 3 - 3
internal/pkg/loghelper.go → internal/pkg/log_helper/loghelper.go

@@ -1,4 +1,4 @@
-package pkg
+package log_helper
 
 import (
 	rotatelogs "github.com/lestrrat-go/file-rotatelogs"
@@ -41,10 +41,10 @@ func NewLogHelper(appName string, level logrus.Level, maxAge time.Duration, rota
 	return Logger
 }
 func GetLogger() *logrus.Logger {
-	once.Do(func() {
+	logOnce.Do(func() {
 		logger = NewLogHelper("ChineseSubFinder", logrus.DebugLevel, time.Duration(7*24)*time.Hour, time.Duration(24)*time.Hour)
 	})
 	return logger
 }
 var logger *logrus.Logger
-var once sync.Once
+var logOnce sync.Once

+ 3 - 2
internal/pkg/NotifyCenter.go → internal/pkg/notify_center/NotifyCenter.go

@@ -1,6 +1,7 @@
-package pkg
+package notify_center
 
 import (
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
 	"github.com/go-resty/resty/v2"
 	"net/url"
 	"sync"
@@ -35,7 +36,7 @@ func (n *NotifyCenter) Send() {
 	for s, s2 := range n.infos {
 		_, err := client.R().Get(n.webhookUrl + s + "/" + url.QueryEscape(s2))
 		if err != nil {
-			GetLogger().Errorln("NewNotifyCenter.Send", err)
+			log_helper.GetLogger().Errorln("NewNotifyCenter.Send", err)
 			return
 		}
 	}

+ 3 - 11
internal/pkg/NotifyCenter_test.go → internal/pkg/notify_center/NotifyCenter_test.go

@@ -1,21 +1,13 @@
-package pkg
+package notify_center
 
 import (
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
 	"testing"
 )
 
 func TestNewNotifyCenter(t *testing.T) {
 
-	configViper, err := InitConfigure()
-	if err != nil {
-		t.Fatal(err)
-		return
-	}
-	config, err := ReadConfig(configViper)
-	if err != nil {
-		t.Fatal(err)
-		return
-	}
+	config := pkg.GetConfig()
 	center := NewNotifyCenter(config.WhenSubSupplierInvalidWebHook)
 	center.Add("groupName", "Info asd 哈哈")
 	center.Send()

+ 5 - 3
internal/pkg/pass_water_wall.go → internal/pkg/pass_water_wall/pass_water_wall.go

@@ -1,8 +1,10 @@
-package pkg
+package pass_water_wall
 
 import (
 	"bytes"
 	"fmt"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/rod_helper"
 	"github.com/nfnt/resize"
 	"image/jpeg"
 	"math"
@@ -14,7 +16,7 @@ import (
 func SimulationTest() {
 	// 具体的应用见 subhd 的解析器
 	// 感谢 https://www.bigs3.com/article/gorod-crack-slider-captcha/
-	page, err := NewBrowserLoadPage("https://007.qq.com/online.html", "", 10*time.Second, 5)
+	page, err := rod_helper.NewBrowserLoadPage("https://007.qq.com/online.html", "", 10*time.Second, 5)
 	if err != nil {
 		println(err.Error())
 		return
@@ -37,7 +39,7 @@ func SimulationTest() {
 	shadowbg := iframe.MustElement("#slideBg").MustResource()
 	//取得原始圖像
 	src := iframe.MustElement("#slideBg").MustProperty("src")
-	fullbg, fileName, err := DownFile(strings.Replace(src.String(), "img_index=1", "img_index=0", 1))
+	fullbg, fileName, err := pkg.DownFile(strings.Replace(src.String(), "img_index=1", "img_index=0", 1))
 	if err != nil {
 		return
 	}

+ 1 - 1
internal/pkg/pass_water_wall_test.go → internal/pkg/pass_water_wall/pass_water_wall_test.go

@@ -1,4 +1,4 @@
-package pkg
+package pass_water_wall
 
 import (
 	"testing"

+ 1 - 1
internal/pkg/rodHelper.go → internal/pkg/rod_helper/rodHelper.go

@@ -1,4 +1,4 @@
-package pkg
+package rod_helper
 
 import (
 	"context"

+ 1 - 1
internal/pkg/rodHelper_test.go → internal/pkg/rod_helper/rodHelper_test.go

@@ -1,4 +1,4 @@
-package pkg
+package rod_helper
 
 import (
 	"github.com/go-rod/rod/lib/proto"

+ 16 - 14
internal/pkg/subParserHub.go → internal/pkg/sub_helper/subParserHub.go

@@ -1,8 +1,10 @@
-package pkg
+package sub_helper
 
 import (
-	common2 "github.com/allanpk716/ChineseSubFinder/internal/common"
-	_interface2 "github.com/allanpk716/ChineseSubFinder/internal/interface"
+	"github.com/allanpk716/ChineseSubFinder/internal/common"
+	"github.com/allanpk716/ChineseSubFinder/internal/ifaces"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/language"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/subparser"
 	"path/filepath"
 	"regexp"
@@ -10,13 +12,13 @@ import (
 )
 
 type SubParserHub struct {
-	Parser []_interface2.ISubParser
+	Parser []ifaces.ISubParser
 }
 
 // NewSubParserHub 处理的字幕文件需要符合 [siteName]_ 的前缀描述,是本程序专用的
-func NewSubParserHub(parser _interface2.ISubParser, _parser ..._interface2.ISubParser) *SubParserHub {
+func NewSubParserHub(parser ifaces.ISubParser, _parser ...ifaces.ISubParser) *SubParserHub {
 	s := SubParserHub{}
-	s.Parser = make([]_interface2.ISubParser, 0)
+	s.Parser = make([]ifaces.ISubParser, 0)
 	s.Parser = append(s.Parser, parser)
 	if len(_parser) > 0 {
 		for _, one := range _parser {
@@ -57,15 +59,15 @@ func (p SubParserHub) IsSubHasChinese(fileFPath string) bool {
 	// 增加判断已存在的字幕是否有中文
 	file, err := p.DetermineFileTypeFromFile(fileFPath)
 	if err != nil {
-		GetLogger().Warnln("IsSubHasChinese.DetermineFileTypeFromFile", fileFPath, err)
+		log_helper.GetLogger().Warnln("IsSubHasChinese.DetermineFileTypeFromFile", fileFPath, err)
 		return false
 	}
 	if file == nil {
-		GetLogger().Warnln("IsSubHasChinese.DetermineFileTypeFromFile", fileFPath, "is nil")
+		log_helper.GetLogger().Warnln("IsSubHasChinese.DetermineFileTypeFromFile", fileFPath, "is nil")
 		return false
 	}
-	if HasChineseLang(file.Lang) == false {
-		GetLogger().Warnln("IsSubHasChinese.HasChineseLang", fileFPath, "not chinese sub, is ", file.Lang.String())
+	if language.HasChineseLang(file.Lang) == false {
+		log_helper.GetLogger().Warnln("IsSubHasChinese.HasChineseLang", fileFPath, "not chinese sub, is ", file.Lang.String())
 		return false
 	}
 
@@ -86,9 +88,9 @@ func (p SubParserHub) getFromWhereSite(filePath string) string {
 // IsSubTypeWanted 这里匹配的字幕的格式,不包含 Ext 的 . 小数点,注意,仅仅是包含关系
 func IsSubTypeWanted(subName string) bool {
 	nowLowerName := strings.ToLower(subName)
-	if strings.Contains(nowLowerName, common2.SubTypeASS) ||
-		strings.Contains(nowLowerName, common2.SubTypeSSA) ||
-		strings.Contains(nowLowerName, common2.SubTypeSRT) {
+	if strings.Contains(nowLowerName, common.SubTypeASS) ||
+		strings.Contains(nowLowerName, common.SubTypeSSA) ||
+		strings.Contains(nowLowerName, common.SubTypeSRT) {
 		return true
 	}
 
@@ -99,7 +101,7 @@ func IsSubTypeWanted(subName string) bool {
 func IsSubExtWanted(subName string) bool {
 	inExt := filepath.Ext(subName)
 	switch strings.ToLower(inExt) {
-	case common2.SubExtSSA, common2.SubExtASS, common2.SubExtSRT:
+	case common.SubExtSSA, common.SubExtASS, common.SubExtSRT:
 		return true
 	default:
 		return false

+ 79 - 20
internal/pkg/sub_helper.go → internal/pkg/sub_helper/sub_helper.go

@@ -1,13 +1,20 @@
-package pkg
+package sub_helper
 
 import (
-	common2 "github.com/allanpk716/ChineseSubFinder/internal/common"
+	"github.com/allanpk716/ChineseSubFinder/internal/common"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/archive_helper"
+	"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/types/subparser"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/supplier"
 	"github.com/go-rod/rod/lib/utils"
+	"io/ioutil"
 	"os"
 	"path"
 	"path/filepath"
+	"strconv"
 	"strings"
 )
 
@@ -17,7 +24,7 @@ func OrganizeDlSubFiles(tmpFolderName string, subInfos []supplier.SubInfo) (map[
 	// 缓存列表,整理后的字幕列表
 	// SxEx - []string 字幕的路径
 	var siteSubInfoDict = make(map[string][]string)
-	tmpFolderFullPath, err := GetTmpFolder(tmpFolderName)
+	tmpFolderFullPath, err := pkg.GetTmpFolder(tmpFolderName)
 	if err != nil {
 		return nil, err
 	}
@@ -33,11 +40,11 @@ func OrganizeDlSubFiles(tmpFolderName string, subInfos []supplier.SubInfo) (map[
 		nowFileSaveFullPath := path.Join(tmpFolderFullPath, GetFrontNameAndOrgName(&subInfos[i]))
 		err = utils.OutputFile(nowFileSaveFullPath, subInfos[i].Data)
 		if err != nil {
-			GetLogger().Errorln("getFrontNameAndOrgName - OutputFile",subInfos[i].FromWhere, subInfos[i].Name, subInfos[i].TopN, err)
+			log_helper.GetLogger().Errorln("getFrontNameAndOrgName - OutputFile",subInfos[i].FromWhere, subInfos[i].Name, subInfos[i].TopN, err)
 			continue
 		}
 		nowExt := strings.ToLower(subInfos[i].Ext)
-		epsKey := GetEpisodeKeyName(subInfos[i].Season, subInfos[i].Episode)
+		epsKey := pkg.GetEpisodeKeyName(subInfos[i].Season, subInfos[i].Episode)
 		_, ok := siteSubInfoDict[epsKey]
 		if ok == false {
 			// 不存在则实例化
@@ -58,16 +65,16 @@ func OrganizeDlSubFiles(tmpFolderName string, subInfos []supplier.SubInfo) (map[
 			if err != nil {
 				return nil, err
 			}
-			err = UnArchiveFile(nowFileSaveFullPath, unzipTmpFolder)
+			err = archive_helper.UnArchiveFile(nowFileSaveFullPath, unzipTmpFolder)
 			// 解压完成后,遍历受支持的字幕列表,加入缓存列表
 			if err != nil {
-				GetLogger().Errorln("archiver.UnArchive", subInfos[i].FromWhere, subInfos[i].Name, subInfos[i].TopN, err)
+				log_helper.GetLogger().Errorln("archiver.UnArchive", subInfos[i].FromWhere, subInfos[i].Name, subInfos[i].TopN, err)
 				continue
 			}
 			// 搜索这个目录下的所有符合字幕格式的文件
 			subFileFullPaths, err := SearchMatchedSubFile(unzipTmpFolder)
 			if err != nil {
-				GetLogger().Errorln("searchMatchedSubFile", subInfos[i].FromWhere, subInfos[i].Name, subInfos[i].TopN, err)
+				log_helper.GetLogger().Errorln("searchMatchedSubFile", subInfos[i].FromWhere, subInfos[i].Name, subInfos[i].TopN, err)
 				continue
 			}
 			// 这里需要给这些下载到的文件进行改名,加是从那个网站来的前缀,后续好查找
@@ -77,7 +84,7 @@ func OrganizeDlSubFiles(tmpFolderName string, subInfos []supplier.SubInfo) (map[
 				// 改名
 				err = os.Rename(fileFullPath, newSubNameFullPath)
 				if err != nil {
-					GetLogger().Errorln("os.Rename", subInfos[i].FromWhere, subInfos[i].Name, subInfos[i].TopN, err)
+					log_helper.GetLogger().Errorln("os.Rename", subInfos[i].FromWhere, subInfos[i].Name, subInfos[i].TopN, err)
 					continue
 				}
 				// 加入缓存列表
@@ -94,7 +101,7 @@ func ChangeVideoExt2SubExt(subInfos []supplier.SubInfo) {
 	for x, info := range subInfos {
 		tmpSubFileName := info.Name
 		// 如果后缀名是下载字幕目标的后缀名  或者 是压缩包格式的,则跳过
-		if strings.Contains(tmpSubFileName, info.Ext) == true || IsWantedArchiveExtName(tmpSubFileName) == true {
+		if strings.Contains(tmpSubFileName, info.Ext) == true || archive_helper.IsWantedArchiveExtName(tmpSubFileName) == true {
 
 		} else {
 			subInfos[x].Name = tmpSubFileName + info.Ext
@@ -108,27 +115,27 @@ func SelectChineseBestBilingualSubtitle(subs []subparser.FileInfo, subTypePriori
 	// 先傻一点实现优先双语的,之前的写法有 bug
 	for _, info := range subs {
 		// 找到了中文字幕
-		if HasChineseLang(info.Lang) == true {
+		if language.HasChineseLang(info.Lang) == true {
 			// 字幕的优先级 0 - 原样, 1 - srt , 2 - ass/ssa
 			if subTypePriority == 1 {
 				// 1 - srt
-				if strings.ToLower(info.Ext) == common2.SubExtSRT {
+				if strings.ToLower(info.Ext) == common.SubExtSRT {
 					// 优先双语
-					if IsBilingualSubtitle(info.Lang) == true {
+					if language.IsBilingualSubtitle(info.Lang) == true {
 						return &info
 					}
 				}
 			} else if subTypePriority == 2 {
 				//  2 - ass/ssa
-				if strings.ToLower(info.Ext) == common2.SubExtASS || strings.ToLower(info.Ext) == common2.SubExtSSA {
+				if strings.ToLower(info.Ext) == common.SubExtASS || strings.ToLower(info.Ext) == common.SubExtSSA {
 					// 优先双语
-					if IsBilingualSubtitle(info.Lang) == true {
+					if language.IsBilingualSubtitle(info.Lang) == true {
 						return &info
 					}
 				}
 			} else {
 				// 优先双语
-				if IsBilingualSubtitle(info.Lang) == true {
+				if language.IsBilingualSubtitle(info.Lang) == true {
 					return &info
 				}
 			}
@@ -144,16 +151,16 @@ func SelectChineseBestSubtitle(subs []subparser.FileInfo, subTypePriority int) *
 	// 先傻一点实现优先双语的,之前的写法有 bug
 	for _, info := range subs {
 		// 找到了中文字幕
-		if HasChineseLang(info.Lang) == true {
+		if language.HasChineseLang(info.Lang) == true {
 			// 字幕的优先级 0 - 原样, 1 - srt , 2 - ass/ssa
 			if subTypePriority == 1 {
 				// 1 - srt
-				if strings.ToLower(info.Ext) == common2.SubExtSRT {
+				if strings.ToLower(info.Ext) == common.SubExtSRT {
 					return &info
 				}
 			} else if subTypePriority == 2 {
 				//  2 - ass/ssa
-				if strings.ToLower(info.Ext) == common2.SubExtASS || strings.ToLower(info.Ext) == common2.SubExtSSA {
+				if strings.ToLower(info.Ext) == common.SubExtASS || strings.ToLower(info.Ext) == common.SubExtSSA {
 					return &info
 				}
 			} else {
@@ -163,4 +170,56 @@ func SelectChineseBestSubtitle(subs []subparser.FileInfo, subTypePriority int) *
 	}
 
 	return nil
-}
+}
+
+// GetFrontNameAndOrgName 返回的名称包含,那个网站下载的,这个网站中排名第几,文件名
+func GetFrontNameAndOrgName(info *supplier.SubInfo) string {
+
+	infoName := ""
+	path, err := decode.GetVideoInfoFromFileName(info.Name)
+	if err != nil {
+		log_helper.GetLogger().Warnln("", err)
+		infoName = info.Name
+	} else {
+		infoName = path.Title + "_S" + strconv.Itoa(path.Season) + "E" + strconv.Itoa(path.Episode) + filepath.Ext(info.Name)
+	}
+	info.Name = infoName
+
+	return "[" + info.FromWhere + "]_" + strconv.FormatInt(info.TopN,10) + "_" + infoName
+}
+
+// AddFrontName 添加文件的前缀
+func AddFrontName(info supplier.SubInfo, orgName string) string {
+	return "[" + info.FromWhere + "]_" + strconv.FormatInt(info.TopN,10) + "_" + orgName
+}
+
+// SearchMatchedSubFile 搜索符合后缀名的视频文件
+func SearchMatchedSubFile(dir string) ([]string, error) {
+	// 这里有个梗,会出现 __MACOSX 这类文件夹,那么里面会有一样的文件,需要用文件大小排除一下,至少大于 1 kb 吧
+	var fileFullPathList = make([]string, 0)
+	pathSep := string(os.PathSeparator)
+	files, err := ioutil.ReadDir(dir)
+	if err != nil {
+		return nil, err
+	}
+	for _, curFile := range files {
+		fullPath := dir + pathSep + curFile.Name()
+		if curFile.IsDir() {
+			// 内层的错误就无视了
+			oneList, _ := SearchMatchedSubFile(fullPath)
+			if oneList != nil {
+				fileFullPathList = append(fileFullPathList, oneList...)
+			}
+		} else {
+			// 这里就是文件了
+			if curFile.Size() < 1000 {
+				continue
+			}
+			if IsSubExtWanted(filepath.Ext(curFile.Name())) == true {
+				fileFullPathList = append(fileFullPathList, fullPath)
+			}
+		}
+	}
+	return fileFullPathList, nil
+}
+

+ 17 - 45
internal/pkg/util.go

@@ -3,7 +3,9 @@ package pkg
 import (
 	"fmt"
 	browser "github.com/EDDYCJY/fake-useragent"
-	common2 "github.com/allanpk716/ChineseSubFinder/internal/common"
+	"github.com/allanpk716/ChineseSubFinder/internal/common"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/rod_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	"github.com/go-resty/resty/v2"
 	"io"
@@ -44,7 +46,7 @@ func NewHttpClient(_reqParam ...types.ReqParam) *resty.Client {
 	}
 
 	httpClient := resty.New()
-	httpClient.SetTimeout(common2.HTMLTimeOut)
+	httpClient.SetTimeout(common.HTMLTimeOut)
 	if HttpProxy != "" {
 		httpClient.SetProxy(HttpProxy)
 	} else {
@@ -103,7 +105,7 @@ func AddBaseUrl(baseUrl, url string) string {
 func GetDebugFolder() (string, error) {
 	if defDebugFolder == "" {
 		nowProcessRoot, _ := os.Getwd()
-		nowProcessRoot = path.Join(nowProcessRoot, common2.DebugFolder)
+		nowProcessRoot = path.Join(nowProcessRoot, common.DebugFolder)
 		err := os.MkdirAll(nowProcessRoot, os.ModePerm)
 		if err != nil {
 			return "", err
@@ -118,7 +120,7 @@ func GetDebugFolder() (string, error) {
 func GetRootTmpFolder() (string, error) {
 	if defTmpFolder == "" {
 		nowProcessRoot, _ := os.Getwd()
-		nowProcessRoot = path.Join(nowProcessRoot, common2.TmpFolder)
+		nowProcessRoot = path.Join(nowProcessRoot, common.TmpFolder)
 		err := os.MkdirAll(nowProcessRoot, os.ModePerm)
 		if err != nil {
 			return "", err
@@ -234,7 +236,7 @@ func VideoNameSearchKeywordMaker(title string, year string) string {
 	iYear, err := strconv.Atoi(year)
 	if err != nil {
 		// 允许的错误
-		GetLogger().Errorln("VideoNameSearchKeywordMaker", "year to int", err)
+		log_helper.GetLogger().Errorln("VideoNameSearchKeywordMaker", "year to int", err)
 		iYear = 0
 	}
 	searchKeyword := title
@@ -272,50 +274,20 @@ func SearchMatchedVideoFile(dir string) ([]string, error) {
 	return fileFullPathList, nil
 }
 
-// SearchMatchedSubFile 搜索符合后缀名的视频文件
-func SearchMatchedSubFile(dir string) ([]string, error) {
-	// 这里有个梗,会出现 __MACOSX 这类文件夹,那么里面会有一样的文件,需要用文件大小排除一下,至少大于 1 kb 吧
-	var fileFullPathList = make([]string, 0)
-	pathSep := string(os.PathSeparator)
-	files, err := ioutil.ReadDir(dir)
-	if err != nil {
-		return nil, err
-	}
-	for _, curFile := range files {
-		fullPath := dir + pathSep + curFile.Name()
-		if curFile.IsDir() {
-			// 内层的错误就无视了
-			oneList, _ := SearchMatchedSubFile(fullPath)
-			if oneList != nil {
-				fileFullPathList = append(fileFullPathList, oneList...)
-			}
-		} else {
-			// 这里就是文件了
-			if curFile.Size() < 1000 {
-				continue
-			}
-			if IsSubExtWanted(filepath.Ext(curFile.Name())) == true {
-				fileFullPathList = append(fileFullPathList, fullPath)
-			}
-		}
-	}
-	return fileFullPathList, nil
-}
-
 // IsWantedVideoExtDef 后缀名是否符合规则
 func IsWantedVideoExtDef(fileName string) bool {
 	// TODO 强制使用固定的视频后缀名匹配列表,后续有需求再考虑额实现外部可配置的列表
 
 	if len(wantedExtList) < 1 {
-		defExtList = append(defExtList, common2.VideoExtMp4)
-		defExtList = append(defExtList, common2.VideoExtMkv)
-		defExtList = append(defExtList, common2.VideoExtRmvb)
-		defExtList = append(defExtList, common2.VideoExtIso)
-
-		wantedExtList = append(defExtList, common2.VideoExtMp4)
-		wantedExtList = append(defExtList, common2.VideoExtMkv)
-		wantedExtList = append(defExtList, common2.VideoExtRmvb)
-		wantedExtList = append(defExtList, common2.VideoExtIso)
+		defExtList = append(defExtList, common.VideoExtMp4)
+		defExtList = append(defExtList, common.VideoExtMkv)
+		defExtList = append(defExtList, common.VideoExtRmvb)
+		defExtList = append(defExtList, common.VideoExtIso)
+
+		wantedExtList = append(defExtList, common.VideoExtMp4)
+		wantedExtList = append(defExtList, common.VideoExtMkv)
+		wantedExtList = append(defExtList, common.VideoExtRmvb)
+		wantedExtList = append(defExtList, common.VideoExtIso)
 	}
 	fileName = strings.ToLower(filepath.Ext(fileName))
 	for _, s := range wantedExtList {
@@ -332,7 +304,7 @@ func GetEpisodeKeyName(season, eps int) string {
 
 // ReloadBrowser 提前把浏览器下载好
 func ReloadBrowser() {
-	page, err := NewBrowserLoadPage("https://www.baidu.com", "", 300*time.Second, 2)
+	page, err := rod_helper.NewBrowserLoadPage("https://www.baidu.com", "", 300*time.Second, 2)
 	if err != nil {
 		return
 	}

+ 1 - 1
internal/types/language.go

@@ -23,7 +23,7 @@ const (
 )
 
 
-// 需要符合 emby 的格式要求,在后缀名前面
+// 需要符合 emby_helper 的格式要求,在后缀名前面
 const (
 	Emby_unknow = ".unknow"					// 未知语言
 	Emby_chinese 	= ".chinese"			// 中文

+ 9 - 21
main.go

@@ -1,35 +1,24 @@
 package main
 
 import (
+	"github.com/allanpk716/ChineseSubFinder/internal"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/notify_center"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	"github.com/robfig/cron/v3"
 	"github.com/sirupsen/logrus"
-	"github.com/spf13/viper"
 )
 
 func init() {
-	var err error
-	log = pkg.GetLogger()
-	configViper, err = pkg.InitConfigure()
-	if err != nil {
-		log.Errorln("InitConfigure", err)
-		return 
-	}
-	config, err = pkg.ReadConfig(configViper)
-	if err != nil {
-		log.Errorln("ReadConfig", err)
-		return 
-	}
+	log = log_helper.GetLogger()
+	config = pkg.GetConfig()
 }
 
 func main() {
 	if log == nil {
 		panic("log init error")
 	}
-	if configViper == nil {
-		panic("init viper error")
-	}
 	if config == nil {
 		panic("read config error")
 	}
@@ -47,7 +36,7 @@ func main() {
 		return
 	}
 
-	pkg.Notify = pkg.NewNotifyCenter(config.WhenSubSupplierInvalidWebHook)
+	notify_center.Notify = notify_center.NewNotifyCenter(config.WhenSubSupplierInvalidWebHook)
 
 	log.Infoln("MovieFolder:", config.MovieFolder)
 	log.Infoln("SeriesFolder:", config.SeriesFolder)
@@ -80,12 +69,12 @@ func main() {
 func DownLoadStart(httpProxy string) {
 	defer func() {
 		log.Infoln("Download One End...")
-		pkg.Notify.Send()
+		notify_center.Notify.Send()
 	}()
-	pkg.Notify.Clear()
+	notify_center.Notify.Clear()
 
 	// 下载实例
-	downloader := NewDownloader(types.ReqParam{
+	downloader := internal.NewDownloader(types.ReqParam{
 		HttpProxy:       httpProxy,
 		DebugMode:       config.DebugMode,
 		SaveMultiSub:    config.SaveMultiSub,
@@ -130,6 +119,5 @@ func DownLoadStart(httpProxy string) {
 
 var(
 	log         *logrus.Logger
-	configViper *viper.Viper
 	config      *types.Config
 )