Browse Source

调整一部连续剧的最大超时时间到 30 min,考虑到第一次使用的时候可能会遇到大量的搜索需求

Signed-off-by: 716 <[email protected]>
716 3 years ago
parent
commit
40864f17a9

+ 4 - 3
internal/common/constvalue.go

@@ -4,9 +4,10 @@ import (
 	"time"
 )
 
-const HTMLTimeOut = 2 * 60 * time.Second            // HttpClient 超时时间
-const OneVideoProcessTimeOut = 5 * 60 * time.Second // 一部电影、一个连续剧,最多的处理时间
-const DownloadSubsPerSite = 1                       // 默认,每个网站下载一个字幕,允许额外传参调整
+const HTMLTimeOut = 2 * 60 * time.Second              // HttpClient 超时时间
+const OneMovieProcessTimeOut = 5 * 60 * time.Second   // 一部电影,最多的处理时间
+const OneSeriesProcessTimeOut = 30 * 60 * time.Second // 一部连续剧,最多的处理时间
+const DownloadSubsPerSite = 1                         // 默认,每个网站下载一个字幕,允许额外传参调整
 const EmbyApiGetItemsLimitMin = 50
 const EmbyApiGetItemsLimitMax = 50000
 

+ 2 - 2
internal/downloader.go

@@ -256,7 +256,7 @@ func (d Downloader) DownloadSub4Movie(dir string) error {
 	antPool, err := ants.NewPoolWithFunc(d.reqParam.Threads, func(inData interface{}) {
 		data := inData.(InputData)
 		defer data.Wg.Done()
-		ctx, cancel := context.WithTimeout(context.Background(), common.OneVideoProcessTimeOut)
+		ctx, cancel := context.WithTimeout(context.Background(), common.OneMovieProcessTimeOut)
 		defer cancel()
 
 		done := make(chan error, 1)
@@ -391,7 +391,7 @@ func (d Downloader) DownloadSub4Series(dir string) error {
 	antPool, err := ants.NewPoolWithFunc(d.reqParam.Threads, func(inData interface{}) {
 		data := inData.(InputData)
 		defer data.Wg.Done()
-		ctx, cancel := context.WithTimeout(context.Background(), common.OneVideoProcessTimeOut)
+		ctx, cancel := context.WithTimeout(context.Background(), common.OneSeriesProcessTimeOut)
 		defer cancel()
 
 		done := make(chan error, 1)

+ 3 - 3
internal/logic/sub_supplier/subhd/subhd.go

@@ -55,7 +55,7 @@ func NewSupplier(_reqParam ...types.ReqParam) *Supplier {
 	sup.tt = common.HTMLTimeOut
 	sup.debugMode = sup.reqParam.DebugMode
 	if sup.reqParam.DebugMode == true {
-		sup.tt = common.OneVideoProcessTimeOut
+		sup.tt = common.OneMovieProcessTimeOut
 	}
 
 	return &sup
@@ -668,11 +668,11 @@ func (s Supplier) httpGetFromBrowser(browser *rod.Browser, inputUrl string) (str
 	if err != nil {
 		return "", nil, err
 	}
-	// 每次搜索间隔在 30-40s
+	// 每次搜索间隔
 	if s.debugMode == true {
 		time.Sleep(my_util.RandomSecondDuration(5, 10))
 	} else {
-		time.Sleep(my_util.RandomSecondDuration(30, 40))
+		time.Sleep(my_util.RandomSecondDuration(5, 15))
 	}
 
 	return pageString, page, nil

+ 4 - 3
internal/logic/sub_supplier/subhd/subhd_test.go

@@ -6,6 +6,7 @@ import (
 	series_helper2 "github.com/allanpk716/ChineseSubFinder/internal/logic/series_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/something_static"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/unit_test_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	"path/filepath"
 	"testing"
 )
@@ -24,7 +25,7 @@ func TestSupplier_GetSubListFromFile(t *testing.T) {
 	rootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"sub_spplier"}, 5, true)
 	movie1 := filepath.Join(rootDir, "zimuku", "movies", "消失爱人 (2016)", "消失爱人 (2016) 720p AAC.rmvb")
 
-	subhd := NewSupplier()
+	subhd := NewSupplier(types.ReqParam{DebugMode: true})
 	outList, err := subhd.getSubListFromFile4Movie(movie1)
 	if err != nil {
 		t.Error(err)
@@ -56,7 +57,7 @@ func TestSupplier_GetSubListFromFile4Series(t *testing.T) {
 	if err != nil {
 		t.Fatal(err)
 	}
-	s := NewSupplier()
+	s := NewSupplier(types.ReqParam{DebugMode: true})
 	outList, err := s.GetSubListFromFile4Series(seriesInfo)
 	if err != nil {
 		t.Fatal(err)
@@ -78,7 +79,7 @@ func TestSupplier_getSubListFromKeyword4Movie(t *testing.T) {
 	//imdbID := "tt15299712" // 云南虫谷
 	//imdbID := "tt3626476" // Vacation Friends (2021)
 	getCode()
-	subhd := NewSupplier()
+	subhd := NewSupplier(types.ReqParam{DebugMode: true})
 	subInfos, err := subhd.getSubListFromKeyword4Movie(imdbID)
 	if err != nil {
 		t.Fatal(err)