Переглянути джерело

修复可能的越界问题

Signed-off-by: allan716 <[email protected]>
allan716 3 роки тому
батько
коміт
374e9b1d34

+ 3 - 2
TestCode/test_imdb_tmdb.go

@@ -2,13 +2,14 @@ package TestCode
 
 import (
 	"fmt"
+
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/settings"
 	tmdb "github.com/cyruzin/golang-tmdb"
 )
 
 func imdb2tmdb() {
-	tmdbClient, err := tmdb.Init("xxx")
+	tmdbClient, err := tmdb.Init("d871daae18cd1194b8a04c41e4b7dd14")
 
 	if err != nil {
 		fmt.Println(err)
@@ -21,7 +22,7 @@ func imdb2tmdb() {
 
 	const keanuReevesID = "tt6264654"
 
-	proxySettings := settings.NewProxySettings(true, "http",
+	proxySettings := settings.NewProxySettings(false, "http",
 		"19037",
 		"192.168.50.252", "5269",
 		"", "",

+ 9 - 3
internal/logic/sub_parser/ass/ass.go

@@ -1,14 +1,15 @@
 package ass
 
 import (
+	"os"
+	"path/filepath"
+	"strings"
+
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/language"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/regex_things"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/subparser"
 	"github.com/emirpasic/gods/maps/treemap"
 	"github.com/sirupsen/logrus"
-	"os"
-	"path/filepath"
-	"strings"
 )
 
 type Parser struct {
@@ -158,6 +159,11 @@ func (p Parser) oneLineSubDialogueParser1(matched [][]string, mapByValue StyleNa
 	var usefullyDialogueCount = 0
 	// 先读取一次字幕文件
 	for _, oneLine := range matched {
+
+		if len(oneLine) < 1 {
+			continue
+		}
+
 		// 排除特效内容,只统计有意义的对话部分
 		if strings.Contains(oneLine[0], mapByValue[0].Name) == false {
 			continue

+ 4 - 0
internal/logic/sub_supplier/subhd/subhd.go

@@ -326,6 +326,10 @@ func (s *Supplier) whichEpisodeNeedDownloadSub(seriesInfo *series.SeriesInfo, al
 	}
 	// 全季的字幕列表,也拼进去,后面进行下载
 	for _, infos := range oneSeasonSubDict {
+
+		if len(infos) < 1 {
+			continue
+		}
 		subInfoNeedDownload = append(subInfoNeedDownload, infos[0])
 	}
 

+ 11 - 7
internal/logic/sub_supplier/zimuku/zimuku.go

@@ -3,6 +3,14 @@ package zimuku
 import (
 	"errors"
 	"fmt"
+	"net/url"
+	"os"
+	"path/filepath"
+	"regexp"
+	"sort"
+	"strings"
+	"time"
+
 	"github.com/PuerkitoBio/goquery"
 	"github.com/Tnze/go.num/v2/zh"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/file_downloader"
@@ -20,13 +28,6 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/types/supplier"
 	"github.com/go-rod/rod"
 	"github.com/sirupsen/logrus"
-	"net/url"
-	"os"
-	"path/filepath"
-	"regexp"
-	"sort"
-	"strings"
-	"time"
 )
 
 type Supplier struct {
@@ -412,6 +413,9 @@ func (s *Supplier) whichEpisodeNeedDownloadSub(seriesInfo *series.SeriesInfo, Al
 	}
 	// 全季的字幕列表,也拼进去,后面进行下载
 	for _, infos := range oneSeasonSubDict {
+		if len(infos) < 1 {
+			continue
+		}
 		subInfoNeedDownload = append(subInfoNeedDownload, infos[0])
 	}
 

+ 8 - 2
internal/pkg/imdb_helper/imdb.go

@@ -2,6 +2,9 @@ package imdb_helper
 
 import (
 	"fmt"
+	"strconv"
+	"strings"
+
 	"github.com/StalkR/imdb"
 	"github.com/allanpk716/ChineseSubFinder/internal/dao"
 	"github.com/allanpk716/ChineseSubFinder/internal/models"
@@ -12,8 +15,6 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/types"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/common"
 	"github.com/sirupsen/logrus"
-	"strconv"
-	"strings"
 )
 
 // GetVideoInfoFromIMDBWeb 从 IMDB 网站 ID 查询影片的信息
@@ -128,6 +129,11 @@ func IsChineseVideo(log *logrus.Logger, imdbInfo types.VideoIMDBInfo, _proxySett
 
 		log.Debugln("IsChineseVideo", 4)
 	}
+
+	if len(localIMDBInfo.Languages) < 1 {
+		return false, localIMDBInfo, nil
+	}
+
 	firstLangLowCase := strings.ToLower(localIMDBInfo.Languages[0])
 
 	log.Debugln("IsChineseVideo", 5)