Browse Source

重构,调整项目结构

Signed-off-by: allan716 <[email protected]>
allan716 4 years ago
parent
commit
e2778aa4a5

+ 2 - 1
cmd/chinesesubfinder/main.go

@@ -4,6 +4,7 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_timeline_fixer"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	config2 "github.com/allanpk716/ChineseSubFinder/internal/pkg/config"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/hot_fix"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/notify_center"
@@ -29,7 +30,7 @@ and
 implement getSpeFileName() in internal/logic/forced_scan_and_down_sub/forced_scan_and_down_sub.go`)
 	}
 
-	config = pkg.GetConfig()
+	config = config2.GetConfig()
 }
 
 func main() {

+ 2 - 2
internal/downloader.go

@@ -118,8 +118,8 @@ func (d *Downloader) GetUpdateVideoListFromEmby(movieRootDir, seriesRootDir stri
 	log_helper.GetLogger().Debugln("GetUpdateVideoListFromEmby - DebugInfo - seriesSubNeedDlMap End")
 
 	log_helper.GetLogger().Debugln("GetUpdateVideoListFromEmby - DebugInfo - movieFileFullPathList Start")
-	for s := range d.movieFileFullPathList {
-		log_helper.GetLogger().Debugln(s)
+	for s, value := range d.movieFileFullPathList {
+		log_helper.GetLogger().Debugln(s, value)
 	}
 	log_helper.GetLogger().Debugln("GetUpdateVideoListFromEmby - DebugInfo - movieFileFullPathList End")
 

+ 4 - 4
internal/downloader_test.go

@@ -1,7 +1,7 @@
 package internal
 
 import (
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/config"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_formatter"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	"testing"
@@ -18,7 +18,7 @@ func TestDownloader_DownloadSub4Movie(t *testing.T) {
 	//dirRoot := "X:\\电影\\冰海陷落 (2018)"
 	dirRoot := "X:\\电影\\The Boss Baby Family Business (2021)"
 	//dirRoot := "X:\\电影"
-	config := pkg.GetConfig()
+	config := config.GetConfig()
 	dl := NewDownloader(sub_formatter.GetSubFormatter(config.SubNameFormatter), types.ReqParam{
 		SaveMultiSub:    true,
 		SubTypePriority: 1,
@@ -49,7 +49,7 @@ func TestDownloader_DownloadSub4Series(t *testing.T) {
 	//dirRoot := "X:\\连续剧\\黄石 (2018)"
 	//dirRoot := "X:\\连续剧"
 
-	config := pkg.GetConfig()
+	config := config.GetConfig()
 	// 如果需要调试 Emby 一定需要 dirRoot := "X:\\连续剧"
 	dl := NewDownloader(sub_formatter.GetSubFormatter(config.SubNameFormatter), types.ReqParam{
 		SaveMultiSub:    true,
@@ -68,7 +68,7 @@ func TestDownloader_DownloadSub4Series(t *testing.T) {
 
 func TestDownloader_GetUpdateVideoListFromEmby(t *testing.T) {
 	var err error
-	config := pkg.GetConfig()
+	config := config.GetConfig()
 	dl := NewDownloader(sub_formatter.GetSubFormatter(config.SubNameFormatter), types.ReqParam{
 		SaveMultiSub:    true,
 		SubTypePriority: 1,

+ 4 - 4
internal/logic/emby_helper/embyhelper_test.go

@@ -1,12 +1,12 @@
 package emby_helper
 
 import (
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/config"
 	"testing"
 )
 
 func TestEmbyHelper_GetRecentlyAddVideoList(t *testing.T) {
-	config := pkg.GetConfig()
+	config := config.GetConfig()
 	em := NewEmbyHelper(config.EmbyConfig)
 	movieList, seriesList, err := em.GetRecentlyAddVideoList(config.MovieFolder, config.SeriesFolder)
 	if err != nil {
@@ -17,7 +17,7 @@ func TestEmbyHelper_GetRecentlyAddVideoList(t *testing.T) {
 }
 
 func TestEmbyHelper_RefreshEmbySubList(t *testing.T) {
-	config := pkg.GetConfig()
+	config := config.GetConfig()
 	em := NewEmbyHelper(config.EmbyConfig)
 	bok, err := em.RefreshEmbySubList()
 	if err != nil {
@@ -27,7 +27,7 @@ func TestEmbyHelper_RefreshEmbySubList(t *testing.T) {
 }
 
 func TestEmbyHelper_GetInternalEngSubAndExSub(t *testing.T) {
-	config := pkg.GetConfig()
+	config := config.GetConfig()
 	em := NewEmbyHelper(config.EmbyConfig)
 	// 81873 -- R&M - S05E01
 	// R&M S05E10  2 org english, 5 简英 	145499

+ 2 - 2
internal/logic/sub_supplier/subhd/subhd_test.go

@@ -2,7 +2,7 @@ package subhd
 
 import (
 	series_helper2 "github.com/allanpk716/ChineseSubFinder/internal/logic/series_helper"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/config"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	"testing"
 )
@@ -78,7 +78,7 @@ func TestSupplier_getSubListFromKeyword4Movie(t *testing.T) {
 
 func getReqParam() types.ReqParam {
 
-	config := pkg.GetConfig()
+	config := config.GetConfig()
 	req := types.ReqParam{}
 	if config.UseProxy == true {
 		req.HttpProxy = config.HttpProxy

+ 3 - 3
internal/logic/sub_timeline_fixer/sub_timeline_fixer_helper_test.go

@@ -1,13 +1,13 @@
 package sub_timeline_fixer
 
 import (
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/config"
 	"testing"
 )
 
 func TestSubTimelineFixerHelper_FixRecentlyItemsSubTimeline(t *testing.T) {
 	// 单独执行这个,第一次是有效的,第二次,就没得效果了,原因是已经替换字幕了啊,当然就不会修正了啊。你懂的
-	config := pkg.GetConfig()
+	config := config.GetConfig()
 	fixer := NewSubTimelineFixerHelper(config.EmbyConfig, config.SubTimelineFixerConfig)
 	err := fixer.FixRecentlyItemsSubTimeline(config.MovieFolder, config.SeriesFolder)
 	if err != nil {
@@ -23,7 +23,7 @@ func TestSubTimelineFixerHelper_fixOneVideoSub(t *testing.T) {
 	// 81873 -- R&M - S05E01
 	// 145499 -- R&M - S05E10
 	// 178071 -- The Night House
-	config := pkg.GetConfig()
+	config := config.GetConfig()
 	fixer := NewSubTimelineFixerHelper(config.EmbyConfig, config.SubTimelineFixerConfig)
 	err := fixer.fixOneVideoSub("178071", "")
 	if err != nil {

+ 3 - 2
internal/pkg/config.go → internal/pkg/config/config.go

@@ -1,7 +1,8 @@
-package pkg
+package config
 
 import (
 	"errors"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/global_value"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	"github.com/spf13/viper"
 	"strings"
@@ -21,7 +22,7 @@ func GetConfig() *types.Config {
 		}
 		// 读取用户自定义的视频后缀名列表
 		for _, customExt := range strings.Split(config.CustomVideoExts, ",") {
-			customVideoExts = append(customVideoExts, "."+customExt)
+			global_value.CustomVideoExts = append(global_value.CustomVideoExts, "."+customExt)
 		}
 
 		// 这里进行 Default 值的判断

+ 9 - 9
internal/pkg/emby_api/emby_api_test.go

@@ -1,13 +1,13 @@
 package emby_api
 
 import (
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/config"
 	"testing"
 )
 
 func TestEmbyHelper_GetRecentlyItems(t *testing.T) {
 
-	em := NewEmbyApi(pkg.GetConfig().EmbyConfig)
+	em := NewEmbyApi(config.GetConfig().EmbyConfig)
 	items, err := em.GetRecentlyItems()
 	if err != nil {
 		t.Fatal(err)
@@ -19,7 +19,7 @@ func TestEmbyHelper_GetRecentlyItems(t *testing.T) {
 }
 
 func TestEmbyHelper_GetItemsAncestors(t *testing.T) {
-	em := NewEmbyApi(pkg.GetConfig().EmbyConfig)
+	em := NewEmbyApi(config.GetConfig().EmbyConfig)
 	items, err := em.GetItemAncestors("96564")
 	if err != nil {
 		t.Fatal(err)
@@ -33,7 +33,7 @@ func TestEmbyHelper_GetItemsAncestors(t *testing.T) {
 }
 
 func TestEmbyHelper_GetItemVideoInfoByUserId(t *testing.T) {
-	em := NewEmbyApi(pkg.GetConfig().EmbyConfig)
+	em := NewEmbyApi(config.GetConfig().EmbyConfig)
 	// 95813 -- 命运夜
 	// 96564 -- The Bad Batch - S01E11
 	// 108766 -- R&M - S05E06
@@ -47,7 +47,7 @@ func TestEmbyHelper_GetItemVideoInfoByUserId(t *testing.T) {
 }
 
 func TestEmbyHelper_UpdateVideoSubList(t *testing.T) {
-	em := NewEmbyApi(pkg.GetConfig().EmbyConfig)
+	em := NewEmbyApi(config.GetConfig().EmbyConfig)
 	// 95813 -- 命运夜
 	// 96564 -- The Bad Batch - S01E11
 	// 81873 -- R&M - S05E01
@@ -63,7 +63,7 @@ func TestEmbyHelper_UpdateVideoSubList(t *testing.T) {
 }
 
 func TestEmbyHelper_GetUserIdList(t *testing.T) {
-	em := NewEmbyApi(pkg.GetConfig().EmbyConfig)
+	em := NewEmbyApi(config.GetConfig().EmbyConfig)
 	userIds, err := em.GetUserIdList()
 	if err != nil {
 		t.Fatal(err)
@@ -74,7 +74,7 @@ func TestEmbyHelper_GetUserIdList(t *testing.T) {
 }
 
 func TestEmbyHelper_GetItemVideoInfo(t *testing.T) {
-	em := NewEmbyApi(pkg.GetConfig().EmbyConfig)
+	em := NewEmbyApi(config.GetConfig().EmbyConfig)
 	// 95813 -- 命运夜
 	// 96564 -- The Bad Batch - S01E11
 	// R&M S05E10  2 org english, 5 简英 145499
@@ -90,7 +90,7 @@ func TestEmbyHelper_GetItemVideoInfo(t *testing.T) {
 }
 
 func TestEmbyApi_GetSubFileData(t *testing.T) {
-	em := NewEmbyApi(pkg.GetConfig().EmbyConfig)
+	em := NewEmbyApi(config.GetConfig().EmbyConfig)
 	// R&M S05E10  2 org english, 5 简英					"145499", "c4678509adb72a8b5034bdac2f1fccde", "5", ".ass"
 	// 基地 S01E03		2=eng 	6=chi 	45=简英			"166840", "d6c68ec6097aeceb9f5c1d82add66213", "2", ".ass"
 	// 基地 S01E04		2=eng 	6=chi 	45=简英			"173354", "c08f514cc1708f3fadea56e489da33db", "2", ".ass"
@@ -107,7 +107,7 @@ func TestEmbyApi_GetSubFileData(t *testing.T) {
 
 func TestEmbyApi_RefreshRecentlyVideoInfo(t *testing.T) {
 
-	em := NewEmbyApi(pkg.GetConfig().EmbyConfig)
+	em := NewEmbyApi(config.GetConfig().EmbyConfig)
 	err := em.RefreshRecentlyVideoInfo()
 	if err != nil {
 		t.Fatal("RefreshRecentlyVideoInfo() error = " + err.Error())

+ 10 - 0
internal/pkg/global_value/globalvalue.go

@@ -0,0 +1,10 @@
+package global_value
+
+// util.go
+var (
+	DefDebugFolder  = ""
+	DefTmpFolder    = ""
+	WantedExtMap    = make(map[string]string) // 人工确认的需要监控的视频后缀名
+	DefExtMap       = make(map[string]string) // 内置支持的视频后缀名列表
+	CustomVideoExts = make([]string, 0)       // 用户额外自定义的视频后缀名列表
+)

+ 0 - 10
internal/pkg/globalvalue.go

@@ -1,10 +0,0 @@
-package pkg
-
-// util.go
-var (
-	defDebugFolder  = ""
-	defTmpFolder    = ""
-	wantedExtMap    = make(map[string]string) // 人工确认的需要监控的视频后缀名
-	defExtMap       = make(map[string]string) // 内置支持的视频后缀名列表
-	customVideoExts = make([]string, 0)       // 用户额外自定义的视频后缀名列表
-)

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

@@ -1,7 +1,7 @@
 package log_helper
 
 import (
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/config"
 	rotatelogs "github.com/lestrrat-go/file-rotatelogs"
 	"github.com/sirupsen/logrus"
 	easy "github.com/t-tomalak/logrus-easy-formatter"
@@ -46,7 +46,7 @@ func GetLogger() *logrus.Logger {
 	logOnce.Do(func() {
 
 		var level logrus.Level
-		if pkg.GetConfig().DebugMode == true {
+		if config.GetConfig().DebugMode == true {
 			level = logrus.DebugLevel
 		} else {
 			level = logrus.InfoLevel

+ 2 - 2
internal/pkg/notify_center/NotifyCenter_test.go

@@ -1,13 +1,13 @@
 package notify_center
 
 import (
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/config"
 	"testing"
 )
 
 func TestNewNotifyCenter(t *testing.T) {
 
-	config := pkg.GetConfig()
+	config := config.GetConfig()
 	center := NewNotifyCenter(config.WhenSubSupplierInvalidWebHook)
 	center.Add("groupName", "Info asd 哈哈")
 	center.Send()

+ 19 - 18
internal/pkg/util.go

@@ -3,6 +3,7 @@ package pkg
 import (
 	"fmt"
 	"github.com/allanpk716/ChineseSubFinder/internal/common"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/global_value"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	browser "github.com/allanpk716/fake-useragent"
@@ -102,32 +103,32 @@ func AddBaseUrl(baseUrl, url string) string {
 }
 
 func GetDebugFolder() (string, error) {
-	if defDebugFolder == "" {
+	if global_value.DefDebugFolder == "" {
 		nowProcessRoot, _ := os.Getwd()
 		nowProcessRoot = filepath.Join(nowProcessRoot, common.DebugFolder)
 		err := os.MkdirAll(nowProcessRoot, os.ModePerm)
 		if err != nil {
 			return "", err
 		}
-		defDebugFolder = nowProcessRoot
+		global_value.DefDebugFolder = nowProcessRoot
 		return nowProcessRoot, err
 	}
-	return defDebugFolder, nil
+	return global_value.DefDebugFolder, nil
 }
 
 // GetRootTmpFolder 获取缓存的根目录,每一个视频的缓存将在其中额外新建子集文件夹
 func GetRootTmpFolder() (string, error) {
-	if defTmpFolder == "" {
+	if global_value.DefTmpFolder == "" {
 		nowProcessRoot, _ := os.Getwd()
 		nowProcessRoot = filepath.Join(nowProcessRoot, common.TmpFolder)
 		err := os.MkdirAll(nowProcessRoot, os.ModePerm)
 		if err != nil {
 			return "", err
 		}
-		defTmpFolder = nowProcessRoot
+		global_value.DefTmpFolder = nowProcessRoot
 		return nowProcessRoot, err
 	}
-	return defTmpFolder, nil
+	return global_value.DefTmpFolder, nil
 }
 
 // ClearRootTmpFolder 清理缓存的根目录,将里面的子文件夹一并清理
@@ -276,23 +277,23 @@ func SearchMatchedVideoFile(dir string) ([]string, error) {
 // IsWantedVideoExtDef 后缀名是否符合规则
 func IsWantedVideoExtDef(fileName string) bool {
 
-	if len(wantedExtMap) < 1 {
-		defExtMap[common.VideoExtMp4] = common.VideoExtMp4
-		defExtMap[common.VideoExtMkv] = common.VideoExtMkv
-		defExtMap[common.VideoExtRmvb] = common.VideoExtRmvb
-		defExtMap[common.VideoExtIso] = common.VideoExtIso
+	if len(global_value.WantedExtMap) < 1 {
+		global_value.DefExtMap[common.VideoExtMp4] = common.VideoExtMp4
+		global_value.DefExtMap[common.VideoExtMkv] = common.VideoExtMkv
+		global_value.DefExtMap[common.VideoExtRmvb] = common.VideoExtRmvb
+		global_value.DefExtMap[common.VideoExtIso] = common.VideoExtIso
 
-		wantedExtMap[common.VideoExtMp4] = common.VideoExtMp4
-		wantedExtMap[common.VideoExtMkv] = common.VideoExtMkv
-		wantedExtMap[common.VideoExtRmvb] = common.VideoExtRmvb
-		wantedExtMap[common.VideoExtIso] = common.VideoExtIso
+		global_value.WantedExtMap[common.VideoExtMp4] = common.VideoExtMp4
+		global_value.WantedExtMap[common.VideoExtMkv] = common.VideoExtMkv
+		global_value.WantedExtMap[common.VideoExtRmvb] = common.VideoExtRmvb
+		global_value.WantedExtMap[common.VideoExtIso] = common.VideoExtIso
 
-		for _, videoExt := range customVideoExts {
-			wantedExtMap[videoExt] = videoExt
+		for _, videoExt := range global_value.CustomVideoExts {
+			global_value.WantedExtMap[videoExt] = videoExt
 		}
 	}
 	fileExt := strings.ToLower(filepath.Ext(fileName))
-	_, bFound := wantedExtMap[fileExt]
+	_, bFound := global_value.WantedExtMap[fileExt]
 	return bFound
 }