Browse Source

调整项目结构

Signed-off-by: 716 <[email protected]>
716 4 years ago
parent
commit
1e099d9b8e

+ 0 - 8
common/iSubParser.go

@@ -1,8 +0,0 @@
-package common
-
-type ISubParser interface {
-
-	DetermineFileTypeFromFile(filePath string) (*SubParserFileInfo, error)
-
-	DetermineFileTypeFromBytes(inBytes []byte, nowExt string) (*SubParserFileInfo, error)
-}

+ 67 - 0
common/language.go

@@ -0,0 +1,67 @@
+package common
+
+const (
+	SubNameKeywordChineseSimple = "chs"
+	SubNameKeywordTraditional	 = "cht"
+)
+
+// Language 语言类型,注意,这里默认还是查找的是中文字幕,只不过下载的时候可能附带了其他的
+type Language int
+const (
+	Unknow                     Language = iota // 未知语言
+	ChineseSimple                              // 简体中文
+	ChineseTraditional                         // 繁体中文
+	ChineseSimpleEnglish                       // 简英双语字幕
+	ChineseTraditionalEnglish                  // 繁英双语字幕
+	English                                    // 英文
+	Japanese                                   // 日语
+	ChineseSimpleJapanese                      // 简日双语字幕
+	ChineseTraditionalJapanese                 // 繁日双语字幕
+	Korean                                     // 韩语
+	ChineseSimpleKorean                        // 简韩双语字幕
+	ChineseTraditionalKorean                   // 繁韩双语字幕
+)
+
+const (
+	MathLangChnUnknow = "未知语言"
+	MatchLangChs      = "简"
+	MatchLangCht      = "繁"
+	MatchLangChsEn    = "简英"
+	MatchLangChtEn    = "繁英"
+	MatchLangEn       = "英"
+	MatchLangJp       = "日"
+	MatchLangChsJp    = "简日"
+	MatchLangChtJp    = "繁日"
+	MatchLangKr       = "韩"
+	MatchLangChsKr    = "简韩"
+	MatchLangChtKr    = "繁韩"
+)
+
+func (l Language) String() string {
+	switch l {
+	case ChineseSimple:
+		return MatchLangChs
+	case ChineseTraditional:
+		return MatchLangCht
+	case ChineseSimpleEnglish:
+		return MatchLangChsEn
+	case ChineseTraditionalEnglish:
+		return MatchLangChtEn
+	case English:
+		return MatchLangEn
+	case Japanese:
+		return MatchLangJp
+	case ChineseSimpleJapanese:
+		return MatchLangChsJp
+	case ChineseTraditionalJapanese:
+		return MatchLangChtJp
+	case Korean:
+		return MatchLangKr
+	case ChineseSimpleKorean:
+		return MatchLangChsKr
+	case ChineseTraditionalKorean:
+		return MatchLangChtKr
+	default:
+		return MathLangChnUnknow
+	}
+}

+ 7 - 7
common/subParserFileInfo.go

@@ -1,13 +1,13 @@
 package common
 
 type SubParserFileInfo struct {
-	FromWhereSite string        // 从那个网站下载的
-	Name          string        // 字幕的名称,注意,这里需要额外的赋值,不会自动检测
-	Ext           string        // 字幕的后缀名
-	Lang          Language      // 识别出来的语言
-	FileFullPath  string        // 字幕文件的全路径
-	Data          []byte        // 字幕的二进制文件内容
-	Dialogues     []OneDialogue // 整个字幕文件的所有对话
+	FromWhereSite string         // 从那个网站下载的
+	Name          string         // 字幕的名称,注意,这里需要额外的赋值,不会自动检测
+	Ext           string         // 字幕的后缀名
+	Lang          Language // 识别出来的语言
+	FileFullPath  string         // 字幕文件的全路径
+	Data          []byte         // 字幕的二进制文件内容
+	Dialogues     []OneDialogue  // 整个字幕文件的所有对话
 }
 
 // OneDialogue 一句对话

+ 0 - 28
common/subType.go

@@ -1,33 +1,5 @@
 package common
 
-import (
-	"path/filepath"
-	"strings"
-)
-
-// IsSubTypeWanted 这里匹配的字幕的格式,不包含 Ext 的 . 小数点,注意,仅仅是包含关系
-func IsSubTypeWanted(subName string) bool {
-	nowLowerName := strings.ToLower(subName)
-	if strings.Contains(nowLowerName, SubTypeASS) ||
-		strings.Contains(nowLowerName, SubTypeSSA) ||
-		strings.Contains(nowLowerName, SubTypeSRT) {
-		return true
-	}
-
-	return false
-}
-
-// IsSubExtWanted 输入的字幕文件名,判断后缀名是否符合期望的字幕后缀名列表
-func IsSubExtWanted(subName string) bool {
-	inExt := filepath.Ext(subName)
-	switch strings.ToLower(inExt) {
-	case SubExtSSA,SubExtASS,SubExtSRT:
-		return true
-	default:
-		return false
-	}
-}
-
 const (
 	SubTypeASS = "ass"
 	SubTypeSSA = "ssa"

+ 9 - 9
common/supplierSubInfo.go

@@ -1,15 +1,15 @@
 package common
 
 type SupplierSubInfo struct {
-	FromWhere string          `json:"from_where"` // 从哪个网站下载来的
-	TopN      int64           `json:"top_n"`      // 是 Top 几?
-	Name      string          `json:"name"`       // 字幕的名称,这个比较随意,优先是影片的名称,然后才是从网上下载字幕的对应名称
-	Language  Language 		  `json:"language"`   // 字幕的语言
-	FileUrl   string          `json:"file-url"`   // 字幕文件下载的路径
-	Score     int64           `json:"score"`      // TODO 字幕的评分,需要有一个独立的评价体系
-	Offset    int64           `json:"offset"`     // 字幕的偏移
-	Ext       string          `json:"ext"`        // 字幕文件的后缀名带点,有可能是直接能用的字幕文件,也可能是压缩包
-	Data      []byte          `json:"data"`       // 字幕文件的二进制数据
+	FromWhere string         `json:"from_where"` // 从哪个网站下载来的
+	TopN      int64          `json:"top_n"`      // 是 Top 几?
+	Name      string         `json:"name"`       // 字幕的名称,这个比较随意,优先是影片的名称,然后才是从网上下载字幕的对应名称
+	Language  Language `json:"language"`   // 字幕的语言
+	FileUrl   string         `json:"file-url"`   // 字幕文件下载的路径
+	Score     int64          `json:"score"`      // TODO 字幕的评分,需要有一个独立的评价体系
+	Offset    int64          `json:"offset"`     // 字幕的偏移
+	Ext       string         `json:"ext"`        // 字幕文件的后缀名带点,有可能是直接能用的字幕文件,也可能是压缩包
+	Data      []byte         `json:"data"`       // 字幕文件的二进制数据
 }
 
 func NewSupplierSubInfo(fromWhere string, topN int64, name string, language Language, fileUrl string, score int64, offset int64, ext string, data []byte) *SupplierSubInfo {

+ 23 - 22
downloader.go

@@ -2,12 +2,13 @@ package ChineseSubFinder
 
 import (
 	"github.com/allanpk716/ChineseSubFinder/common"
-	"github.com/allanpk716/ChineseSubFinder/marking_system"
-	"github.com/allanpk716/ChineseSubFinder/sub_supplier"
-	"github.com/allanpk716/ChineseSubFinder/sub_supplier/shooter"
-	"github.com/allanpk716/ChineseSubFinder/sub_supplier/subhd"
-	"github.com/allanpk716/ChineseSubFinder/sub_supplier/xunlei"
-	"github.com/allanpk716/ChineseSubFinder/sub_supplier/zimuku"
+	"github.com/allanpk716/ChineseSubFinder/mark_system"
+	"github.com/allanpk716/ChineseSubFinder/model"
+	sub_supplier2 "github.com/allanpk716/ChineseSubFinder/sub_supplier"
+	shooter2 "github.com/allanpk716/ChineseSubFinder/sub_supplier/shooter"
+	subhd2 "github.com/allanpk716/ChineseSubFinder/sub_supplier/subhd"
+	xunlei2 "github.com/allanpk716/ChineseSubFinder/sub_supplier/xunlei"
+	zimuku2 "github.com/allanpk716/ChineseSubFinder/sub_supplier/zimuku"
 	"github.com/go-rod/rod/lib/utils"
 	"github.com/sirupsen/logrus"
 	"io/ioutil"
@@ -18,18 +19,18 @@ import (
 )
 
 type Downloader struct {
-	reqParam common.ReqParam
-	log *logrus.Logger
-	topic int						// 最多能够下载 Top 几的字幕,每一个网站
-	wantedExtList []string			// 人工确认的需要监控的视频后缀名
-	defExtList []string				// 内置支持的视频后缀名列表
-	mk *marking_system.MarkingSystem	// MarkingSystem
+	reqParam      model.ReqParam
+	log           *logrus.Logger
+	topic         int                        // 最多能够下载 Top 几的字幕,每一个网站
+	wantedExtList []string                   // 人工确认的需要监控的视频后缀名
+	defExtList    []string                   // 内置支持的视频后缀名列表
+	mk            *mark_system.MarkingSystem // MarkingSystem
 }
 
-func NewDownloader(_reqParam ... common.ReqParam) *Downloader {
+func NewDownloader(_reqParam ...model.ReqParam) *Downloader {
 
 	var downloader Downloader
-	downloader.log = common.GetLogger()
+	downloader.log = model.GetLogger()
 	downloader.topic = common.DownloadSubsPerSite
 	if len(_reqParam) > 0 {
 		downloader.reqParam = _reqParam[0]
@@ -48,7 +49,7 @@ func NewDownloader(_reqParam ... common.ReqParam) *Downloader {
 	sitesSequence = append(sitesSequence, common.SubSiteSubHd)
 	sitesSequence = append(sitesSequence, common.SubSiteZiMuKu)
 	sitesSequence = append(sitesSequence, common.SubSiteXunLei)
-	downloader.mk = marking_system.NewMarkingSystem(sitesSequence)
+	downloader.mk = mark_system.NewMarkingSystem(sitesSequence)
 
 	if len(_reqParam) > 0 {
 		// 如果用户设置了关注的视频后缀名列表,则用ta的
@@ -76,7 +77,7 @@ func (d Downloader) GetDefSupportExtList() []string {
 func (d Downloader) DownloadSub(dir string) error {
 	defer func() {
 		// 抉择完毕,需要清理缓存目录
-		err := common.ClearTmpFolder()
+		err := model.ClearTmpFolder()
 		if err != nil {
 			d.log.Error(err)
 		}
@@ -86,10 +87,10 @@ func (d Downloader) DownloadSub(dir string) error {
 		return err
 	}
 	// 构建每个字幕站点下载者的实例
-	subSupplierHub := sub_supplier.NewSubSupplierHub(shooter.NewSupplier(d.reqParam),
-									subhd.NewSupplier(d.reqParam),
-									xunlei.NewSupplier(d.reqParam),
-									zimuku.NewSupplier(d.reqParam),
+	subSupplierHub := sub_supplier2.NewSubSupplierHub(shooter2.NewSupplier(d.reqParam),
+									subhd2.NewSupplier(d.reqParam),
+									xunlei2.NewSupplier(d.reqParam),
+									zimuku2.NewSupplier(d.reqParam),
 	)
 	// TODO 后续再改为每个视频以上的流程都是一个 channel 来做,并且需要控制在一个并发量之下(很可能没必要,毕竟要在弱鸡机器上挂机用的)
 	// 一个视频文件同时多个站点查询,阻塞完毕后,在进行下一个
@@ -137,7 +138,7 @@ func (d Downloader) writeSubFile2VideoPath(videoFileFullPath string, finalSubFil
 	const emby_jp = ".jp"
 	const emby_kr = ".kr"
 	lan := ""
-	if common.HasChineseLang(finalSubFile.Lang) == true {
+	if model.HasChineseLang(finalSubFile.Lang) == true {
 		lan = emby_zh
 	} else if finalSubFile.Lang == common.English {
 		lan = emby_en
@@ -206,7 +207,7 @@ func (d Downloader) copySubFile2DesFolder(desFolder string, subFiles []string) e
 	// 复制下载在 tmp 文件夹中的字幕文件到视频文件夹下面
 	for _, subFile := range subFiles {
 		newFn := path.Join(desFolderFullPath, filepath.Base(subFile))
-		_, err = common.CopyFile(newFn, subFile)
+		_, err = model.CopyFile(newFn, subFile)
 		if err != nil {
 			return err
 		}

+ 4 - 4
downloader_test.go

@@ -1,8 +1,8 @@
 package ChineseSubFinder
 
 import (
-	"github.com/allanpk716/ChineseSubFinder/common"
-	"github.com/allanpk716/ChineseSubFinder/sub_supplier/shooter"
+	"github.com/allanpk716/ChineseSubFinder/model"
+	shooter2 "github.com/allanpk716/ChineseSubFinder/sub_supplier/shooter"
 	"testing"
 )
 
@@ -16,7 +16,7 @@ func TestDownloader_searchFile(t *testing.T) {
 	if err != nil {
 		t.Fatal(err)
 	}
-	sp := shooter.NewSupplier()
+	sp := shooter2.NewSupplier()
 	for i, file := range files {
 		println(i, file)
 		_, err := sp.ComputeFileHash(file)
@@ -30,7 +30,7 @@ func TestDownloader_DownloadSub(t *testing.T) {
 	var err error
 	dirRoot := "X:\\电影\\Spiral From the Book of Saw (2021)"
 
-	dl := NewDownloader(common.ReqParam{DebugMode: true})
+	dl := NewDownloader(model.ReqParam{DebugMode: true})
 	err = dl.DownloadSub(dirRoot)
 	if err != nil {
 		t.Fatal(err)

+ 10 - 0
interface/iSubParser.go

@@ -0,0 +1,10 @@
+package _interface
+
+import "github.com/allanpk716/ChineseSubFinder/common"
+
+type ISubParser interface {
+
+	DetermineFileTypeFromFile(filePath string) (*common.SubParserFileInfo, error)
+
+	DetermineFileTypeFromBytes(inBytes []byte, nowExt string) (*common.SubParserFileInfo, error)
+}

+ 5 - 3
common/iSupplier.go → interface/iSupplier.go

@@ -1,4 +1,6 @@
-package common
+package _interface
+
+import "github.com/allanpk716/ChineseSubFinder/common"
 
 type ISupplier interface {
 	// TODO 这里需要考虑是什么类型的视频文件,可能是 电影、连续剧、动画,这三类应该有细节上的差异
@@ -7,7 +9,7 @@ type ISupplier interface {
 	// 动画,嗯···还没啥经验,额外粗略看来,很多坑
 	GetSupplierName() string
 
-	GetSubListFromFile(filePath string) ([]SupplierSubInfo, error)
+	GetSubListFromFile(filePath string) ([]common.SupplierSubInfo, error)
 
-	GetSubListFromKeyword(keyword string) ([]SupplierSubInfo, error)
+	GetSubListFromKeyword(keyword string) ([]common.SupplierSubInfo, error)
 }

+ 6 - 5
marking_system/marking_system.go → mark_system/marking_system.go

@@ -1,7 +1,8 @@
-package marking_system
+package mark_system
 
 import (
 	"github.com/allanpk716/ChineseSubFinder/common"
+	"github.com/allanpk716/ChineseSubFinder/model"
 	"github.com/allanpk716/ChineseSubFinder/sub_parser/ass"
 	"github.com/allanpk716/ChineseSubFinder/sub_parser/srt"
 	"github.com/sirupsen/logrus"
@@ -14,8 +15,8 @@ type MarkingSystem struct {
 }
 
 func NewMarkingSystem(subSiteSequence []string) *MarkingSystem {
-	mk :=MarkingSystem{subSiteSequence: subSiteSequence,
-		log: common.GetLogger()}
+	mk := MarkingSystem{subSiteSequence: subSiteSequence,
+		log: model.GetLogger()}
 	return &mk
 }
 
@@ -26,7 +27,7 @@ func (m MarkingSystem) SelectOneSubFile(organizeSubFiles []string) *common.SubPa
 	var subInfoDict = make(map[string][]common.SubParserFileInfo)
 	// 拿到现有的字幕列表,开始抉择
 	// 先判断当前字幕是什么语言(如果是简体,还需要考虑,判断这个字幕是简体还是繁体)
-	subParserHub := common.NewSubParserHub(ass.NewParser(), srt.NewParser())
+	subParserHub := model.NewSubParserHub(ass.NewParser(), srt.NewParser())
 	for _, oneSubFileFullPath := range organizeSubFiles {
 		subFileInfo, err := subParserHub.DetermineFileTypeFromFile(oneSubFileFullPath)
 		if err != nil {
@@ -53,7 +54,7 @@ func (m MarkingSystem) SelectOneSubFile(organizeSubFiles []string) *common.SubPa
 		if ok == true {
 			for _, info := range value {
 				// 找到了中文字幕
-				if common.HasChineseLang(info.Lang) == true {
+				if model.HasChineseLang(info.Lang) == true {
 					finalSubFile = info
 					return &finalSubFile
 				}

+ 6 - 5
common/decode.go → model/decode.go

@@ -1,7 +1,8 @@
-package common
+package model
 
 import (
 	"errors"
+	"github.com/allanpk716/ChineseSubFinder/common"
 	"github.com/beevik/etree"
 	PTN "github.com/middelink/go-parse-torrent-name"
 	"io/ioutil"
@@ -21,7 +22,7 @@ func getImdbMovieXml(movieFilePath string) (string, error) {
 		return t.Text(), nil
 	}
 
-	return "", CanNotFindIMDBID
+	return "", common.CanNotFindIMDBID
 }
 
 func getImdbNfo(nfoFilePath string) (string, error) {
@@ -33,7 +34,7 @@ func getImdbNfo(nfoFilePath string) (string, error) {
 		return t.Text(), nil
 	}
 
-	return "", CanNotFindIMDBID
+	return "", common.CanNotFindIMDBID
 }
 
 func GetImdbId(dirPth string) (string ,error) {
@@ -64,7 +65,7 @@ func GetImdbId(dirPth string) (string ,error) {
 	}
 	// 根据找到的开始解析
 	if movieFilePath == "" && nfoFilePath == "" {
-		return "", NoMetadataFile
+		return "", common.NoMetadataFile
 	}
 
 	if movieFilePath != "" {
@@ -85,7 +86,7 @@ func GetImdbId(dirPth string) (string ,error) {
 		}
 	}
 
-	return "", CanNotFindIMDBID
+	return "", common.CanNotFindIMDBID
 }
 
 //GetVideoInfo 从文件名推断视频文件的信息

+ 1 - 1
common/decode_test.go → model/decode_test.go

@@ -1,4 +1,4 @@
-package common
+package model
 
 import (
 	"testing"

+ 60 - 123
common/lang.go → model/language.go

@@ -1,72 +1,73 @@
-package common
+package model
 
 import (
 	"github.com/abadojack/whatlanggo"
+	"github.com/allanpk716/ChineseSubFinder/common"
 	"strings"
 )
 
 // LangConverter 语言转换器
-func LangConverter(subLang string) Language {
+func LangConverter(subLang string) common.Language {
 	/*
 		xunlei:未知语言、简体&英语、繁体&英语、简体、繁体、英语
 	*/
-	if strings.Contains(subLang, MatchLangChs) {
+	if strings.Contains(subLang, common.MatchLangChs) {
 		// 优先简体
-		if strings.Contains(subLang, MatchLangEn) {
+		if strings.Contains(subLang, common.MatchLangEn) {
 			// 简英
-			return ChineseSimpleEnglish
-		} else if strings.Contains(subLang, MatchLangJp) {
+			return common.ChineseSimpleEnglish
+		} else if strings.Contains(subLang, common.MatchLangJp) {
 			// 简日
-			return ChineseSimpleJapanese
-		} else if strings.Contains(subLang, MatchLangKr) {
+			return common.ChineseSimpleJapanese
+		} else if strings.Contains(subLang, common.MatchLangKr) {
 			// 简韩
-			return ChineseSimpleKorean
+			return common.ChineseSimpleKorean
 		}
 		// 默认简体中文
-		return ChineseSimple
-	} else if strings.Contains(subLang, MatchLangCht) {
+		return common.ChineseSimple
+	} else if strings.Contains(subLang, common.MatchLangCht) {
 		// 然后是繁体
-		if strings.Contains(subLang, MatchLangEn) {
+		if strings.Contains(subLang, common.MatchLangEn) {
 			// 繁英
-			return ChineseTraditionalEnglish
-		} else if strings.Contains(subLang, MatchLangJp) {
+			return common.ChineseTraditionalEnglish
+		} else if strings.Contains(subLang, common.MatchLangJp) {
 			// 繁日
-			return ChineseTraditionalJapanese
-		} else if strings.Contains(subLang, MatchLangKr) {
+			return common.ChineseTraditionalJapanese
+		} else if strings.Contains(subLang, common.MatchLangKr) {
 			// 繁韩
-			return ChineseTraditionalKorean
+			return common.ChineseTraditionalKorean
 		}
 		// 默认繁体中文
-		return ChineseTraditional
-	} else if strings.Contains(subLang, MatchLangEn) {
+		return common.ChineseTraditional
+	} else if strings.Contains(subLang, common.MatchLangEn) {
 		// 英文
-		return English
-	} else if strings.Contains(subLang, MatchLangJp) {
+		return common.English
+	} else if strings.Contains(subLang, common.MatchLangJp) {
 		// 日文
-		return Japanese
-	} else if strings.Contains(subLang, MatchLangKr) {
+		return common.Japanese
+	} else if strings.Contains(subLang, common.MatchLangKr) {
 		// 韩文
-		return Korean
+		return common.Korean
 	} else {
 		// 都没有,则标记未知
-		return Unknow
+		return common.Unknow
 	}
 }
 
 // HasChineseLang 是否包含中文
-func HasChineseLang(lan Language) bool {
+func HasChineseLang(lan common.Language) bool {
 	switch lan {
-	case ChineseSimple,
-	ChineseTraditional,
+	case common.ChineseSimple,
+		common.ChineseTraditional,
 
-	ChineseSimpleEnglish,
-	ChineseTraditionalEnglish,
+		common.ChineseSimpleEnglish,
+		common.ChineseTraditionalEnglish,
 
-	ChineseSimpleJapanese,
-	ChineseTraditionalJapanese,
+		common.ChineseSimpleJapanese,
+		common.ChineseTraditionalJapanese,
 
-	ChineseSimpleKorean,
-	ChineseTraditionalKorean:
+		common.ChineseSimpleKorean,
+		common.ChineseTraditionalKorean:
 		return true
 	default:
 		return false
@@ -116,7 +117,7 @@ func DetectSubLangAndStatistics(lines []string, langDict map[int]int) {
 }
 
 // SubLangStatistics2SubLangType 由分析的信息转换为具体是什么字幕的语言类型
-func SubLangStatistics2SubLangType(countLineFeed, AllLines float32, langDict map[int]int) Language {
+func SubLangStatistics2SubLangType(countLineFeed, AllLines float32, langDict map[int]int) common.Language {
 	const basePer = 0.8
 	// 是否是双语?
 	isDouble := false
@@ -140,23 +141,23 @@ func SubLangStatistics2SubLangType(countLineFeed, AllLines float32, langDict map
 		// 首先得在外面统计就知道是双语
 		if hasChinese && hasEnglish {
 			// 简体	英文
-			return ChineseSimpleEnglish
+			return common.ChineseSimpleEnglish
 		} else if hasChinese && hasJapanese {
 			// 简体 日文
-			return ChineseSimpleJapanese
+			return common.ChineseSimpleJapanese
 		} else if hasChinese && hasKorean {
 			// 简体 韩文
-			return ChineseSimpleKorean
+			return common.ChineseSimpleKorean
 		} else if hasChinese {
-			return ChineseSimple
+			return common.ChineseSimple
 		} else if hasEnglish {
-			return English
+			return common.English
 		} else if hasJapanese {
-			return Japanese
+			return common.Japanese
 		} else if hasKorean {
-			return Korean
+			return common.Korean
 		} else {
-			return Unknow
+			return common.Unknow
 		}
 	} else {
 		// 如果比例达不到,那么就是单语言,所以最多的那个就是当前的语言
@@ -165,56 +166,56 @@ func SubLangStatistics2SubLangType(countLineFeed, AllLines float32, langDict map
 			// 那么起码要占比 80% 对吧
 			perLines = float32(countChinese) / AllLines
 			if perLines > basePer {
-				return ChineseSimple
+				return common.ChineseSimple
 			}
 		}
 		if hasEnglish {
 			// 那么起码要占比 80% 对吧
 			perLines = float32(countEnglish) / AllLines
 			if perLines > basePer {
-				return English
+				return common.English
 			}
 		}
 		if hasJapanese {
 			// 那么起码要占比 80% 对吧
 			perLines = float32(countJapanese) / AllLines
 			if perLines > basePer {
-				return Japanese
+				return common.Japanese
 			}
 		}
 		if hasKorean {
 			// 那么起码要占比 80% 对吧
 			perLines = float32(countKorean) / AllLines
 			if perLines > basePer {
-				return Korean
+				return common.Korean
 			}
 		}
 
-		return Unknow
+		return common.Unknow
 	}
 
 }
 
 // IsChineseSimpleOrTraditional 从字幕的文件名称中尝试确认是简体还是繁体,不需要判断双语问题,有额外的解析器完成。只可能出现 ChineseSimple ChineseTraditional Unknow 三种情况
-func IsChineseSimpleOrTraditional(inputFileName string, orgLang Language) Language {
+func IsChineseSimpleOrTraditional(inputFileName string, orgLang common.Language) common.Language {
 
-	if strings.Contains(inputFileName, SubNameKeywordChineseSimple) || strings.Contains(inputFileName, MatchLangChs) {
+	if strings.Contains(inputFileName, common.SubNameKeywordChineseSimple) || strings.Contains(inputFileName, common.MatchLangChs) {
 		// 简体中文关键词的匹配
 		return orgLang
-	} else if strings.Contains(inputFileName, SubNameKeywordTraditional) || strings.Contains(inputFileName, MatchLangCht) {
+	} else if strings.Contains(inputFileName, common.SubNameKeywordTraditional) || strings.Contains(inputFileName, common.MatchLangCht) {
 		// 繁体中文关键词的匹配
-		if orgLang == ChineseSimple {
+		if orgLang == common.ChineseSimple {
 			// 简体 -> 繁体
-			return ChineseTraditional
-		} else if orgLang == ChineseSimpleEnglish {
+			return common.ChineseTraditional
+		} else if orgLang == common.ChineseSimpleEnglish {
 			// 简体英文 -> 繁体英文
-			return ChineseTraditionalEnglish
-		} else if orgLang == ChineseSimpleJapanese {
+			return common.ChineseTraditionalEnglish
+		} else if orgLang == common.ChineseSimpleJapanese {
 			// 简体日文 -> 繁体日文
-			return ChineseTraditionalJapanese
-		} else if orgLang == ChineseSimpleKorean {
+			return common.ChineseTraditionalJapanese
+		} else if orgLang == common.ChineseSimpleKorean {
 			// 简体韩文 -> 繁体韩文
-			return ChineseTraditionalKorean
+			return common.ChineseTraditionalKorean
 		}
 		// 进来了都不是,那么就返回原来的语言
 		return orgLang
@@ -224,68 +225,4 @@ func IsChineseSimpleOrTraditional(inputFileName string, orgLang Language) Langua
 	}
 }
 
-const (
-	SubNameKeywordChineseSimple = "chs"
-	SubNameKeywordTraditional	 = "cht"
-)
-
-// Language 语言类型,注意,这里默认还是查找的是中文字幕,只不过下载的时候可能附带了其他的
-type Language int
-const (
-	Unknow	Language = iota				// 未知语言
-	ChineseSimple    					// 简体中文
-	ChineseTraditional					// 繁体中文
-	ChineseSimpleEnglish				// 简英双语字幕
-	ChineseTraditionalEnglish			// 繁英双语字幕
-	English								// 英文
-	Japanese							// 日语
-	ChineseSimpleJapanese				// 简日双语字幕
-	ChineseTraditionalJapanese			// 繁日双语字幕
-	Korean								// 韩语
-	ChineseSimpleKorean					// 简韩双语字幕
-	ChineseTraditionalKorean			// 繁韩双语字幕
-)
-
-const (
-	MathLangChnUnknow = "未知语言"
-	MatchLangChs      = "简"
-	MatchLangCht      = "繁"
-	MatchLangChsEn    = "简英"
-	MatchLangChtEn    = "繁英"
-	MatchLangEn       = "英"
-	MatchLangJp       = "日"
-	MatchLangChsJp    = "简日"
-	MatchLangChtJp    = "繁日"
-	MatchLangKr       = "韩"
-	MatchLangChsKr    = "简韩"
-	MatchLangChtKr    = "繁韩"
-)
 
-func (l Language) String() string {
-	switch l {
-	case ChineseSimple:
-		return MatchLangChs
-	case ChineseTraditional:
-		return MatchLangCht
-	case ChineseSimpleEnglish:
-		return MatchLangChsEn
-	case ChineseTraditionalEnglish:
-		return MatchLangChtEn
-	case English:
-		return MatchLangEn
-	case Japanese:
-		return MatchLangJp
-	case ChineseSimpleJapanese:
-		return MatchLangChsJp
-	case ChineseTraditionalJapanese:
-		return MatchLangChtJp
-	case Korean:
-		return MatchLangKr
-	case ChineseSimpleKorean:
-		return MatchLangChsKr
-	case ChineseTraditionalKorean:
-		return MatchLangChtKr
-	default:
-		return MathLangChnUnknow
-	}
-}

+ 1 - 1
common/loghelper.go → model/loghelper.go

@@ -1,4 +1,4 @@
-package common
+package model
 
 import (
 	rotatelogs "github.com/lestrrat-go/file-rotatelogs"

+ 1 - 1
common/pass_water_wall.go → model/pass_water_wall.go

@@ -1,4 +1,4 @@
-package common
+package model
 
 import (
 	"bytes"

+ 1 - 1
common/pass_water_wall_test.go → model/pass_water_wall_test.go

@@ -1,4 +1,4 @@
-package common
+package model
 
 import (
 	"testing"

+ 1 - 1
common/rodHelper.go → model/rodHelper.go

@@ -1,4 +1,4 @@
-package common
+package model
 
 import (
 	"context"

+ 1 - 1
common/rodHelper_test.go → model/rodHelper_test.go

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

+ 32 - 5
common/subParserHub.go → model/subParserHub.go

@@ -1,18 +1,21 @@
-package common
+package model
 
 import (
+	"github.com/allanpk716/ChineseSubFinder/common"
+	"github.com/allanpk716/ChineseSubFinder/interface"
 	"path/filepath"
 	"regexp"
+	"strings"
 )
 
 type SubParserHub struct {
-	Parser []ISubParser
+	Parser []_interface.ISubParser
 }
 
 // NewSubParserHub 处理的字幕文件需要符合 [siteName]_ 的前缀描述,是本程序专用的
-func NewSubParserHub(parser ISubParser, _parser ...ISubParser) *SubParserHub {
+func NewSubParserHub(parser _interface.ISubParser, _parser ..._interface.ISubParser) *SubParserHub {
 	s := SubParserHub{}
-	s.Parser = make([]ISubParser, 0)
+	s.Parser = make([]_interface.ISubParser, 0)
 	s.Parser = append(s.Parser, parser)
 	if len(_parser) > 0 {
 		for _, one := range _parser {
@@ -23,7 +26,7 @@ func NewSubParserHub(parser ISubParser, _parser ...ISubParser) *SubParserHub {
 }
 
 // DetermineFileTypeFromFile 确定字幕文件的类型,是双语字幕或者某一种语言等等信息,如果返回 nil ,那么就说明都没有字幕的格式匹配上
-func (p SubParserHub) DetermineFileTypeFromFile(filePath string) (*SubParserFileInfo, error){
+func (p SubParserHub) DetermineFileTypeFromFile(filePath string) (*common.SubParserFileInfo, error){
 	for _, parser := range p.Parser {
 		subFileInfo, err := parser.DetermineFileTypeFromFile(filePath)
 		if err != nil {
@@ -56,3 +59,27 @@ func (p SubParserHub) getFromWhereSite(filePath string) string {
 	}
 	return matched[1]
 }
+
+
+// IsSubTypeWanted 这里匹配的字幕的格式,不包含 Ext 的 . 小数点,注意,仅仅是包含关系
+func IsSubTypeWanted(subName string) bool {
+	nowLowerName := strings.ToLower(subName)
+	if strings.Contains(nowLowerName, common.SubTypeASS) ||
+		strings.Contains(nowLowerName, common.SubTypeSSA) ||
+		strings.Contains(nowLowerName, common.SubTypeSRT) {
+		return true
+	}
+
+	return false
+}
+
+// IsSubExtWanted 输入的字幕文件名,判断后缀名是否符合期望的字幕后缀名列表
+func IsSubExtWanted(subName string) bool {
+	inExt := filepath.Ext(subName)
+	switch strings.ToLower(inExt) {
+	case common.SubExtSSA,common.SubExtASS,common.SubExtSRT:
+		return true
+	default:
+		return false
+	}
+}

+ 1 - 1
common/subParserHub_test.go → model/subParserHub_test.go

@@ -1,4 +1,4 @@
-package common
+package model
 
 import (
 	"github.com/allanpk716/ChineseSubFinder/sub_parser/ass"

+ 5 - 4
common/util.go → model/util.go

@@ -1,7 +1,8 @@
-package common
+package model
 
 import (
 	"fmt"
+	"github.com/allanpk716/ChineseSubFinder/common"
 	"github.com/go-resty/resty/v2"
 	"io"
 	"io/ioutil"
@@ -36,7 +37,7 @@ func NewHttpClient(_reqParam ...ReqParam) *resty.Client {
 	}
 
 	httpClient := resty.New()
-	httpClient.SetTimeout(HTMLTimeOut)
+	httpClient.SetTimeout(common.HTMLTimeOut)
 	if HttpProxy != "" {
 		httpClient.SetProxy(HttpProxy)
 	}
@@ -93,7 +94,7 @@ func AddBaseUrl(baseUrl, url string) string {
 func GetDebugFolder() (string, error) {
 	if defDebugFolder == "" {
 		nowProcessRoot, _ := os.Getwd()
-		nowProcessRoot = path.Join(nowProcessRoot, DebugFolder)
+		nowProcessRoot = path.Join(nowProcessRoot, common.DebugFolder)
 		err := os.MkdirAll(nowProcessRoot, os.ModePerm)
 		if err != nil {
 			return "", err
@@ -107,7 +108,7 @@ func GetDebugFolder() (string, error) {
 func GetTmpFolder() (string, error) {
 	if defTmpFolder == "" {
 		nowProcessRoot, _ := os.Getwd()
-		nowProcessRoot = path.Join(nowProcessRoot, TmpFolder)
+		nowProcessRoot = path.Join(nowProcessRoot, common.TmpFolder)
 		err := os.MkdirAll(nowProcessRoot, os.ModePerm)
 		if err != nil {
 			return "", err

+ 3 - 2
sub_parser/ass/ass.go

@@ -2,6 +2,7 @@ package ass
 
 import (
 	"github.com/allanpk716/ChineseSubFinder/common"
+	"github.com/allanpk716/ChineseSubFinder/model"
 	"io/ioutil"
 	"path/filepath"
 	"regexp"
@@ -85,10 +86,10 @@ func (p Parser) DetermineFileTypeFromBytes(inBytes []byte, nowExt string) (*comm
 	var langDict map[int]int
 	langDict = make(map[int]int)
 	for _, dialogue := range subFileInfo.Dialogues {
-		common.DetectSubLangAndStatistics(dialogue.Lines, langDict)
+		model.DetectSubLangAndStatistics(dialogue.Lines, langDict)
 	}
 	// 从统计出来的字典,找出 Top 1 或者 2 的出来,然后计算出是什么语言的字幕
-	detectLang := common.SubLangStatistics2SubLangType(float32(countLineFeed), float32(len(matched)), langDict)
+	detectLang := model.SubLangStatistics2SubLangType(float32(countLineFeed), float32(len(matched)), langDict)
 	subFileInfo.Lang = detectLang
 	subFileInfo.Data = inBytes
 	return &subFileInfo, nil

+ 3 - 2
sub_parser/srt/srt.go

@@ -2,6 +2,7 @@ package srt
 
 import (
 	"github.com/allanpk716/ChineseSubFinder/common"
+	"github.com/allanpk716/ChineseSubFinder/model"
 	"io/ioutil"
 	"path/filepath"
 	"regexp"
@@ -72,10 +73,10 @@ func (p Parser) DetermineFileTypeFromBytes(inBytes []byte, nowExt string) (*comm
 	var langDict map[int]int
 	langDict = make(map[int]int)
 	for _, dialogue := range subFileInfo.Dialogues {
-		common.DetectSubLangAndStatistics(dialogue.Lines, langDict)
+		model.DetectSubLangAndStatistics(dialogue.Lines, langDict)
 	}
 	// 从统计出来的字典,找出 Top 1 或者 2 的出来,然后计算出是什么语言的字幕
-	detectLang := common.SubLangStatistics2SubLangType(float32(countLineFeed), float32(len(matched)), langDict)
+	detectLang := model.SubLangStatistics2SubLangType(float32(countLineFeed), float32(len(matched)), langDict)
 	subFileInfo.Lang = detectLang
 	subFileInfo.Data = inBytes
 	return &subFileInfo, nil

+ 8 - 7
sub_supplier/shooter/shooter.go

@@ -4,6 +4,7 @@ import (
 	"crypto/md5"
 	"fmt"
 	"github.com/allanpk716/ChineseSubFinder/common"
+	"github.com/allanpk716/ChineseSubFinder/model"
 	"github.com/sirupsen/logrus"
 	"math"
 	"os"
@@ -12,15 +13,15 @@ import (
 )
 
 type Supplier struct {
-	reqParam common.ReqParam
-	log *logrus.Logger
-	topic int
+	reqParam model.ReqParam
+	log      *logrus.Logger
+	topic    int
 }
 
-func NewSupplier(_reqParam ... common.ReqParam) *Supplier {
+func NewSupplier(_reqParam ...model.ReqParam) *Supplier {
 
 	sup := Supplier{}
-	sup.log = common.GetLogger()
+	sup.log = model.GetLogger()
 	sup.topic = common.DownloadSubsPerSite
 	if len(_reqParam) > 0 {
 		sup.reqParam = _reqParam[0]
@@ -52,7 +53,7 @@ func (s Supplier) GetSubListFromFile(filePath string) ([]common.SupplierSubInfo,
 
 	fileName := filepath.Base(filePath)
 
-	httpClient := common.NewHttpClient(s.reqParam)
+	httpClient := model.NewHttpClient(s.reqParam)
 
 	_, err = httpClient.R().
 		SetFormData(map[string]string{
@@ -73,7 +74,7 @@ func (s Supplier) GetSubListFromFile(filePath string) ([]common.SupplierSubInfo,
 				subExt = "." + subExt
 			}
 
-			data, _, err := common.DownFile(file.Link)
+			data, _, err := model.DownFile(file.Link)
 			if err != nil {
 				s.log.Error(err.Error())
 				continue

+ 2 - 2
sub_supplier/shooter/shooter_test.go

@@ -1,7 +1,7 @@
 package shooter
 
 import (
-	"github.com/allanpk716/ChineseSubFinder/common"
+	"github.com/allanpk716/ChineseSubFinder/model"
 	"testing"
 )
 
@@ -10,7 +10,7 @@ func TestNewSupplier(t *testing.T) {
 	//movie1 := "X:\\电影\\消失爱人 (2016)\\消失爱人 (2016) 720p AAC.rmvb"
 	//movie1 := "X:\\电影\\机动战士Z高达:星之继承者 (2005)\\机动战士Z高达:星之继承者 (2005) 1080p TrueHD.mkv"
 	//movie1 := "X:\\连续剧\\The Bad Batch\\Season 1\\The Bad Batch - S01E01 - Aftermath WEBDL-1080p.mkv"
-	shooter := NewSupplier(common.ReqParam{Topic: 3})
+	shooter := NewSupplier(model.ReqParam{Topic: 3})
 	outList, err := shooter.GetSubListFromFile(movie1)
 	if err != nil {
 		t.Error(err)

+ 11 - 9
sub_supplier/subSupplierHub.go

@@ -2,6 +2,8 @@ package sub_supplier
 
 import (
 	"github.com/allanpk716/ChineseSubFinder/common"
+	"github.com/allanpk716/ChineseSubFinder/interface"
+	"github.com/allanpk716/ChineseSubFinder/model"
 	"github.com/go-rod/rod/lib/utils"
 	"github.com/mholt/archiver/v3"
 	"github.com/sirupsen/logrus"
@@ -14,14 +16,14 @@ import (
 )
 
 type SubSupplierHub struct {
-	Suppliers []common.ISupplier
+	Suppliers []_interface.ISupplier
 	log *logrus.Logger
 }
 
-func NewSubSupplierHub(one common.ISupplier,_inSupplier ...common.ISupplier) *SubSupplierHub {
+func NewSubSupplierHub(one _interface.ISupplier,_inSupplier ..._interface.ISupplier) *SubSupplierHub {
 	s := SubSupplierHub{}
-	s.log = common.GetLogger()
-	s.Suppliers = make([]common.ISupplier, 0)
+	s.log = model.GetLogger()
+	s.Suppliers = make([]_interface.ISupplier, 0)
 	s.Suppliers = append(s.Suppliers, one)
 	if len(_inSupplier) > 0 {
 		for _, supplier := range _inSupplier {
@@ -68,7 +70,7 @@ func (d SubSupplierHub) downloadSub4OneVideo(oneVideoFullPath string, i int) []c
 }
 
 // downloadSub4OneSite 在一个站点下载这个视频的字幕
-func (d SubSupplierHub) downloadSub4OneSite(oneVideoFullPath string, i int, supplier common.ISupplier) ([]common.SupplierSubInfo, error) {
+func (d SubSupplierHub) downloadSub4OneSite(oneVideoFullPath string, i int, supplier _interface.ISupplier) ([]common.SupplierSubInfo, error) {
 	d.log.Infoln(i, supplier.GetSupplierName(), "Start...")
 	subInfos, err := supplier.GetSubListFromFile(oneVideoFullPath)
 	if err != nil {
@@ -90,12 +92,12 @@ func (d SubSupplierHub) organizeDlSubFiles(subInfos []common.SupplierSubInfo) ([
 
 	// 缓存列表,整理后的字幕列表
 	var siteSubInfoDict = make([]string, 0)
-	tmpFolderFullPath, err := common.GetTmpFolder()
+	tmpFolderFullPath, err := model.GetTmpFolder()
 	if err != nil {
 		return nil, err
 	}
 	// 先清理缓存目录
-	err = common.ClearTmpFolder()
+	err = model.ClearTmpFolder()
 	if err != nil {
 		return nil, err
 	}
@@ -113,7 +115,7 @@ func (d SubSupplierHub) organizeDlSubFiles(subInfos []common.SupplierSubInfo) ([
 		nowExt := strings.ToLower(subInfo.Ext)
 		if nowExt != ".zip" && nowExt != ".tar" && nowExt != ".rar" && nowExt != ".7z" {
 			// 是否是受支持的字幕类型
-			if common.IsSubExtWanted(nowExt) == false {
+			if model.IsSubExtWanted(nowExt) == false {
 				continue
 			}
 			// 加入缓存列表
@@ -175,7 +177,7 @@ func (d SubSupplierHub) searchMatchedSubFile(dir string) ([]string, error) {
 			if curFile.Size() < 1000 {
 				continue
 			}
-			if common.IsSubExtWanted(filepath.Ext(curFile.Name())) == true {
+			if model.IsSubExtWanted(filepath.Ext(curFile.Name())) == true {
 				fileFullPathList = append(fileFullPathList, fullPath)
 			}
 		}

+ 22 - 21
sub_supplier/subhd/subhd.go

@@ -5,6 +5,7 @@ import (
 	"fmt"
 	"github.com/PuerkitoBio/goquery"
 	"github.com/allanpk716/ChineseSubFinder/common"
+	"github.com/allanpk716/ChineseSubFinder/model"
 	"github.com/go-rod/rod"
 	"github.com/go-rod/rod/lib/launcher"
 	"github.com/nfnt/resize"
@@ -22,16 +23,16 @@ import (
 )
 
 type Supplier struct {
-	reqParam common.ReqParam
-	log *logrus.Logger
-	topic int
+	reqParam    model.ReqParam
+	log         *logrus.Logger
+	topic       int
 	rodlauncher *launcher.Launcher
 }
 
-func NewSupplier(_reqParam ... common.ReqParam) *Supplier {
+func NewSupplier(_reqParam ...model.ReqParam) *Supplier {
 
 	sup := Supplier{}
-	sup.log = common.GetLogger()
+	sup.log = model.GetLogger()
 	sup.topic = common.DownloadSubsPerSite
 	if len(_reqParam) > 0 {
 		sup.reqParam = _reqParam[0]
@@ -54,13 +55,13 @@ func (s Supplier) GetSubListFromFile(filePath string) ([]common.SupplierSubInfo,
 		如果找不到,再靠文件名提取影片名称去查找
 	*/
 	// 得到这个视频文件名中的信息
-	info, err := common.GetVideoInfo(filePath)
+	info, err := model.GetVideoInfo(filePath)
 	if err != nil {
 		return nil, err
 	}
 	// 找到这个视频文件,然后读取它目录下的文件,尝试得到 IMDB ID
 	fileRootDirPath := filepath.Dir(filePath)
-	imdbId, err := common.GetImdbId(fileRootDirPath)
+	imdbId, err := model.GetImdbId(fileRootDirPath)
 	if err != nil {
 		// 允许的错误,跳过,继续进行文件名的搜索
 		if err == common.CanNotFindIMDBID {
@@ -110,7 +111,7 @@ func (s Supplier) GetSubListFromKeyword(keyword string) ([]common.SupplierSubInf
 	}
 
 	// TODO 后面如果用 docker 部署,需要允许改位远程 browser 启动
-	browser, err := common.NewBrowser(s.reqParam.HttpProxy)
+	browser, err := model.NewBrowser(s.reqParam.HttpProxy)
 	if err != nil {
 		return nil, err
 	}
@@ -120,7 +121,7 @@ func (s Supplier) GetSubListFromKeyword(keyword string) ([]common.SupplierSubInf
 		if err != nil {
 			return nil, err
 		}
-		subInfos = append(subInfos, *common.NewSupplierSubInfo(s.GetSupplierName(), int64(i), hdContent.Filename, common.ChineseSimple, common.AddBaseUrl(common.SubSubHDRootUrl, item.Url), 0, 0, hdContent.Ext, hdContent.Data))
+		subInfos = append(subInfos, *common.NewSupplierSubInfo(s.GetSupplierName(), int64(i), hdContent.Filename, common.ChineseSimple, model.AddBaseUrl(common.SubSubHDRootUrl, item.Url), 0, 0, hdContent.Ext, hdContent.Data))
 	}
 
 	return subInfos, nil
@@ -139,7 +140,7 @@ func (s Supplier) Step0(keyword string) (string, error) {
 	if len(matched) < 1 {
 		return "",  common.SubHDStep0SubCountNotFound
 	}
-	subCount, err := common.GetNumber2int(matched[0][0])
+	subCount, err := model.GetNumber2int(matched[0][0])
 	if err != nil {
 		return "", err
 	}
@@ -157,7 +158,7 @@ func (s Supplier) Step0(keyword string) (string, error) {
 }
 // Step1 获取影片的详情字幕列表
 func (s Supplier) Step1(detailPageUrl string) ([]HdListItem, error) {
-	detailPageUrl = common.AddBaseUrl(common.SubSubHDRootUrl, detailPageUrl)
+	detailPageUrl = model.AddBaseUrl(common.SubSubHDRootUrl, detailPageUrl)
 	result, err := s.httpGet(detailPageUrl)
 	if err != nil {
 		return nil, err
@@ -186,11 +187,11 @@ func (s Supplier) Step1(detailPageUrl string) ([]HdListItem, error) {
 		title := strings.TrimSpace(tr.Find(oneSubTrTitleKeyword).Text())
 		// 字幕类型
 		insideSubType := tr.Find(oneSubLangAndTypeKetword).Text()
-		if common.IsSubTypeWanted(insideSubType) == false {
+		if model.IsSubTypeWanted(insideSubType) == false {
 			return true
 		}
 		// 下载的次数
-		downCount, err := common.GetNumber2int(tr.Find(oneSubTrDownloadCountKeyword).Eq(1).Text())
+		downCount, err := model.GetNumber2int(tr.Find(oneSubTrDownloadCountKeyword).Eq(1).Text())
 		if err != nil {
 			return true
 		}
@@ -214,7 +215,7 @@ func (s Supplier) Step1(detailPageUrl string) ([]HdListItem, error) {
 }
 // Step2 下载字幕,没用了,弃了
 func (s Supplier) Step2(subDownloadPageUrl string) (*HdContent, error) {
-	subDownloadPageUrl = common.AddBaseUrl(common.SubSubHDRootUrl, subDownloadPageUrl)
+	subDownloadPageUrl = model.AddBaseUrl(common.SubSubHDRootUrl, subDownloadPageUrl)
 	result, err := s.httpGet(subDownloadPageUrl)
 	if err != nil {
 		return nil, err
@@ -260,7 +261,7 @@ func (s Supplier) Step2(subDownloadPageUrl string) (*HdContent, error) {
 	downUrl = strings.ReplaceAll(downUrl, "\\", "")
 	var filename = filepath.Base(downUrl)
 	var data []byte
-	data, filename, err = common.DownFile(downUrl, s.reqParam)
+	data, filename, err = model.DownFile(downUrl, s.reqParam)
 	if err != nil {
 		return nil, err
 	}
@@ -273,9 +274,9 @@ func (s Supplier) Step2(subDownloadPageUrl string) (*HdContent, error) {
 
 // Step2Ex 下载字幕 过防水墙
 func (s Supplier) Step2Ex(browser *rod.Browser, subDownloadPageUrl string) (*HdContent, error)  {
-	subDownloadPageUrl = common.AddBaseUrl(common.SubSubHDRootUrl, subDownloadPageUrl)
+	subDownloadPageUrl = model.AddBaseUrl(common.SubSubHDRootUrl, subDownloadPageUrl)
 	// TODO 需要提取出 rod 的超时时间和重试次数,注意,这里的超时时间,在调试的时候也算进去的,所以···
-	page, err := common.NewPageNavigate(browser, subDownloadPageUrl, 300*time.Second, 5)
+	page, err := model.NewPageNavigate(browser, subDownloadPageUrl, 300*time.Second, 5)
 	if err != nil {
 		return nil, err
 	}
@@ -375,7 +376,7 @@ func (s Supplier) passWaterWall(page *rod.Page)  {
 	shadowbg := slideBgEl.MustResource()
 	// 取得原始圖像
 	src := slideBgEl.MustProperty("src")
-	fullbg, _, err := common.DownFile(strings.Replace(src.String(), "img_index=1", "img_index=0", 1))
+	fullbg, _, err := model.DownFile(strings.Replace(src.String(), "img_index=1", "img_index=0", 1))
 	if err != nil {
 		panic(err)
 	}
@@ -442,7 +443,7 @@ search:
 
 	if s.reqParam.DebugMode == true {
 		//截圖保存
-		nowProcessRoot, err := common.GetDebugFolder()
+		nowProcessRoot, err := model.GetDebugFolder()
 		if err == nil {
 			page.MustScreenshot(path.Join(nowProcessRoot, "result.png"))
 		} else {
@@ -453,7 +454,7 @@ search:
 
 func (s Supplier) httpGet(url string) (string, error) {
 	s.reqParam.Referer = url
-	httpClient := common.NewHttpClient(s.reqParam)
+	httpClient := model.NewHttpClient(s.reqParam)
 	resp, err := httpClient.R().Get(url)
 	if err != nil {
 		return "", err
@@ -470,7 +471,7 @@ func (s Supplier) httpGet(url string) (string, error) {
 func (s Supplier) httpPost(url string, postData map[string]string, referer string) (string, error) {
 
 	s.reqParam.Referer = referer
-	httpClient := common.NewHttpClient(s.reqParam)
+	httpClient := model.NewHttpClient(s.reqParam)
 	resp, err := httpClient.R().
 		SetFormData(postData).
 		Post(url)

+ 2 - 2
sub_supplier/subhd/subhd_test.go

@@ -1,7 +1,7 @@
 package subhd
 
 import (
-	"github.com/allanpk716/ChineseSubFinder/common"
+	"github.com/allanpk716/ChineseSubFinder/model"
 	"testing"
 )
 
@@ -11,7 +11,7 @@ func TestSupplier_GetSubListFromFile(t *testing.T) {
 	//movie1 := "X:\\电影\\消失爱人 (2016)\\消失爱人 (2016) 720p AAC.rmvb"
 	//movie1 := "X:\\电影\\机动战士Z高达:星之继承者 (2005)\\机动战士Z高达:星之继承者 (2005) 1080p TrueHD.mkv"
 	//movie1 := "X:\\连续剧\\The Bad Batch\\Season 1\\The Bad Batch - S01E01 - Aftermath WEBDL-1080p.mkv"
-	shooter := NewSupplier(common.ReqParam{Topic: 3})
+	shooter := NewSupplier(model.ReqParam{Topic: 3})
 	outList, err := shooter.GetSubListFromFile(movie1)
 	if err != nil {
 		t.Error(err)

+ 13 - 12
sub_supplier/xunlei/xunlei.go

@@ -4,6 +4,7 @@ import (
 	"crypto/sha1"
 	"fmt"
 	"github.com/allanpk716/ChineseSubFinder/common"
+	"github.com/allanpk716/ChineseSubFinder/model"
 	"github.com/sirupsen/logrus"
 	"math"
 	"os"
@@ -11,15 +12,15 @@ import (
 )
 
 type Supplier struct {
-	reqParam common.ReqParam
-	log *logrus.Logger
-	topic int
+	reqParam model.ReqParam
+	log      *logrus.Logger
+	topic    int
 }
 
-func NewSupplier(_reqParam ... common.ReqParam) *Supplier {
+func NewSupplier(_reqParam ...model.ReqParam) *Supplier {
 
 	sup := Supplier{}
-	sup.log = common.GetLogger()
+	sup.log = model.GetLogger()
 	sup.topic = common.DownloadSubsPerSite
 	if len(_reqParam) > 0 {
 		sup.reqParam = _reqParam[0]
@@ -43,7 +44,7 @@ func (s Supplier) GetSubListFromFile(filePath string) ([]common.SupplierSubInfo,
 	if len(cid) == 0 {
 		return outSubList, common.XunLeiCIdIsEmpty
 	}
-	httpClient := common.NewHttpClient(s.reqParam)
+	httpClient := model.NewHttpClient(s.reqParam)
 	_, err = httpClient.R().
 		SetResult(&jsonList).
 		Get(fmt.Sprintf(common.SubXunLeiRootUrl, cid))
@@ -54,8 +55,8 @@ func (s Supplier) GetSubListFromFile(filePath string) ([]common.SupplierSubInfo,
 	for _, v := range jsonList.Sublist {
 		if len(v.Scid) > 0 {
 			// 符合中文语言的先加入列表
-			tmpLang := common.LangConverter(v.Language)
-			if common.HasChineseLang(tmpLang) == true && common.IsSubTypeWanted(v.Sname) == true {
+			tmpLang := model.LangConverter(v.Language)
+			if model.HasChineseLang(tmpLang) == true && model.IsSubTypeWanted(v.Sname) == true {
 				tmpXunLeiSubListChinese = append(tmpXunLeiSubListChinese, v)
 			}
 		}
@@ -67,16 +68,16 @@ func (s Supplier) GetSubListFromFile(filePath string) ([]common.SupplierSubInfo,
 			if len(tmpXunLeiSubListChinese) >= s.topic {
 				break
 			}
-			tmpLang := common.LangConverter(v.Language)
-			if common.HasChineseLang(tmpLang) == false {
+			tmpLang := model.LangConverter(v.Language)
+			if model.HasChineseLang(tmpLang) == false {
 				tmpXunLeiSubListChinese = append(tmpXunLeiSubListChinese, v)
 			}
 		}
 	}
 	// 再开始下载字幕
 	for i, v := range tmpXunLeiSubListChinese {
-		tmpLang := common.LangConverter(v.Language)
-		data, filename, err := common.DownFile(v.Surl)
+		tmpLang := model.LangConverter(v.Language)
+		data, filename, err := model.DownFile(v.Surl)
 		if err != nil {
 			s.log.Error(err)
 			continue

+ 2 - 2
sub_supplier/xunlei/xunlei_test.go

@@ -1,7 +1,7 @@
 package xunlei
 
 import (
-	"github.com/allanpk716/ChineseSubFinder/common"
+	"github.com/allanpk716/ChineseSubFinder/model"
 	"testing"
 )
 
@@ -11,7 +11,7 @@ func TestGetList(t *testing.T) {
 	//movie1:= "X:\\电影\\Spiral From the Book of Saw (2021)\\Spiral From the Book of Saw (2021) WEBDL-1080p.mkv"
 	//movie1 := "X:\\电影\\机动战士Z高达:星之继承者 (2005)\\机动战士Z高达:星之继承者 (2005) 1080p TrueHD.mkv"
 	//movie1 := "X:\\连续剧\\The Bad Batch\\Season 1\\The Bad Batch - S01E01 - Aftermath WEBDL-1080p.mkv"
-	xunlie := NewSupplier(common.ReqParam{Topic: 3})
+	xunlie := NewSupplier(model.ReqParam{Topic: 3})
 	outList, err := xunlie.GetSubListFromFile(movie1)
 	if err != nil {
 		t.Error(err)

+ 30 - 29
sub_supplier/zimuku/zimuku.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"github.com/PuerkitoBio/goquery"
 	"github.com/allanpk716/ChineseSubFinder/common"
+	"github.com/allanpk716/ChineseSubFinder/model"
 	"github.com/sirupsen/logrus"
 	"path/filepath"
 	"regexp"
@@ -12,15 +13,15 @@ import (
 )
 
 type Supplier struct {
-	reqParam common.ReqParam
-	log *logrus.Logger
-	topic int
+	reqParam model.ReqParam
+	log      *logrus.Logger
+	topic    int
 }
 
-func NewSupplier(_reqParam ... common.ReqParam) *Supplier {
+func NewSupplier(_reqParam ...model.ReqParam) *Supplier {
 
 	sup := Supplier{}
-	sup.log = common.GetLogger()
+	sup.log = model.GetLogger()
 	sup.topic = common.DownloadSubsPerSite
 	if len(_reqParam) > 0 {
 		sup.reqParam = _reqParam[0]
@@ -44,13 +45,13 @@ func (s Supplier) GetSubListFromFile(filePath string) ([]common.SupplierSubInfo,
 		如果找不到,再靠文件名提取影片名称去查找
 	*/
 	// 得到这个视频文件名中的信息
-	info, err := common.GetVideoInfo(filePath)
+	info, err := model.GetVideoInfo(filePath)
 	if err != nil {
 		return nil, err
 	}
 	// 找到这个视频文件,然后读取它目录下的文件,尝试得到 IMDB ID
 	fileRootDirPath := filepath.Dir(filePath)
-	imdbId, err := common.GetImdbId(fileRootDirPath)
+	imdbId, err := model.GetImdbId(fileRootDirPath)
 	if err != nil {
 		// 允许的错误,跳过,继续进行文件名的搜索
 		if err == common.CanNotFindIMDBID {
@@ -112,8 +113,8 @@ func (s Supplier) GetSubListFromKeyword(keyword string) ([]common.SupplierSubInf
 	// 首先过滤出中文的字幕,同时需要满足是支持的字幕
 	var tmpSubInfo = make([]SubInfo, 0)
 	for _, subInfo := range subResult.SubInfos {
-		tmpLang := common.LangConverter(subInfo.Lang)
-		if common.HasChineseLang(tmpLang) == true && common.IsSubTypeWanted(subInfo.Ext) == true {
+		tmpLang := model.LangConverter(subInfo.Lang)
+		if model.HasChineseLang(tmpLang) == true && model.IsSubTypeWanted(subInfo.Ext) == true {
 			tmpSubInfo = append(tmpSubInfo, subInfo)
 		}
 	}
@@ -123,8 +124,8 @@ func (s Supplier) GetSubListFromKeyword(keyword string) ([]common.SupplierSubInf
 			if len(tmpSubInfo) >= s.topic {
 				break
 			}
-			tmpLang := common.LangConverter(subInfo.Lang)
-			if common.HasChineseLang(tmpLang) == false {
+			tmpLang := model.LangConverter(subInfo.Lang)
+			if model.HasChineseLang(tmpLang) == false {
 				tmpSubInfo = append(tmpSubInfo, subInfo)
 			}
 		}
@@ -138,7 +139,7 @@ func (s Supplier) GetSubListFromKeyword(keyword string) ([]common.SupplierSubInf
 			continue
 		}
 		// 默认都是包含中文字幕的,然后具体使用的时候再进行区分
-		outSubInfoList = append(outSubInfoList, *common.NewSupplierSubInfo(s.GetSupplierName(), int64(i), fileName, common.ChineseSimple, common.AddBaseUrl(common.SubZiMuKuRootUrl, subInfo.SubDownloadPageUrl), 0,
+		outSubInfoList = append(outSubInfoList, *common.NewSupplierSubInfo(s.GetSupplierName(), int64(i), fileName, common.ChineseSimple, model.AddBaseUrl(common.SubZiMuKuRootUrl, subInfo.SubDownloadPageUrl), 0,
 			0, filepath.Ext(fileName), data))
 	}
 
@@ -147,7 +148,7 @@ func (s Supplier) GetSubListFromKeyword(keyword string) ([]common.SupplierSubInf
 
 // Step0 先在查询界面找到字幕对应第一个影片的详情界面
 func (s Supplier) Step0(keyword string) (string, error) {
-	httpClient := common.NewHttpClient(s.reqParam)
+	httpClient := model.NewHttpClient(s.reqParam)
 	// 第一级界面,有多少个字幕
 	resp, err := httpClient.R().
 		SetQueryParams(map[string]string{
@@ -170,8 +171,8 @@ func (s Supplier) Step0(keyword string) (string, error) {
 
 // Step1 分析详情界面,找到有多少个字幕
 func (s Supplier) Step1(filmDetailPageUrl string) (SubResult, error) {
-	filmDetailPageUrl = common.AddBaseUrl(common.SubZiMuKuRootUrl, filmDetailPageUrl)
-	httpClient := common.NewHttpClient(s.reqParam)
+	filmDetailPageUrl = model.AddBaseUrl(common.SubZiMuKuRootUrl, filmDetailPageUrl)
+	httpClient := model.NewHttpClient(s.reqParam)
 	resp, err := httpClient.R().
 		Get(filmDetailPageUrl)
 	if err != nil {
@@ -216,7 +217,7 @@ func (s Supplier) Step1(filmDetailPageUrl string) (SubResult, error) {
 		if !exists {
 			rate = ""
 		}
-		vote, err := common.GetNumber2Float(rate)
+		vote, err := model.GetNumber2Float(rate)
 		if err != nil {
 			return
 		}
@@ -224,13 +225,13 @@ func (s Supplier) Step1(filmDetailPageUrl string) (SubResult, error) {
 		downCountNub := 0
 		downCount := tr.Find("td").Eq(3).Text()
 		if strings.Contains(downCount, "万") {
-			fNumb, err := common.GetNumber2Float(downCount)
+			fNumb, err := model.GetNumber2Float(downCount)
 			if err != nil {
 				return
 			}
 			downCountNub = int(fNumb * 10000)
 		} else {
-			downCountNub, err = common.GetNumber2int(downCount)
+			downCountNub, err = model.GetNumber2int(downCount)
 			if err != nil {
 				return
 			}
@@ -256,8 +257,8 @@ func (s Supplier) Step1(filmDetailPageUrl string) (SubResult, error) {
 // Step2 第二级界面,单个字幕详情
 func (s Supplier) Step2(subInfo *SubInfo) error {
 
-	detailUrl := common.AddBaseUrl(common.SubZiMuKuRootUrl, subInfo.DetailUrl)
-	httpClient := common.NewHttpClient(s.reqParam)
+	detailUrl := model.AddBaseUrl(common.SubZiMuKuRootUrl, subInfo.DetailUrl)
+	httpClient := model.NewHttpClient(s.reqParam)
 	resp, err := httpClient.R().
 		Get(detailUrl)
 	if err != nil {
@@ -281,8 +282,8 @@ func (s Supplier) Step2(subInfo *SubInfo) error {
 // Step3 第三级界面,具体字幕下载
 func (s Supplier) Step3(subDownloadPageUrl string) (string, []byte, error) {
 
-	subDownloadPageUrl = common.AddBaseUrl(common.SubZiMuKuRootUrl, subDownloadPageUrl)
-	httpClient := common.NewHttpClient(s.reqParam)
+	subDownloadPageUrl = model.AddBaseUrl(common.SubZiMuKuRootUrl, subDownloadPageUrl)
+	httpClient := model.NewHttpClient(s.reqParam)
 	resp, err := httpClient.R().
 		Get(subDownloadPageUrl)
 	if err != nil {
@@ -299,7 +300,7 @@ func (s Supplier) Step3(subDownloadPageUrl string) (string, []byte, error) {
 
 	s.reqParam.Referer = subDownloadPageUrl
 	for i := 0; i < len(matched); i++ {
-		data, filename, err = common.DownFile(common.AddBaseUrl(common.SubZiMuKuRootUrl, matched[i][1]), s.reqParam)
+		data, filename, err = model.DownFile(model.AddBaseUrl(common.SubZiMuKuRootUrl, matched[i][1]), s.reqParam)
 		if err != nil {
 			s.log.Error("ZiMuKu Step3 DownloadFile", err)
 			continue
@@ -312,7 +313,7 @@ func (s Supplier) Step3(subDownloadPageUrl string) (string, []byte, error) {
 
 // Step1Discard 第一级界面,有多少个字幕,弃用,直接再搜索出来的结果界面匹配会遇到一个问题,就是 “还有8个字幕,点击查看” 类似此问题
 func (s Supplier) Step1Discard(keyword string) (SubResult, error) {
-	httpClient := common.NewHttpClient(s.reqParam)
+	httpClient := model.NewHttpClient(s.reqParam)
 	// 第一级界面,有多少个字幕
 	resp, err := httpClient.R().
 		SetQueryParams(map[string]string{
@@ -357,14 +358,14 @@ func (s Supplier) Step1Discard(keyword string) (SubResult, error) {
 						if ok == false {
 							return
 						}
-						number, err := common.GetNumber2Float(vote)
+						number, err := model.GetNumber2Float(vote)
 						if err != nil {
 							return
 						}
 						subInfo.Score = number
 					} else if i == 2{
 						// 下载量
-						number, err := common.GetNumber2int(sTd.Text())
+						number, err := model.GetNumber2int(sTd.Text())
 						if err != nil {
 							return
 						}
@@ -389,9 +390,9 @@ func (s Supplier) Step1Discard(keyword string) (SubResult, error) {
 }
 
 type SubResult struct {
-	Title string			// 字幕的标题
-	OtherName string		// 影片又名
-	SubInfos SubInfos		// 字幕的列表
+	Title     string   // 字幕的标题
+	OtherName string   // 影片又名
+	SubInfos  SubInfos // 字幕的列表
 }
 
 type SubInfo struct {