Browse Source

修复 subhd 前期的工作完成

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

+ 14 - 1
cmd/chinesesubfinder/main.go

@@ -9,6 +9,7 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/notify_center"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/proxy_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/something_static"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_formatter"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_formatter/common"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
@@ -157,6 +158,18 @@ func DownLoadStart(httpProxy string) {
 
 	notify_center.Notify.Clear()
 
+	updateTimeString, code, err := something_static.GetCodeFromWeb()
+	if err != nil {
+		notify_center.Notify.Add("GetSubhdCode", "GetCodeFromWeb,"+err.Error())
+		log.Errorln("something_static.GetCodeFromWeb", err)
+		log.Errorln("Skip Subhd download")
+		// 没有则需要清空
+		commonValue.SubhdCode = ""
+	} else {
+		log.Infoln("GetCode", updateTimeString, code)
+		commonValue.SubhdCode = code
+	}
+
 	// 下载实例
 	downloader := internal.NewDownloader(sub_formatter.GetSubFormatter(config.SubNameFormatter),
 		types.ReqParam{
@@ -183,7 +196,7 @@ func DownLoadStart(httpProxy string) {
 	log.Infoln("Download One Started...")
 
 	// 优先级最高。读取特殊文件,启用一些特殊的功能,比如 forced_scan_and_down_sub
-	err := downloader.ReadSpeFile()
+	err = downloader.ReadSpeFile()
 	if err != nil {
 		log.Errorln("ReadSpeFile", err)
 	}

+ 4 - 0
internal/common/global_value.go

@@ -0,0 +1,4 @@
+package common
+
+// SubHD Code 的全局变量,偷懒先实现
+var SubhdCode = ""

+ 7 - 1
internal/downloader.go

@@ -10,6 +10,7 @@ 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/logic/sub_timeline_fixer"
@@ -85,8 +86,8 @@ func NewDownloader(inSubFormatter ifaces.ISubFormatter, _reqParam ...types.ReqPa
 	// TODO 这里写固定了抉择字幕的顺序
 	sitesSequence = append(sitesSequence, common.SubSiteZiMuKu)
 	sitesSequence = append(sitesSequence, common.SubSiteSubHd)
-	sitesSequence = append(sitesSequence, common.SubSiteXunLei)
 	sitesSequence = append(sitesSequence, common.SubSiteShooter)
+	sitesSequence = append(sitesSequence, common.SubSiteXunLei)
 	downloader.mk = markSystem.NewMarkingSystem(sitesSequence, downloader.reqParam.SubTypePriority)
 
 	downloader.movieFileFullPathList = make([]string, 0)
@@ -224,6 +225,11 @@ func (d Downloader) DownloadSub4Movie(dir string) error {
 			xunlei.NewSupplier(d.reqParam),
 			shooter.NewSupplier(d.reqParam),
 		)
+
+		if common.SubhdCode != "" {
+			// 如果找到 code 了,那么就可以继续用这个实例
+			subSupplierHub.AddSubSupplier(subhd.NewSupplier(d.reqParam))
+		}
 		// 字幕都下载缓存好了,需要抉择存哪一个,优先选择中文双语的,然后到中文
 		organizeSubFiles, err := subSupplierHub.DownloadSub4Movie(inData.OneVideoFullPath, inData.Index, d.needForcedScanAndDownSub)
 		if err != nil {

+ 5 - 0
internal/logic/sub_supplier/subSupplierHub.go

@@ -35,6 +35,11 @@ func NewSubSupplierHub(one ifaces.ISupplier, _inSupplier ...ifaces.ISupplier) *S
 	return &s
 }
 
+// AddSubSupplier 添加一个下载器,目前目标是给 SubHD 使用
+func (d *SubSupplierHub) AddSubSupplier(one ifaces.ISupplier) {
+	d.Suppliers = append(d.Suppliers, one)
+}
+
 // DownloadSub4Movie 某一个电影字幕下载,下载完毕后,返回下载缓存每个字幕的位置
 func (d SubSupplierHub) DownloadSub4Movie(videoFullPath string, index int, forcedScanAndDownloadSub bool) ([]string, error) {
 

+ 28 - 0
internal/pkg/something_static/something_static.go

@@ -74,4 +74,32 @@ func writeFile(saveFileFPath, enString, nowTime string) error {
 	return nil
 }
 
+func GetCodeFromWeb() (string, string, error) {
+	const baseCodeFileUrl = "https://cdn.jsdelivr.net/gh/"
+	const whichProject = "allanpk716/SomeThingsStatic/"
+
+	desUrl := baseCodeFileUrl + whichProject + common.StaticFileName00
+
+	fileBytes, _, err := my_util.DownFile(desUrl)
+	if err != nil {
+		return "", "", err
+	}
+
+	timeB64String := fileBytes[len(fileBytes)-16:]
+	decodedTime, err := b64.StdEncoding.DecodeString(string(timeB64String))
+	if err != nil {
+		return "", "", err
+	}
+	decodeTimeStr := string(decodedTime)
+
+	codeB64String := fileBytes[:len(fileBytes)-16]
+	decodedCode, err := b64.StdEncoding.DecodeString(string(codeB64String))
+	if err != nil {
+		return "", "", err
+	}
+	decodeCodeStr := string(decodedCode)
+
+	return decodeTimeStr, decodeCodeStr, nil
+}
+
 const waitExt = ".wait"