Browse Source

升级内部视频唯一ID的算法到 sha256

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

+ 4 - 7
internal/pkg/sub_file_hash/sub_file_hash.go

@@ -1,8 +1,7 @@
 package sub_file_hash
 
 import (
-	"crypto/md5"
-	"crypto/sha1"
+	"crypto/sha256"
 	"errors"
 	"fmt"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/decode"
@@ -23,7 +22,6 @@ func Calculate(filePath string) (string, error) {
 		filePath = bdmvBigFileFPath
 	}
 
-	h := sha1.New()
 	fp, err := os.Open(filePath)
 	if err != nil {
 		return "", err
@@ -78,10 +76,9 @@ func Calculate(filePath string) (string, error) {
 		//_ = f.Close()
 	}
 
-	h.Write(fullBlock)
-	hashBytes := h.Sum(nil)
+	sum := sha256.Sum256(fullBlock)
 
-	return fmt.Sprintf("%x", md5.Sum(hashBytes)), nil
+	return fmt.Sprintf("%x", sum), nil
 }
 
 func getBDMVBigFileFPath(STREAMDir string) (string, error) {
@@ -126,4 +123,4 @@ const (
 	onePointLen    = 4 * 1024
 )
 
-const checkHash = "f08d48a3e2cd6a02f9fd8ac92743dd3e"
+const checkHash = "f5176762cb6d62471d71511fdddeb7b80c9a7a8939fce5cf172100b4a404a048"

+ 6 - 0
internal/pkg/sub_file_hash/sub_file_hash_test.go

@@ -24,4 +24,10 @@ func TestCalculate(t *testing.T) {
 	if calculate != checkHash {
 		t.Fatal("Hash not the same")
 	}
+
+	//dd := "X:\\电影\\失控玩家 (2021)\\失控玩家 (2021).mp4"
+	//calculate, err := Calculate(dd)
+	//if err != nil {
+	//	t.Fatal(err)
+	//}
 }