Преглед на файлове

修复,当视频文件有字幕但不是中文字幕的时候没有继续下载的问题

Signed-off-by: 716 <[email protected]>
716 преди 4 години
родител
ревизия
96710d8199
променени са 5 файла, в които са добавени 39 реда и са изтрити 6 реда
  1. 2 2
      downloader_test.go
  2. 22 0
      model/subParserHub.go
  3. 8 2
      movie_helper/movieHelper.go
  4. 5 2
      series_helper/seriesHelper.go
  5. 2 0
      sub_supplier/subSupplierHub.go

+ 2 - 2
downloader_test.go

@@ -29,11 +29,11 @@ func TestDownloader_DownloadSub4Movie(t *testing.T) {
 func TestDownloader_DownloadSub4Series(t *testing.T) {
 	var err error
 	//dirRoot := "X:\\连续剧\\隐秘的角落 (2020)"
-	//dirRoot := "X:\\连续剧\\The Bad Batch"
+	dirRoot := "X:\\连续剧\\The Bad Batch"
 	//dirRoot := "X:\\连续剧\\豪斯医生 (2004)"
 	//dirRoot := "X:\\连续剧\\Why Women Kill"
 	//dirRoot := "X:\\连续剧\\Mare of Easttown"
-	dirRoot := "X:\\连续剧\\瑞克和莫蒂 (2013)"
+	//dirRoot := "X:\\连续剧\\瑞克和莫蒂 (2013)"
 	//dirRoot := "X:\\连续剧\\黄石 (2018)"
 	//dirRoot := "X:\\连续剧"
 

+ 22 - 0
model/subParserHub.go

@@ -49,6 +49,28 @@ func (p SubParserHub) DetermineFileTypeFromFile(filePath string) (*common.SubPar
 	// 如果返回 nil ,那么就说明都没有字幕的格式匹配上
 	return nil, nil
 }
+
+// IsSubHasChinese 字幕文件是否包含中文
+func (p SubParserHub) IsSubHasChinese(fileFPath string) bool {
+
+	// 增加判断已存在的字幕是否有中文
+	file, err := p.DetermineFileTypeFromFile(fileFPath)
+	if err != nil {
+		GetLogger().Warnln("IsSubHasChinese.DetermineFileTypeFromFile", fileFPath, err)
+		return false
+	}
+	if file == nil {
+		GetLogger().Warnln("IsSubHasChinese.DetermineFileTypeFromFile", fileFPath, "is nil")
+		return false
+	}
+	if HasChineseLang(file.Lang) == false {
+		GetLogger().Warnln("IsSubHasChinese.HasChineseLang", fileFPath, "not chinese sub, is ")
+		return false
+	}
+
+	return true
+}
+
 // getFromWhereSite 从文件名找出是从那个网站下载的。这里的文件名的前缀是下载时候标记好的,比较特殊
 func (p SubParserHub) getFromWhereSite(filePath string) string {
 	fileName := filepath.Base(filePath)

+ 8 - 2
movie_helper/movieHelper.go

@@ -4,6 +4,8 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/common"
 	_interface "github.com/allanpk716/ChineseSubFinder/interface"
 	"github.com/allanpk716/ChineseSubFinder/model"
+	"github.com/allanpk716/ChineseSubFinder/sub_parser/ass"
+	"github.com/allanpk716/ChineseSubFinder/sub_parser/srt"
 	"github.com/jinzhu/now"
 	"io/ioutil"
 	"path/filepath"
@@ -65,7 +67,11 @@ func MovieHasSub(videoFilePath string) (bool, error) {
 			continue
 		} else {
 			// 文件
-			if model.IsSubExtWanted(curFile.Name()) == true {
+			if model.IsSubExtWanted(curFile.Name()) == false {
+				continue
+			}
+			// 字幕文件是否包含中文
+			if model.NewSubParserHub(ass.NewParser(), srt.NewParser()).IsSubHasChinese(filepath.Join(dir, curFile.Name())) == true {
 				return true, nil
 			}
 		}
@@ -153,4 +159,4 @@ func MovieNeedDlSub(videoFullPath string) (bool, error) {
 			return false, nil
 		}
 	}
-}
+}

+ 5 - 2
series_helper/seriesHelper.go

@@ -62,7 +62,10 @@ func ReadSeriesInfoFromDir(seriesDir string, imdbInfo *imdb.Title) (*common.Seri
 	// 字幕字典 S01E01 - []SubInfo
 	SubDict := make(map[string][]common.SubInfo)
 	for _, subFile := range subFiles {
-
+		// 判断这个字幕是否包含中文
+		if subParserHub.IsSubHasChinese(subFile) == false {
+			continue
+		}
 		info, _, err := model.GetVideoInfoFromFileFullPath(subFile)
 		if err != nil {
 			model.GetLogger().Errorln(err)
@@ -75,7 +78,7 @@ func ReadSeriesInfoFromDir(seriesDir string, imdbInfo *imdb.Title) (*common.Seri
 		}
 		if subParserFileInfo == nil {
 			// 说明这个字幕无法解析
-			model.GetLogger().Warnln("ReadSeriesInfoFromDir", seriesInfo.DirPath, "DetermineFileTypeFromFile is nill")
+			model.GetLogger().Warnln("ReadSeriesInfoFromDir", seriesInfo.DirPath, "DetermineFileTypeFromFile is nil")
 			continue
 		}
 		epsKey := model.GetEpisodeKeyName(info.Season, info.Episode)

+ 2 - 0
sub_supplier/subSupplierHub.go

@@ -13,6 +13,7 @@ import (
 
 type SubSupplierHub struct {
 	Suppliers []_interface.ISupplier
+
 	log *logrus.Logger
 }
 
@@ -26,6 +27,7 @@ func NewSubSupplierHub(one _interface.ISupplier,_inSupplier ..._interface.ISuppl
 			s.Suppliers = append(s.Suppliers, supplier)
 		}
 	}
+
 	return &s
 }