瀏覽代碼

Merge branch 'dev' of github.com:allanpk716/ChineseSubFinder into dev

allan716 3 年之前
父節點
當前提交
ff94ab865d

+ 13 - 2
internal/logic/sub_supplier/shooter/shooter_test.go

@@ -1,7 +1,9 @@
 package shooter
 
 import (
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/unit_test_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
+	"path/filepath"
 	"testing"
 )
 
@@ -13,9 +15,18 @@ func TestNewSupplier(t *testing.T) {
 	//movie1 := "X:\\连续剧\\The Bad Batch\\Season 1\\The Bad Batch - S01E01 - Aftermath WEBDL-1080p.mkv"
 	//movie1 := "X:\\电影\\An Invisible Sign (2010)\\An Invisible Sign (2010) 720p AAC.mp4"
 	//movie1 := "X:\\连续剧\\少年间谍 (2020)\\Season 2\\Alex Rider - S02E01 - Episode One WEBDL-1080p.mkv"
-	movie1 := "X:\\连续剧\\黄石 (2018)\\Season 4\\Yellowstone (2018) - S04E05 - Under a Blanket of Red WEBDL-2160p.mkv"
+	//movie1 := "X:\\连续剧\\黄石 (2018)\\Season 4\\Yellowstone (2018) - S04E05 - Under a Blanket of Red WEBDL-2160p.mkv"
+	//movie1 := "X:\\连续剧\\瑞克和莫蒂 (2013)\\Season 5\\Rick and Morty - S05E09 - Forgetting Sarick Mortshall WEBRip-1080p.mkv"
+
+	rootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"sub_spplier"}, 5, true)
+	rootDir = filepath.Join(rootDir, "shooter")
+
+	gVideoFPath, err := unit_test_helper.GenerateShooterVideoFile(rootDir)
+	if err != nil {
+		t.Fatal(err)
+	}
 	shooter := NewSupplier(types.ReqParam{Topic: 3})
-	outList, err := shooter.getSubListFromFile(movie1)
+	outList, err := shooter.getSubListFromFile(gVideoFPath)
 	if err != nil {
 		t.Error(err)
 	}

+ 15 - 2
internal/logic/sub_supplier/xunlei/xunlei_test.go

@@ -1,7 +1,9 @@
 package xunlei
 
 import (
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/unit_test_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
+	"path/filepath"
 	"testing"
 )
 
@@ -13,9 +15,20 @@ func TestGetList(t *testing.T) {
 	//movie1 := "X:\\电影\\机动战士Z高达:星之继承者 (2005)\\机动战士Z高达:星之继承者 (2005) 1080p TrueHD.mkv"
 	//movie1 := "X:\\连续剧\\The Bad Batch\\Season 1\\The Bad Batch - S01E01 - Aftermath WEBDL-1080p.mkv"
 	//movie1 := "X:\\连续剧\\黄石 (2018)\\Season 4\\Yellowstone (2018) - S04E05 - Under a Blanket of Red WEBDL-2160p.mkv"
-	movie1 := "X:\\动漫\\碧蓝之海 (2018)\\Season 1\\碧蓝之海 - S01E01 - [UHA-WINGS][Grand Blue][01][BDRIP 1920x1080 x264 FLACx2].mkv"
+	//movie1 := "X:\\动漫\\碧蓝之海 (2018)\\Season 1\\碧蓝之海 - S01E01 - [UHA-WINGS][Grand Blue][01][BDRIP 1920x1080 x264 FLACx2].mkv"
+	//movie1 := "X:\\连续剧\\瑞克和莫蒂 (2013)\\Season 5\\Rick and Morty - S05E01 - Mort Dinner Rick Andre WEBDL-1080p.mkv"
+	//movie1 := "X:\\电影\\手机 (2003)\\手机 (2003) 720p Cooker.rmvb"
+
+	rootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"sub_spplier"}, 5, true)
+	rootDir = filepath.Join(rootDir, "xunlei")
+
+	gVideoFPath, err := unit_test_helper.GenerateXunleiVideoFile(rootDir)
+	if err != nil {
+		t.Fatal(err)
+	}
+
 	xunlie := NewSupplier(types.ReqParam{Topic: 3})
-	outList, err := xunlie.getSubListFromFile(movie1)
+	outList, err := xunlie.getSubListFromFile(gVideoFPath)
 	if err != nil {
 		t.Error(err)
 	}

+ 99 - 0
internal/pkg/unit_test_helper/unit_test_helper.go

@@ -2,7 +2,10 @@ package unit_test_helper
 
 import (
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
+	"io"
+	"os"
 	"path/filepath"
+	"strconv"
 )
 
 // GetTestDataResourceRootPath 向上返回几层就能够到 ChineseSubFinder-TestData 同级目录,然后进入其中的 resourceFolderName 资源文件夹中
@@ -38,6 +41,102 @@ func GetTestDataResourceRootPath(resourceFolderNames []string, goBackTimes int,
 	return outPath
 }
 
+// GenerateShooterVideoFile 这里为 shooter 的接口专门生成一个视频文件,瑞克和莫蒂 (2013)\Season 5\S05E09 .mkv
+func GenerateShooterVideoFile(videoPartsRootPath string) (string, error) {
+
+	const videoSize int64 = 640302895
+	const videoName = "S05E09.mkv"
+	const ext = ".videoPart"
+	partNames := []string{"4096", "213434298", "426868596", "640294703"}
+
+	outVideoFPath := filepath.Join(videoPartsRootPath, videoName)
+
+	f, err := os.Create(outVideoFPath)
+	if err != nil {
+		return "", err
+	}
+	defer func() {
+		_ = f.Close()
+	}()
+
+	if err := f.Truncate(videoSize); err != nil {
+		return "", err
+	}
+
+	/*
+		一共有 4 个检测点
+	*/
+	for _, name := range partNames {
+
+		partF, err := os.Open(filepath.Join(videoPartsRootPath, name+ext))
+		if err != nil {
+			return "", err
+		}
+		partAll, err := io.ReadAll(partF)
+		if err != nil {
+			return "", err
+		}
+		int64Numb, err := strconv.ParseInt(name, 10, 64)
+		if err != nil {
+			return "", err
+		}
+		_, err = f.WriteAt(partAll, int64Numb)
+		if err != nil {
+			return "", err
+		}
+	}
+
+	return outVideoFPath, nil
+}
+
+// GenerateXunleiVideoFile 这里为 xunlei 的接口专门生成一个视频文件,手机 (2003) 720p Cooker.rmvb
+func GenerateXunleiVideoFile(videoPartsRootPath string) (string, error) {
+
+	const videoSize int64 = 640302895
+	const videoName = "手机 (2003) 720p Cooker.rmvb"
+	const ext = ".videoPart"
+	partNames := []string{"0", "311177499", "933512018"}
+
+	outVideoFPath := filepath.Join(videoPartsRootPath, videoName)
+
+	f, err := os.Create(outVideoFPath)
+	if err != nil {
+		return "", err
+	}
+	defer func() {
+		_ = f.Close()
+	}()
+
+	if err := f.Truncate(videoSize); err != nil {
+		return "", err
+	}
+
+	/*
+		一共有 3 个检测点
+	*/
+	for _, name := range partNames {
+
+		partF, err := os.Open(filepath.Join(videoPartsRootPath, name+ext))
+		if err != nil {
+			return "", err
+		}
+		partAll, err := io.ReadAll(partF)
+		if err != nil {
+			return "", err
+		}
+		int64Numb, err := strconv.ParseInt(name, 10, 64)
+		if err != nil {
+			return "", err
+		}
+		_, err = f.WriteAt(partAll, int64Numb)
+		if err != nil {
+			return "", err
+		}
+	}
+
+	return outVideoFPath, nil
+}
+
 // copyTestData 单元测试前把测试的数据 copy 一份出来操作,src 目录中默认应该有一个 org 原始数据文件夹,然后需要复制一份 test 文件夹出来
 func copyTestData(srcDir string) (string, error) {
 	// 测试数据的文件夹