浏览代码

更换简繁转换为 opencc,完成 assrt 对接

Signed-off-by: allan716 <[email protected]>
allan716 3 年之前
父节点
当前提交
c80a764fd7

+ 1 - 27
TestCode/test_chs_cht_convert.go

@@ -1,31 +1,5 @@
 package TestCode
 
-import (
-	"github.com/go-creed/sat"
-)
-
 func convertChsCht() {
-	/*
-		dicter.Read 转简体
-		dicter.ReadReverse 转繁体
-	*/
-	dicter := sat.DefaultDict()
-	println("---------------------")
-	sstr := "什麼sdg as 123"
-	println(sstr)
-	// 转换到 简体
-	println(dicter.Read(sstr))
-	// 转换到 繁体
-	println(dicter.ReadReverse(sstr))
-	println("---------------------")
-	sstr = "11什asd么56"
-	println(sstr)
-	println(dicter.Read(sstr))
-	println(dicter.ReadReverse(sstr))
-	println("---------------------")
-	sstr = "asd簡繁as25轉s換66"
-	println(sstr)
-	println(dicter.Read(sstr))
-	println(dicter.ReadReverse(sstr))
-	println("---------------------")
+
 }

+ 5 - 1
go.mod

@@ -70,6 +70,7 @@ require (
 require (
 	github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
 	github.com/elazarl/goproxy v0.0.0-20220417044921-416226498f94
+	github.com/longbridgeapp/opencc v0.1.7
 )
 
 require (
@@ -104,6 +105,8 @@ require (
 	github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
 	github.com/klauspost/pgzip v1.2.4 // indirect
 	github.com/leodido/go-urn v1.2.1 // indirect
+	github.com/liuzl/cedar-go v0.0.0-20170805034717-80a9c64b256d // indirect
+	github.com/liuzl/da v0.0.0-20180704015230-14771aad5b1d // indirect
 	github.com/mattn/go-isatty v0.0.14 // indirect
 	github.com/mattn/go-sqlite3 v1.14.10 // indirect
 	github.com/mitchellh/go-homedir v1.1.0 // indirect
@@ -112,7 +115,7 @@ require (
 	github.com/nwaples/rardecode v1.1.0 // indirect
 	github.com/pierrec/lz4/v4 v4.0.3 // indirect
 	github.com/pkg/errors v0.9.1 // indirect
-	github.com/sergi/go-diff v1.1.0 // indirect
+	github.com/sergi/go-diff v1.2.0 // indirect
 	github.com/spaolacci/murmur3 v1.1.0 // indirect
 	github.com/subosito/gotenv v1.2.0 // indirect
 	github.com/tidwall/match v1.1.1 // indirect
@@ -132,5 +135,6 @@ require (
 
 replace (
 	github.com/go-creed/sat => github.com/allanpk716/sat v0.0.0-20210622112535-2e00ce54a80b
+	github.com/longbridgeapp/opencc => github.com/allanpk716/opencc v0.1.8
 	github.com/middelink/go-parse-torrent-name => github.com/allanpk716/go-parse-torrent-name v0.0.0-20220212145434-430ea25cbba7
 )

+ 10 - 1
go.sum

@@ -44,6 +44,8 @@ github.com/abadojack/whatlanggo v1.0.1 h1:19N6YogDnf71CTHm3Mp2qhYfkRdyvbgwWdd2EP
 github.com/abadojack/whatlanggo v1.0.1/go.mod h1:66WiQbSbJBIlOZMsvbKe5m6pzQovxCH9B/K8tQB2uoc=
 github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk=
 github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
+github.com/adamzy/cedar-go v0.0.0-20170805034717-80a9c64b256d h1:ir/IFJU5xbja5UaBEQLjcvn7aAU01nqU/NUyOBEU+ew=
+github.com/adamzy/cedar-go v0.0.0-20170805034717-80a9c64b256d/go.mod h1:PRWNwWq0yifz6XDPZu48aSld8BWwBfr2JKB2bGWiEd4=
 github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
 github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
 github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
@@ -54,6 +56,8 @@ github.com/allanpk716/fake-useragent v0.2.1 h1:5EurHovAMGNwMZNbZ2cFOH8HsLdHwopnn
 github.com/allanpk716/fake-useragent v0.2.1/go.mod h1:U3tmrxBYvSPeQKQ/9x59CXJPkHbU4x4eXw3ji5TDhPk=
 github.com/allanpk716/go-parse-torrent-name v0.0.0-20220212145434-430ea25cbba7 h1:5AYgeYsVjtDPG5sUS77lyeEPiRMduIKstLjkBLiVPRc=
 github.com/allanpk716/go-parse-torrent-name v0.0.0-20220212145434-430ea25cbba7/go.mod h1:H66QhXPJpUSdWschhL6u//v3ge96/qMnQ9mWp3efbxA=
+github.com/allanpk716/opencc v0.1.8 h1:9jQN/nbav5S7wxeekOr5Zl/LrITcQgJuk7MuhN7bOdU=
+github.com/allanpk716/opencc v0.1.8/go.mod h1:jRuKtq8eLA+cZUu75XgMvkB/hFSXJbZDmij0v29lNaY=
 github.com/allanpk716/sat v0.0.0-20210622112535-2e00ce54a80b h1:vxXQuRgTH0D6aacl7Jyk4Kz8N4wbVTFn7M7Ib+/IFq4=
 github.com/allanpk716/sat v0.0.0-20210622112535-2e00ce54a80b/go.mod h1:ZxAhQ0ikMzjqeMbFeoMdCr6es8p10Y87F2nHkqNjSbY=
 github.com/andybalholm/brotli v1.0.0 h1:7UCwP93aiSfvWpapti8g88vVVGp2qqtGyePsSuDafo4=
@@ -372,6 +376,10 @@ github.com/lestrrat-go/strftime v1.0.4 h1:T1Rb9EPkAhgxKqbcMIPguPq8glqXTA1koF8n9B
 github.com/lestrrat-go/strftime v1.0.4/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR76fd03sz+Qz4g=
 github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
 github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
+github.com/liuzl/cedar-go v0.0.0-20170805034717-80a9c64b256d h1:qSmEGTgjkESUX5kPMSGJ4pcBUtYVDdkNzMrjQyvRvp0=
+github.com/liuzl/cedar-go v0.0.0-20170805034717-80a9c64b256d/go.mod h1:x7SghIWwLVcJObXbjK7S2ENsT1cAcdJcPl7dRaSFog0=
+github.com/liuzl/da v0.0.0-20180704015230-14771aad5b1d h1:hTRDIpJ1FjS9ULJuEzu69n3qTgc18eI+ztw/pJv47hs=
+github.com/liuzl/da v0.0.0-20180704015230-14771aad5b1d/go.mod h1:7xD3p0XnHvJFQ3t/stEJd877CSIMkH/fACVWen5pYnc=
 github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
 github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
 github.com/magiconair/properties v1.8.4 h1:8KGKTcQQGm0Kv7vEbKFErAoAOFyyacLStRtQSeYtvkY=
@@ -512,8 +520,9 @@ github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca/go.mod h1:uugorj
 github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
 github.com/scylladb/termtables v0.0.0-20191203121021-c4c0b6d42ff4/go.mod h1:C1a7PQSMz9NShzorzCiG2fk9+xuCgLkPeCvMHYR2OWg=
 github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
-github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
 github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
+github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
+github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
 github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
 github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
 github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=

+ 2 - 0
internal/logic/sub_parser/ass/ass_test.go

@@ -1,6 +1,7 @@
 package ass
 
 import (
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/unit_test_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/language"
 	"path/filepath"
@@ -37,6 +38,7 @@ func TestParser_DetermineFileTypeFromFile(t *testing.T) {
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			p := Parser{}
+			p.log = log_helper.GetLogger4Tester()
 			bFind, got, err := p.DetermineFileTypeFromFile(tt.args.filePath)
 			if (err != nil) != tt.wantErr {
 				t.Errorf("DetermineFileTypeFromFile() error = %v, wantErr %v", err, tt.wantErr)

+ 61 - 59
internal/logic/sub_supplier/assrt/assrt.go

@@ -3,15 +3,12 @@ package assrt
 import (
 	"errors"
 	"fmt"
-	"github.com/allanpk716/ChineseSubFinder/internal/dao"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/file_downloader"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/decode"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/imdb_helper"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/language"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/notify_center"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/settings"
-	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	common2 "github.com/allanpk716/ChineseSubFinder/internal/types/common"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/series"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/supplier"
@@ -47,18 +44,25 @@ func NewSupplier(fileDownloader *file_downloader.FileDownloader) *Supplier {
 }
 
 func (s *Supplier) CheckAlive() (bool, int64) {
-	//// 计算当前时间
-	//startT := time.Now()
-	//_, err := s.getSubInfos(checkFileHash, checkFileName, qLan)
-	//if err != nil {
-	//	s.log.Errorln(s.GetSupplierName(), "CheckAlive", "Error", err)
-	//	s.isAlive = false
-	//	return false, 0
-	//}
-	//// 计算耗时
-	//s.isAlive = true
-	//return true, time.Since(startT).Milliseconds()
-	return false, 0
+
+	// 如果没有设置这个 API 接口,那么就任务是不可用的
+	if s.settings.SubtitleSources.AssrtSettings.Token == "" {
+		s.isAlive = false
+		return false, 0
+	}
+
+	// 计算当前时间
+	startT := time.Now()
+	userInfo, err := s.getUserInfo()
+	if err != nil {
+		s.log.Errorln(s.GetSupplierName(), "CheckAlive", "Error", err)
+		s.isAlive = false
+		return false, 0
+	}
+	s.log.Infoln(s.GetSupplierName(), "CheckAlive", "UserInfo.Status:", userInfo.Status, "UserInfo.Quota:", userInfo.User.Quota)
+	// 计算耗时
+	s.isAlive = true
+	return true, time.Since(startT).Milliseconds()
 }
 
 func (s *Supplier) IsAlive() bool {
@@ -110,57 +114,24 @@ func (s *Supplier) getSubListFromFile(videoFPath string, isMovie bool) ([]suppli
 
 	outSubInfoList := make([]supplier.SubInfo, 0)
 
-	var err error
-	var imdbInfo4Video types.VideoIMDBInfo
-	if isMovie == true {
-		imdbInfo4Video, err = decode.GetImdbInfo4Movie(videoFPath)
-	} else {
-		imdbInfo4Video, err = decode.GetSeriesSeasonImdbInfoFromEpisode(videoFPath)
-	}
-	if err != nil {
-		// 如果找不到当前电影的 IMDB Info 本地文件,那么就跳过
-		s.log.Warningln("getSubListFromFile", videoFPath, err)
-		return nil, err
-	}
-
-	imdbInfo, err := imdb_helper.GetVideoIMDBInfoFromLocal(s.log, imdbInfo4Video)
+	imdbInfo, err := imdb_helper.GetIMDBInfo(s.log, videoFPath, isMovie, s.settings.AdvancedSettings.ProxySettings)
 	if err != nil {
-		s.log.Warningln("GetVideoIMDBInfoFromLocal", videoFPath, err)
+		s.log.Errorln(s.GetSupplierName(), videoFPath, "GetIMDBInfo", err)
 		return nil, err
 	}
-	if len(imdbInfo.Description) <= 0 {
-		// 需要去外网获去补全信息,然后更新本地的信息
-		t, err := imdb_helper.GetVideoInfoFromIMDBWeb(imdbInfo4Video, s.settings.AdvancedSettings.ProxySettings)
-		if err != nil {
-			s.log.Errorln("GetVideoInfoFromIMDBWeb,", imdbInfo4Video.Title, err)
-			return nil, err
-		}
-		imdbInfo.Year = t.Year
-		imdbInfo.AKA = t.AKA
-		imdbInfo.Description = t.Description
-		imdbInfo.Languages = t.Languages
 
-		dao.GetDb().Save(imdbInfo)
-	}
 	// 需要找到中文名称去搜索
-	keyWord := ""
-	for _, akaWord := range imdbInfo.AKA {
-		if language.IsChs(akaWord) == true {
-			keyWord = akaWord
-			break
-		}
-	}
+	keyWord := imdbInfo.GetChineseNameFromAKA()
 	if keyWord == "" {
 		return nil, errors.New("No Chinese name")
 	}
-
 	if isMovie == false {
 		// 连续剧需要额外补充 S01E01 这样的信息
 		infoFromFileName, err := decode.GetVideoInfoFromFileName(videoFPath)
 		if err != nil {
 			return nil, err
 		}
-		keyWord += my_util.GetEpisodeKeyName(infoFromFileName.Season, infoFromFileName.Episode)
+		keyWord += " " + my_util.GetEpisodeKeyName(infoFromFileName.Season, infoFromFileName.Episode, true)
 	}
 
 	var searchSubResult SearchSubResult
@@ -254,15 +225,12 @@ func (s *Supplier) getSubByKeyWord(keyword string) (SearchSubResult, error) {
 		return searchSubResult, err
 	}
 	resp, err := httpClient.R().
-		//SetQueryParams(map[string]string{
-		//	"token": s.settings.SubtitleSources.AssrtSettings.Token,
-		//	"q":     url.QueryEscape(keyword),
-		//	"cnt":   "15",
-		//	"pos":   "0",
-		//}).
 		SetHeader("Content-Type", "application/x-www-form-urlencoded").
 		SetResult(&searchSubResult).
-		Get(s.settings.AdvancedSettings.SuppliersSettings.Assrt.RootUrl + "/sub/search?q=" + tt + "&cnt=15&pos=0" + "&token=" + s.settings.SubtitleSources.AssrtSettings.Token)
+		Get(s.settings.AdvancedSettings.SuppliersSettings.Assrt.RootUrl +
+			"/sub/search?q=" + tt +
+			"&cnt=15&pos=0" +
+			"&token=" + s.settings.SubtitleSources.AssrtSettings.Token)
 	if err != nil {
 		if resp != nil {
 			s.log.Errorln(s.GetSupplierName(), "NewHttpClient:", keyword, err.Error())
@@ -299,6 +267,31 @@ func (s *Supplier) getSubDetail(subID int) (OneSubDetail, error) {
 	return subDetail, nil
 }
 
+func (s *Supplier) getUserInfo() (UserInfo, error) {
+
+	var userInfo UserInfo
+
+	httpClient, err := my_util.NewHttpClient(s.settings.AdvancedSettings.ProxySettings)
+	if err != nil {
+		return userInfo, err
+	}
+	resp, err := httpClient.R().
+		SetQueryParams(map[string]string{
+			"token": s.settings.SubtitleSources.AssrtSettings.Token,
+		}).
+		SetResult(&userInfo).
+		Get(s.settings.AdvancedSettings.SuppliersSettings.Assrt.RootUrl + "/user/quota")
+	if err != nil {
+		if resp != nil {
+			s.log.Errorln(s.GetSupplierName(), "NewHttpClient:", err.Error())
+			notify_center.Notify.Add(s.GetSupplierName()+" NewHttpClient", fmt.Sprintf("resp: %s, error: %s", resp.String(), err.Error()))
+		}
+		return userInfo, err
+	}
+
+	return userInfo, nil
+}
+
 type SearchSubResult struct {
 	Sub struct {
 		Action string `json:"action"`
@@ -370,3 +363,12 @@ type OneSubDetail struct {
 	} `json:"sub"`
 	Status int `json:"status"`
 }
+
+type UserInfo struct {
+	User struct {
+		Action string `json:"action"`
+		Result string `json:"result"`
+		Quota  int    `json:"quota"`
+	} `json:"user"`
+	Status int `json:"status"`
+}

+ 21 - 6
internal/logic/sub_supplier/assrt/assrt_test.go

@@ -8,16 +8,23 @@ import (
 	"testing"
 )
 
+var assrtInstance *Supplier
+
+func defInstance() {
+	nowSettings := settings.NewSettings()
+	nowSettings.SubtitleSources.AssrtSettings.Token = "xxxx"
+	assrtInstance = NewSupplier(file_downloader.NewFileDownloader(cache_center.NewCacheCenter("test", nowSettings, log_helper.GetLogger4Tester())))
+}
+
 func TestSupplier_getSubListFromFile(t *testing.T) {
 
 	//videoFPath := "X:\\电影\\失控玩家 (2021)\\失控玩家 (2021).mp4"
-	videoFPath := "X:\\电影\\失控玩家 (2021)\\失控玩家 (2021).mp4"
-	//videoFPath := "X:\\连续剧\\风骚律师 (2015)\\Season 6\\Better Call Saul - S06E05 - Black and Blue WEBDL-1080p.mkv"
+	//isMovie := true
+	defInstance()
+	videoFPath := "X:\\连续剧\\风骚律师 (2015)\\Season 6\\Better Call Saul - S06E05 - Black and Blue WEBDL-1080p.mkv"
+	isMovie := false
 
-	nowSettings := settings.NewSettings()
-	nowSettings.SubtitleSources.AssrtSettings.Token = "xxx"
-	assrtInstance := NewSupplier(file_downloader.NewFileDownloader(cache_center.NewCacheCenter("test", nowSettings, log_helper.GetLogger4Tester())))
-	got, err := assrtInstance.getSubListFromFile(videoFPath, true)
+	got, err := assrtInstance.getSubListFromFile(videoFPath, isMovie)
 	if err != nil {
 		t.Error(err)
 	}
@@ -25,3 +32,11 @@ func TestSupplier_getSubListFromFile(t *testing.T) {
 		println(i, info.Name, info.FileUrl)
 	}
 }
+
+func TestSupplier_CheckAlive(t *testing.T) {
+
+	defInstance()
+	bok, speed := assrtInstance.CheckAlive()
+	println(bok, speed)
+
+}

+ 45 - 0
internal/models/imdb_info.go

@@ -1,5 +1,10 @@
 package models
 
+import (
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/language"
+	"github.com/longbridgeapp/opencc"
+)
+
 type IMDBInfo struct {
 	IMDBID        string         `gorm:"primaryKey" json:"imdb_id"  binding:"required"`                   // IMDB ID
 	Name          string         `json:"name" binding:"required"`                                         // 视频名称
@@ -15,3 +20,43 @@ type IMDBInfo struct {
 func NewIMDBInfo(IMDBID string, name string, year int, description string, languages StringList, AKA StringList) *IMDBInfo {
 	return &IMDBInfo{IMDBID: IMDBID, Name: name, Year: year, Description: description, Languages: languages, AKA: AKA, VideoSubInfos: make([]VideoSubInfo, 0)}
 }
+
+func (i *IMDBInfo) GetChineseNameFromAKA() string {
+
+	if len(i.AKA) == 0 {
+		return ""
+	}
+	chsName := ""
+	chtName := ""
+	for _, akaWord := range i.AKA {
+		// 0 不是简体和繁体,1 是简体,2 是繁体
+		if language.WhichChineseType(akaWord) == 1 {
+			chsName = akaWord
+			break
+		} else if language.WhichChineseType(akaWord) == 2 {
+			chtName = akaWord
+			break
+		}
+	}
+	// 如果简体找到了,那么就返回
+	if chsName != "" {
+		return chsName
+	}
+	// 如果繁体找到了,那么进行一次简体转换
+	if chtName != "" {
+
+		t2s, err := opencc.New("t2s")
+		if err != nil {
+			return ""
+		}
+		// 繁体转简体
+		newChs, err := t2s.Convert(chtName)
+		if err != nil {
+			return ""
+		}
+
+		return newChs
+	}
+
+	return ""
+}

+ 19 - 4
internal/pkg/chs_cht_changer/chs_cht_changer.go

@@ -1,7 +1,7 @@
 package chs_cht_changer
 
 import (
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/language"
+	"github.com/longbridgeapp/opencc"
 	"os"
 )
 
@@ -17,11 +17,26 @@ func Process(srcSubFileFPath string, desChineseLanguageType int) error {
 	orgString := string(fBytes)
 	outString := ""
 	if desChineseLanguageType == 0 {
-		// 简体
-		outString = language.ChDict.Read(orgString)
+		t2s, err := opencc.New("t2s")
+		if err != nil {
+			return err
+		}
+		// 繁体转简体
+		outString, err = t2s.Convert(orgString)
+		if err != nil {
+			return err
+		}
 	} else {
 		// 繁体
-		outString = language.ChDict.ReadReverse(orgString)
+		s2t, err := opencc.New("s2t")
+		if err != nil {
+			return err
+		}
+		// 简体转繁体
+		outString, err = s2t.Convert(orgString)
+		if err != nil {
+			return err
+		}
 	}
 
 	err = os.WriteFile(srcSubFileFPath, []byte(outString), os.ModePerm)

+ 8 - 0
internal/pkg/chs_cht_changer/chs_cht_changer_test.go

@@ -32,6 +32,14 @@ func TestProcess(t *testing.T) {
 			srcSubFileFPath:        filepath.Join(rootDir, "机动战士Z高达Ⅲ:星辰的鼓动是爱 (2006) 1080p TrueHD.chinese(繁).ass"),
 			desChineseLanguageType: 0,
 		}, wantErr: false},
+		{name: "3", args: args{
+			srcSubFileFPath:        filepath.Join(rootDir, "Better Call Saul - S06E04 - Hit and Run WEBDL-1080p.chinese(简,shooter).srt"),
+			desChineseLanguageType: 1,
+		}, wantErr: false},
+		{name: "4", args: args{
+			srcSubFileFPath:        filepath.Join(rootDir, "Better Call Saul - S06E04 - Hit and Run WEBDL-1080p.chinese(简英,shooter).ass"),
+			desChineseLanguageType: 1,
+		}, wantErr: false},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {

+ 39 - 0
internal/pkg/imdb_helper/imdb.go

@@ -5,6 +5,7 @@ import (
 	"github.com/StalkR/imdb"
 	"github.com/allanpk716/ChineseSubFinder/internal/dao"
 	"github.com/allanpk716/ChineseSubFinder/internal/models"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/decode"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/notify_center"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/settings"
@@ -139,3 +140,41 @@ func IsChineseVideo(log *logrus.Logger, imdbInfo types.VideoIMDBInfo, _proxySett
 		return false, localIMDBInfo, nil
 	}
 }
+
+// GetIMDBInfo 先从本地拿缓存,如果没有就从 Web 获取
+func GetIMDBInfo(log *logrus.Logger, videoFPath string, isMovie bool, _proxySettings ...*settings.ProxySettings) (*models.IMDBInfo, error) {
+
+	var err error
+	var imdbInfo4Video types.VideoIMDBInfo
+	if isMovie == true {
+		imdbInfo4Video, err = decode.GetImdbInfo4Movie(videoFPath)
+	} else {
+		imdbInfo4Video, err = decode.GetSeriesSeasonImdbInfoFromEpisode(videoFPath)
+	}
+	if err != nil {
+		// 如果找不到当前电影的 IMDB Info 本地文件,那么就跳过
+		log.Warningln("getSubListFromFile", videoFPath, err)
+		return nil, err
+	}
+	imdbInfo, err := GetVideoIMDBInfoFromLocal(log, imdbInfo4Video)
+	if err != nil {
+		log.Warningln("GetVideoIMDBInfoFromLocal", videoFPath, err)
+		return nil, err
+	}
+	if len(imdbInfo.Description) <= 0 {
+		// 需要去外网获去补全信息,然后更新本地的信息
+		t, err := GetVideoInfoFromIMDBWeb(imdbInfo4Video, _proxySettings...)
+		if err != nil {
+			log.Errorln("GetVideoInfoFromIMDBWeb,", imdbInfo4Video.Title, err)
+			return nil, err
+		}
+		imdbInfo.Year = t.Year
+		imdbInfo.AKA = t.AKA
+		imdbInfo.Description = t.Description
+		imdbInfo.Languages = t.Languages
+
+		dao.GetDb().Save(imdbInfo)
+	}
+
+	return imdbInfo, nil
+}

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

@@ -14,7 +14,7 @@ func TestGetVideoInfoFromIMDB(t *testing.T) {
 	//imdbID := "tt6468322" 	// 纸钞屋
 	//imdbID := "tt15299712" // 云南虫谷
 	imdbID := "tt6856242" // The King`s Man
-	imdbInfo, err := getVideoInfoFromIMDBWeb(types.VideoIMDBInfo{ImdbId: imdbID})
+	imdbInfo, err := GetVideoInfoFromIMDBWeb(types.VideoIMDBInfo{ImdbId: imdbID})
 	if err != nil {
 		t.Fatal(err)
 	}

+ 6 - 3
internal/pkg/language/whatlanggo.go

@@ -6,17 +6,20 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/types/subparser"
 )
 
-func IsChs(inputString string) bool {
+// WhichChineseType 是简体中文(1)还是繁体中文(2),如果都不是,那么是 0
+func WhichChineseType(inputString string) int {
 
 	info := whatlanggo.DetectWithOptions(inputString, GetLangOptions())
 	// 是否是中文(简体、繁体)
 	if info.Lang == whatlanggo.Cmn {
 		// 判断是简体还是繁体
 		if ChDict.IsChs(inputString, 0.9) == true {
-			return true
+			return 1
+		} else {
+			return 2
 		}
 	}
-	return false
+	return 0
 }
 
 // GetLangOptions 语言识别的 Options Whitelist

+ 7 - 2
internal/pkg/my_util/util.go

@@ -400,8 +400,13 @@ func IsWantedVideoExtDef(fileName string) bool {
 	return bFound
 }
 
-func GetEpisodeKeyName(season, eps int) string {
-	return "S" + strconv.Itoa(season) + "E" + strconv.Itoa(eps)
+func GetEpisodeKeyName(season, eps int, zerofill ...bool) string {
+
+	if len(zerofill) < 1 || zerofill[0] == false {
+		return "S" + strconv.Itoa(season) + "E" + strconv.Itoa(eps)
+	} else {
+		return fmt.Sprintf("S%02dE%02d", season, eps)
+	}
 }
 
 // CopyFile copies a single file from src to dst

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

@@ -1,5 +1,6 @@
 package settings
 
 type AssrtSettings struct {
-	Token string `json:"token"`
+	Enabled bool   `json:"enabled"`
+	Token   string `json:"token"`
 }