Browse Source

暂时移除 subhd 的下载逻辑

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

+ 1 - 1
.github/workflows/manual_test.yml

@@ -33,4 +33,4 @@ jobs:
           platforms: linux/amd64
           push: true
           tags: |
-            allanpk716/chinesesubfinder:dev1014b02
+            allanpk716/chinesesubfinder:dev1014b03

+ 17 - 16
cmd/chinesesubfinder/main.go

@@ -162,22 +162,6 @@ func DownLoadStart(httpProxy string) {
 		notify_center.Notify.Send()
 		pkg.CloseChrome()
 		rod_helper.Clear()
-		// 开始字幕的统一校正
-		log.Infoln("Auto Fix Sub Timeline Start...")
-		fixer := sub_timeline_fixer.NewSubTimelineFixerHelper(config.EmbyConfig, config.SubTimelineFixerConfig)
-		err := fixer.FixRecentlyItemsSubTimeline(config.MovieFolder, config.SeriesFolder)
-		if err != nil {
-			log.Errorln("FixRecentlyItemsSubTimeline", err)
-			return
-		}
-		log.Infoln("Auto Fix Sub Timeline End")
-		// 再次刷新
-		// 刷新 Emby 的字幕,下载完毕字幕了,就统一刷新一下
-		err = downloader.RefreshEmbySubList()
-		if err != nil {
-			log.Errorln("RefreshEmbySubList", err)
-			return
-		}
 	}()
 
 	log.Infoln("Download One Started...")
@@ -216,6 +200,23 @@ func DownLoadStart(httpProxy string) {
 		log.Errorln("RefreshEmbySubList", err)
 		return
 	}
+
+	// 开始字幕的统一校正
+	log.Infoln("Auto Fix Sub Timeline Start...")
+	fixer := sub_timeline_fixer.NewSubTimelineFixerHelper(config.EmbyConfig, config.SubTimelineFixerConfig)
+	err = fixer.FixRecentlyItemsSubTimeline(config.MovieFolder, config.SeriesFolder)
+	if err != nil {
+		log.Errorln("FixRecentlyItemsSubTimeline", err)
+		return
+	}
+	log.Infoln("Auto Fix Sub Timeline End")
+	// 再次刷新
+	// 刷新 Emby 的字幕,下载完毕字幕了,就统一刷新一下
+	err = downloader.RefreshEmbySubList()
+	if err != nil {
+		log.Errorln("RefreshEmbySubList", err)
+		return
+	}
 }
 
 var (

+ 1 - 1
internal/common/urls.go

@@ -4,7 +4,7 @@ const (
 	SubXunLeiRootUrl  = "http://sub.xmp.sandai.net:8000/subxl/%s.json"
 	SubShooterRootUrl = "https://www.shooter.cn/api/subapi.php"
 
-	SubZiMuKuRootUrl   = "http://zmk.pw"
+	SubZiMuKuRootUrl   = "https://zmk.pw"
 	SubZiMuKuSearchUrl = SubZiMuKuRootUrl + "/search"
 
 	SubSubHDRootUrl   = "https://subhd.tv"

+ 2 - 3
internal/downloader.go

@@ -9,7 +9,6 @@ import (
 	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"
@@ -179,7 +178,7 @@ func (d Downloader) DownloadSub4Movie(dir string) error {
 		// -----------------------------------------------------
 		// 构建每个字幕站点下载者的实例
 		var subSupplierHub = subSupplier.NewSubSupplierHub(
-			subhd.NewSupplier(d.reqParam),
+			//subhd.NewSupplier(d.reqParam),
 			zimuku.NewSupplier(d.reqParam),
 			xunlei.NewSupplier(d.reqParam),
 			shooter.NewSupplier(d.reqParam),
@@ -271,7 +270,7 @@ func (d Downloader) DownloadSub4Series(dir string) error {
 		var subSupplierHub *subSupplier.SubSupplierHub
 		subSupplierHub = subSupplier.NewSubSupplierHub(
 			zimuku.NewSupplier(d.reqParam),
-			subhd.NewSupplier(d.reqParam),
+			//subhd.NewSupplier(d.reqParam),
 			xunlei.NewSupplier(d.reqParam),
 			shooter.NewSupplier(d.reqParam),
 		)

+ 22 - 22
internal/logic/sub_timeline_fixer/sub_timeline_fixer_helper.go

@@ -112,7 +112,7 @@ func (s SubTimelineFixerHelper) fixOneVideoSub(videoId string, videoRootPath str
 		if strings.Contains(exSubInfo.FileName, sub_timeline_fixer.FixMask) == true {
 			continue
 		}
-		bFound, subFixInfos, err := s.fixSubTimeline(internalEngSub[inSelectSubIndex], exSubInfo)
+		bFound, subFixInfos, subNewName, err := s.fixSubTimeline(internalEngSub[inSelectSubIndex], exSubInfo)
 		if err != nil {
 			return err
 		}
@@ -125,28 +125,26 @@ func (s SubTimelineFixerHelper) fixOneVideoSub(videoId string, videoRootPath str
 		}
 		for _, info := range subFixInfos {
 			// 写入 fix 后的字幕文件覆盖之前的字幕文件
-			desFixedSubFullName := path.Join(videoRootPath, info.FileName)
+			desFixedSubFullName := path.Join(videoRootPath, subNewName)
+			err = s.saveSubFile(desFixedSubFullName, info.FixContent)
+			if err != nil {
+				return err
+			}
 			log_helper.GetLogger().Debugln("Sub Timeline fixed:", desFixedSubFullName)
-			continue
-			//err = s.saveSubFile(desFixedSubFullName, info.FixContent)
-			//if err != nil {
-			//	return err
-			//}
-			//log_helper.GetLogger().Debugln("Sub Timeline fixed:", desFixedSubFullName)
 		}
 	}
 
 	return nil
 }
 
-func (s SubTimelineFixerHelper) fixSubTimeline(enSubFile emby.SubInfo, ch_enSubFile emby.SubInfo) (bool, []sub_timeline_fixer.SubFixInfo, error) {
-
+func (s SubTimelineFixerHelper) fixSubTimeline(enSubFile emby.SubInfo, ch_enSubFile emby.SubInfo) (bool, []sub_timeline_fixer.SubFixInfo, string, error) {
+	fixedSubName := ""
 	bFind, infoBase, err := s.subParserHub.DetermineFileTypeFromBytes(enSubFile.Content, enSubFile.Ext)
 	if err != nil {
-		return false, nil, err
+		return false, nil, fixedSubName, err
 	}
 	if bFind == false {
-		return false, nil, nil
+		return false, nil, fixedSubName, nil
 	}
 	infoBase.Name = enSubFile.FileName
 	/*
@@ -157,10 +155,10 @@ func (s SubTimelineFixerHelper) fixSubTimeline(enSubFile emby.SubInfo, ch_enSubF
 
 	bFind, infoSrc, err := s.subParserHub.DetermineFileTypeFromBytes(ch_enSubFile.Content, ch_enSubFile.Ext)
 	if err != nil {
-		return false, nil, err
+		return false, nil, fixedSubName, err
 	}
 	if bFind == false {
-		return false, nil, nil
+		return false, nil, fixedSubName, nil
 	}
 	infoSrc.Name = ch_enSubFile.FileName
 	/*
@@ -177,17 +175,17 @@ func (s SubTimelineFixerHelper) fixSubTimeline(enSubFile emby.SubInfo, ch_enSubF
 	if pkg.IsDir(cacheTmpPath) == false {
 		err = os.MkdirAll(cacheTmpPath, os.ModePerm)
 		if err != nil {
-			return false, nil, err
+			return false, nil, fixedSubName, err
 		}
 	}
 	// 写入内置字幕、外置字幕原始文件
 	err = s.saveSubFile(path.Join(cacheTmpPath, infoBaseNameWithOutExt+".chinese(inside)"+infoBase.Ext), infoBase.Content)
 	if err != nil {
-		return false, nil, err
+		return false, nil, fixedSubName, err
 	}
 	err = s.saveSubFile(path.Join(cacheTmpPath, infoSrc.Name), infoSrc.Content)
 	if err != nil {
-		return false, nil, err
+		return false, nil, fixedSubName, err
 	}
 	bok, offsetTime, sd, err := s.subTimelineFixer.GetOffsetTime(infoBase, infoSrc, path.Join(cacheTmpPath, infoSrc.Name+"-bar.html"), path.Join(cacheTmpPath, infoSrc.Name+".log"))
 	if offsetTime != 0 {
@@ -196,19 +194,19 @@ func (s SubTimelineFixerHelper) fixSubTimeline(enSubFile emby.SubInfo, ch_enSubF
 	// 超过 SD 阈值了
 	if sd > s.FixerConfig.MaxStartTimeDiffSD {
 		log_helper.GetLogger().Debugln(infoSrc.Name, "Start Time Diff SD, skip", fmt.Sprintf("%f", sd))
-		return false, nil, nil
+		return false, nil, fixedSubName, nil
 	} else {
 		log_helper.GetLogger().Debugln(infoSrc.Name, "Start Time Diff SD", fmt.Sprintf("%f", sd))
 	}
 
 	if err != nil || bok == false {
-		return false, nil, err
+		return false, nil, fixedSubName, err
 	}
 
 	// 偏移很小就无视了
 	if offsetTime < s.FixerConfig.MinOffset && offsetTime > -s.FixerConfig.MinOffset {
 		log_helper.GetLogger().Debugln(infoSrc.Name, fmt.Sprintf("Min Offset Config is %f, skip ", s.FixerConfig.MinOffset), fmt.Sprintf("now is %f", offsetTime))
-		return false, nil, nil
+		return false, nil, fixedSubName, nil
 	}
 	// 写入校准时间轴后的字幕
 	var subFixInfos = make([]sub_timeline_fixer.SubFixInfo, 0)
@@ -228,19 +226,21 @@ func (s SubTimelineFixerHelper) fixSubTimeline(enSubFile emby.SubInfo, ch_enSubF
 
 		desFixSubFileFullPath := ""
 		if hasDefault == true {
+			fixedSubName = subNewNameDefault
 			desFixSubFileFullPath = path.Join(cacheTmpPath, subNewNameDefault)
 
 		} else {
+			fixedSubName = subNewName
 			desFixSubFileFullPath = path.Join(cacheTmpPath, subNewName)
 		}
 		fixContent, err := s.subTimelineFixer.FixSubTimeline(infoSrc, offsetTime, desFixSubFileFullPath)
 		if err != nil {
-			return false, nil, err
+			return false, nil, fixedSubName, err
 		}
 		subFixInfos = append(subFixInfos, *sub_timeline_fixer.NewSubFixInfo(infoSrc.Name, fixContent))
 	}
 
-	return true, subFixInfos, nil
+	return true, subFixInfos, fixedSubName, nil
 }
 
 func (s SubTimelineFixerHelper) saveSubFile(desSaveSubFileFullPath string, content string) error {

+ 0 - 1
internal/pkg/sub_timeline_fixer/fixer_test.go

@@ -328,7 +328,6 @@ func TestGetOffsetTime(t *testing.T) {
 				if err != nil {
 					t.Fatal(err)
 				}
-
 			}
 
 			println(fmt.Sprintf("GetOffsetTime: %fs SD:%f", got, sd))