Browse Source

新增,内部支持蓝光视频的本程序视频唯一ID计算逻辑,见 sub_file_hash.go

Signed-off-by: allan716 <[email protected]>
allan716 3 years ago
parent
commit
290d47ff4f

+ 4 - 4
internal/logic/series_helper/seriesHelper.go

@@ -168,21 +168,21 @@ func DownloadSubtitleInAllSiteByOneSeries(Suppliers []ifaces.ISupplier, seriesIn
 		log_helper.GetLogger().Infoln(common.QueueName, i, seriesInfo.Name, "-", key)
 	}
 
-	for index, oneSupplier := range Suppliers {
+	for _, oneSupplier := range Suppliers {
 
 		oneSupplierFunc := func() {
 			defer func() {
-				log_helper.GetLogger().Infoln(common.QueueName, index, i, oneSupplier.GetSupplierName(), "End")
+				log_helper.GetLogger().Infoln(common.QueueName, i, oneSupplier.GetSupplierName(), "End")
 				log_helper.GetLogger().Infoln("------------------------------------------")
 			}()
 
 			var subInfos []supplier.SubInfo
 			log_helper.GetLogger().Infoln("------------------------------------------")
-			log_helper.GetLogger().Infoln(common.QueueName, index, i, oneSupplier.GetSupplierName(), "Start...")
+			log_helper.GetLogger().Infoln(common.QueueName, i, oneSupplier.GetSupplierName(), "Start...")
 			// 一次性把这一部连续剧的所有字幕下载完
 			subInfos, err := oneSupplier.GetSubListFromFile4Series(seriesInfo)
 			if err != nil {
-				log_helper.GetLogger().Errorln(common.QueueName, index, i, oneSupplier.GetSupplierName(), "GetSubListFromFile4Series", err)
+				log_helper.GetLogger().Errorln(common.QueueName, i, oneSupplier.GetSupplierName(), "GetSubListFromFile4Series", err)
 				return
 			}
 			// 把后缀名给改好

+ 1 - 1
internal/logic/sub_supplier/shooter/shooter.go

@@ -97,7 +97,7 @@ func (s *Supplier) getSubListFromFile(filePath string) ([]supplier.SubInfo, erro
 
 	if my_util.IsFile(filePath) == false {
 		// 这里传入的可能是蓝光结构的伪造存在的视频文件,需要检查一次这个文件是否存在
-		bok, _ := decode.IsFakeBDMVWorked(filePath)
+		bok, _, _ := decode.IsFakeBDMVWorked(filePath)
 		if bok == false {
 
 			nowError := errors.New(fmt.Sprintf("%s %s %s",

+ 1 - 1
internal/logic/sub_supplier/xunlei/xunlei.go

@@ -100,7 +100,7 @@ func (s *Supplier) getSubListFromFile(filePath string) ([]supplier.SubInfo, erro
 
 	if my_util.IsFile(filePath) == false {
 		// 这里传入的可能是蓝光结构的伪造存在的视频文件,需要检查一次这个文件是否存在
-		bok, _ := decode.IsFakeBDMVWorked(filePath)
+		bok, _, _ := decode.IsFakeBDMVWorked(filePath)
 		if bok == false {
 
 			nowError := errors.New(fmt.Sprintf("%s %s %s",

+ 6 - 5
internal/pkg/decode/decode.go

@@ -333,7 +333,7 @@ func GetVideoInfoFromFileFullPath(videoFileFullPath string) (*PTN.TorrentInfo, t
 	} else {
 		// 再次判断是否是蓝光结构
 		// 因为在前面扫描视频的时候,发现特殊的蓝光结构会伪造一个不存在的 xx.mp4 的视频文件过来,这里就需要额外检测一次
-		bok, idBDMVFPath := IsFakeBDMVWorked(videoFileFullPath)
+		bok, idBDMVFPath, _ := IsFakeBDMVWorked(videoFileFullPath)
 		if bok == false {
 			return nil, time.Time{}, err
 		}
@@ -426,20 +426,21 @@ func IsDir(path string) bool {
 	return s.IsDir()
 }
 
-// IsFakeBDMVWorked 传入的是伪造的不存在的蓝光结构的视频全路径,如果是就返回 true 和 id.bdmv 的绝对路径
-func IsFakeBDMVWorked(fakseVideFPath string) (bool, string) {
+// IsFakeBDMVWorked 传入的是伪造的不存在的蓝光结构的视频全路径,如果是就返回 true 和 id.bdmv 的绝对路径 和 STREAM 绝对路径
+func IsFakeBDMVWorked(fakseVideFPath string) (bool, string, string) {
 
 	rootDir := filepath.Dir(fakseVideFPath)
 
 	CERDir := filepath.Join(rootDir, "CERTIFICATE")
 	BDMVDir := filepath.Join(rootDir, "BDMV")
+	STREAMDir := filepath.Join(BDMVDir, "STREAM")
 	idBDMVFPath := filepath.Join(CERDir, common2.FileBDMV)
 
 	if IsDir(CERDir) == true && IsDir(BDMVDir) == true && IsFile(idBDMVFPath) == true {
-		return true, idBDMVFPath
+		return true, idBDMVFPath, STREAMDir
 	}
 
-	return false, ""
+	return false, "", ""
 }
 
 const (

+ 49 - 1
internal/pkg/sub_file_hash/sub_file_hash.go

@@ -3,15 +3,26 @@ package sub_file_hash
 import (
 	"crypto/md5"
 	"crypto/sha1"
+	"errors"
 	"fmt"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/decode"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/common"
 	"math"
 	"os"
 )
 
-// Calculate 视频文件的唯一ID
+// Calculate 视频文件的唯一ID,支持内程序内的 Fake 蓝光视频文件路径
 func Calculate(filePath string) (string, error) {
 
+	bok, _, STREAMDir := decode.IsFakeBDMVWorked(filePath)
+	if bok == true {
+		bdmvBigFileFPath, err := getBDMVBigFileFPath(STREAMDir)
+		if err != nil {
+			return "", err
+		}
+		filePath = bdmvBigFileFPath
+	}
+
 	h := sha1.New()
 	fp, err := os.Open(filePath)
 	if err != nil {
@@ -73,6 +84,43 @@ func Calculate(filePath string) (string, error) {
 	return fmt.Sprintf("%x", md5.Sum(hashBytes)), nil
 }
 
+func getBDMVBigFileFPath(STREAMDir string) (string, error) {
+
+	// 因为上面可以检测出是否是蓝光电影,这里就是找到蓝光中最大的一个流文件,然后交给后续进行特征提取
+	pathSep := string(os.PathSeparator)
+	maxFileFPath := ""
+	var maxFileSize int64
+	maxFileSize = 0
+	files, err := os.ReadDir(STREAMDir)
+	if err != nil {
+		return "", err
+	}
+	for _, curFile := range files {
+
+		fullPath := STREAMDir + pathSep + curFile.Name()
+
+		if curFile.IsDir() {
+			// 只关心这一个文件夹
+			continue
+		}
+		// 文件
+		info, err := curFile.Info()
+		if err != nil {
+			continue
+		}
+		if info.Size() > maxFileSize {
+			maxFileSize = info.Size()
+			maxFileFPath = fullPath
+		}
+	}
+
+	if maxFileFPath == "" {
+		return "", errors.New("getBDMVBigFileFPath no file found")
+	}
+
+	return maxFileFPath, nil
+}
+
 const (
 	samplingPoints = 5
 	onePointLen    = 4 * 1024

+ 8 - 11
internal/types/task_queue/task_queue.go

@@ -3,7 +3,6 @@ package task_queue
 import (
 	"crypto/sha1"
 	"fmt"
-	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_file_hash"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/common"
 	"path/filepath"
@@ -41,17 +40,15 @@ func NewOneJob(videoType common.VideoType, videoFPath string, taskPriority int,
 		return fmt.Sprintf("%x", bs)
 	}
 
-	// 如果 videoFPath 存在,那么就计算这个文件的唯一ID,使用内部的算法
-	// 如果 videoFPath 不存在,那么就是蓝光伪造的地址,就使用这个伪造的路径进行 sha1 加密即可
-	if my_util.IsFile(videoFPath) == true {
-		sha1String, err := sub_file_hash.Calculate(videoFPath)
-		if err != nil {
-			ob.Id = sha1FilePathID()
-		} else {
-			ob.Id = sha1String
-		}
-	} else {
+	/*
+		sub_file_hash.Calculate 现在支持内部的 fake 蓝光视频地址了,会解析到 BDMV 中最大的那个视频流文件来计算
+		所以上面这个函数如果 errors 了,才需要使用这个伪造的路径进行 sha1 加密即可
+	*/
+	sha1String, err := sub_file_hash.Calculate(videoFPath)
+	if err != nil {
 		ob.Id = sha1FilePathID()
+	} else {
+		ob.Id = sha1String
 	}
 
 	ob.VideoName = filepath.Base(videoFPath)