ソースを参照

正在写

Signed-off-by: 716 <[email protected]>
716 4 年 前
コミット
3a01f46ef8

+ 1 - 0
.gitignore

@@ -13,3 +13,4 @@
 /*.rar
 /sub_supplier/subhd/Logs
 /model/config.yaml
+/sub_supplier/zimuku/Logs

+ 38 - 4
model/decode.go

@@ -128,10 +128,10 @@ func GetImdbInfo(dirPth string) (common.VideoInfo, error) {
 	return imdbInfo, common.CanNotFindIMDBID
 }
 
-//GetVideoInfoFromFileName 从文件名推断视频文件的信息
-func GetVideoInfoFromFileName(videoFileName string) (*PTN.TorrentInfo, time.Time, error) {
+//GetVideoInfoFromFileFullPath 从全文件路径推断文件信息
+func GetVideoInfoFromFileFullPath(videoFileFullPath string) (*PTN.TorrentInfo, time.Time, error) {
 
-	parse, err := PTN.Parse(filepath.Base(videoFileName))
+	parse, err := PTN.Parse(filepath.Base(videoFileFullPath))
 	if err != nil {
 		return nil, time.Time{}, err
 	}
@@ -143,7 +143,7 @@ func GetVideoInfoFromFileName(videoFileName string) (*PTN.TorrentInfo, time.Time
 	match = strings.TrimRight(match, "")
 	parse.Title = match
 
-	fInfo, err := os.Stat(videoFileName)
+	fInfo, err := os.Stat(videoFileFullPath)
 	if err != nil {
 		return nil, time.Time{}, err
 	}
@@ -151,6 +151,40 @@ func GetVideoInfoFromFileName(videoFileName string) (*PTN.TorrentInfo, time.Time
 	return parse, fInfo.ModTime(), nil
 }
 
+// GetSeasonAndEpisodeFromSubFileName 从文件名推断 季 和 集 的信息 Season Episode
+func GetSeasonAndEpisodeFromSubFileName(videoFileName string) (bool, int, int, error) {
+	// 先进行单个 Episode 的匹配
+	// Killing.Eve.S02E01.Do.You.Know.How
+	var re = regexp.MustCompile(`(?m)\.S(\d+)E(\d+)\.`)
+	matched := re.FindAllStringSubmatch(videoFileName, -1)
+	if len(matched) < 1 {
+		// Killing.Eve.S02.Do.You.Know.How
+		// 看看是不是季度字幕打包
+		re = regexp.MustCompile(`(?m)\.S(\d+)\.`)
+		matched = re.FindAllStringSubmatch(videoFileName, -1)
+		if len(matched) < 1 {
+			return false, 0, 0, nil
+		}
+		season, err := GetNumber2int(matched[0][1])
+		if err != nil {
+			return false,0, 0, err
+		}
+		return true, season, 0, nil
+	} else {
+		// 一集的字幕
+		season, err := GetNumber2int(matched[0][1])
+		if err != nil {
+			return false,0, 0, err
+		}
+		episode, err := GetNumber2int(matched[0][2])
+		if err != nil {
+			return false, 0, 0, err
+		}
+
+		return false, season, episode, nil
+	}
+}
+
 func SkipChineseMovie(videoFullPath string, _reqParam ...common.ReqParam) (bool, error) {
 	var reqParam common.ReqParam
 	if len(_reqParam) > 0 {

+ 12 - 2
model/decode_test.go

@@ -46,7 +46,7 @@ func Test_get_IMDB_nfo(t *testing.T) {
 	}
 }
 
-func Test_VideoInfo(t *testing.T) {
+func Test_GetVideoInfoFromFileFullPath(t *testing.T) {
 
 	subTitle := "X:\\电影\\Spiral From the Book of Saw (2021)\\Spiral From the Book of Saw (2021) WEBDL-1080p.mkv"
 	//subTitle := "人之怒 WEBDL-1080p.mkv"
@@ -57,13 +57,23 @@ func Test_VideoInfo(t *testing.T) {
 	//subTitle := "Spiral.From.the.Book.of.Saw.2021.1080p.WEBRip.x264-RARBG.chi.srt"
 	//subTitle := "Spiral.From.the.Book.of.Saw.2021.1080p.WEBRip.x264-RARBG.eng.srt"
 	//subTitle := "东城梅尔 第一季第一集【YYeTs字幕组 简繁英双语字幕】Mare.of.Easttown.S01E01.Miss.Lady.Hawk.Herself.720p/1080p.AMZN.WEB-DL.DDP5.1.H.264-TEPES"
-	info, modifyTime, err := GetVideoInfoFromFileName(subTitle)
+	info, modifyTime, err := GetVideoInfoFromFileFullPath(subTitle)
 	if err != nil {
 		t.Error(err)
 	}
 	println("Title:", info.Title, "Season:", info.Season, "Episode:", info.Episode, modifyTime.String())
 }
 
+func Test_GetSeasonAndEpisodeFromFileName(t *testing.T) {
+	//str := `杀死伊芙 第二季(第1集-简繁英双语字幕-FIX字幕侠)Killing.Eve.S02E01.Do.You.Know.How.to.Dispose.of.a.Body.1080p.AMZN.WEB-DL.DDP5.1.H.264-NTb.rar`
+	str := `杀死伊芙 第二季(-简繁英双语字幕-FIX字幕侠)Killing.Eve.S02.Do.You.Know.How.to.Dispose.of.a.Body.1080p.AMZN.WEB-DL.DDP5.1.H.264-NTb.rar`
+	b, s, e, err := GetSeasonAndEpisodeFromSubFileName(str)
+	if err != nil {
+		t.Fatal(err)
+	}
+	println(b, s, e)
+}
+
 func TestGetNumber2Float(t *testing.T) {
 	testString := "asd&^%1998.2jh aweo "
 	outNumber, err := GetNumber2Float(testString)

+ 2 - 2
series_helper/seriesHelper.go

@@ -44,7 +44,7 @@ func ReadSeriesInfoFromDir(seriesDir string) (*common.SeriesInfo, error) {
 	SubDict := make(map[string][]common.SubInfo)
 	for _, subFile := range subFiles {
 
-		info, _, err := model.GetVideoInfoFromFileName(subFile)
+		info, _, err := model.GetVideoInfoFromFileFullPath(subFile)
 		if err != nil {
 			model.GetLogger().Errorln(err)
 			continue
@@ -74,7 +74,7 @@ func ReadSeriesInfoFromDir(seriesDir string) (*common.SeriesInfo, error) {
 	EpisodeDict := make(map[string]common.EpisodeInfo)
 	for _, videoFile := range videoFiles {
 		// 正常来说,一集只有一个格式的视频,也就是 S01E01 只有一个,如果有多个则会只保存第一个
-		info, modifyTime, err := model.GetVideoInfoFromFileName(videoFile)
+		info, modifyTime, err := model.GetVideoInfoFromFileFullPath(videoFile)
 		if err != nil {
 			model.GetLogger().Errorln(err)
 			continue

+ 12 - 5
sub_supplier/subSupplierHub.go

@@ -4,6 +4,7 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/common"
 	"github.com/allanpk716/ChineseSubFinder/interface"
 	"github.com/allanpk716/ChineseSubFinder/model"
+	"github.com/allanpk716/ChineseSubFinder/series_helper"
 	"github.com/go-rod/rod/lib/utils"
 	"github.com/sirupsen/logrus"
 	"io/ioutil"
@@ -41,10 +42,10 @@ func (d SubSupplierHub) DownloadSub4Movie(videoFullPath string, index int) ([]st
 		d.log.Error(err)
 	}
 
-	// 跳过中文的电影
+	// 跳过中文的电影,不是一定要跳过的
 	skip, err := model.SkipChineseMovie(videoFullPath, d.Suppliers[0].GetReqParam())
 	if err != nil {
-		return nil, err
+		d.log.Error("SkipChineseMovie", err)
 	}
 	if skip == true {
 		return nil, nil
@@ -54,7 +55,7 @@ func (d SubSupplierHub) DownloadSub4Movie(videoFullPath string, index int) ([]st
 	// 30 天
 	currentTime := time.Now()
 	dayRange, _ := time.ParseDuration(common.DownloadSubDuring30Days)
-	_, modifyTime, err := model.GetVideoInfoFromFileName(videoFullPath)
+	_, modifyTime, err := model.GetVideoInfoFromFileFullPath(videoFullPath)
 	if err != nil {
 		return nil, err
 	}
@@ -95,15 +96,21 @@ func (d SubSupplierHub) DownloadSub4Series(seriesDirPath string, index int) ([]s
 	if err != nil {
 		d.log.Error(err)
 	}
-	// 跳过中文的连续剧
+	// 跳过中文的连续剧,不是一定要跳过的
 	skip, err := model.SkipChineseSeries(seriesDirPath, d.Suppliers[0].GetReqParam())
 	if err != nil {
-		return nil, err
+		d.log.Error("SkipChineseSeries", err)
 	}
 	if skip == true {
 		return nil, nil
 	}
 
+	// 读取本地的视频和字幕信息
+	seriesInfo, err := series_helper.ReadSeriesInfoFromDir(seriesDirPath)
+	if err != nil {
+		return nil, err
+	}
+
 
 	return nil, nil
 }

+ 1 - 1
sub_supplier/subhd/subhd.go

@@ -71,7 +71,7 @@ func (s Supplier) GetSubListFromFile(filePath string) ([]common.SupplierSubInfo,
 		如果找不到,再靠文件名提取影片名称去查找
 	*/
 	// 得到这个视频文件名中的信息
-	info, _, err := model.GetVideoInfoFromFileName(filePath)
+	info, _, err := model.GetVideoInfoFromFileFullPath(filePath)
 	if err != nil {
 		return nil, err
 	}

+ 16 - 19
sub_supplier/zimuku/zimuku.go

@@ -6,7 +6,6 @@ import (
 	"github.com/Tnze/go.num/v2/zh"
 	"github.com/allanpk716/ChineseSubFinder/common"
 	"github.com/allanpk716/ChineseSubFinder/model"
-	"github.com/allanpk716/ChineseSubFinder/series_helper"
 	"github.com/sirupsen/logrus"
 	"path/filepath"
 	"regexp"
@@ -47,18 +46,13 @@ func (s Supplier) GetSubListFromFile4Movie(filePath string) ([]common.SupplierSu
 	return s.GetSubListFromFile(filePath)
 }
 
-func (s Supplier) GetSubListFromFile4Series(seriesPath string) ([]common.SupplierSubInfo, error) {
-
+func (s Supplier) GetSubListFromFile4Series(seriesInfo *common.SeriesInfo) ([]common.SupplierSubInfo, error) {
+	var err error
 	/*
 		去网站搜索的时候,有个比较由意思的逻辑,有些剧集,哪怕只有一季,sonarr 也会给它命名为 Season 1
 		但是在 zimuku 搜索的时候,如果你加上 XXX 第一季 就搜索不出来,那么目前比较可行的办法是查询两次
 		第一次优先查询 XXX 第一季 ,如果返回的列表是空的,那么再查询 XXX
 	*/
-	// 读取本地的视频和字幕信息
-	seriesInfo, err := series_helper.ReadSeriesInfoFromDir(seriesPath)
-	if err != nil {
-		return nil, err
-	}
 	// 这里打算牺牲效率,提高代码的复用度,不然后续得维护一套电影的查询逻辑,一套剧集的查询逻辑
 	// 比如,其实可以搜索剧集名称,应该可以得到多个季的列表,然后分析再继续
 	// 现在粗暴点,直接一季搜索一次,跟电影的搜索一样,在首个影片就停止,然后继续往下
@@ -88,13 +82,13 @@ func (s Supplier) GetSubListFromFile4Series(seriesPath string) ([]common.Supplie
 	// key SxEx - SubInfos
 	var allSubDict = make(map[string]SubInfos)
 	for _, subInfo := range AllSeasonSubResult.SubInfos {
-
-		info, _, err := model.GetVideoInfoFromFileName(subInfo.Name)
+		_, season, episode, err := model.GetSeasonAndEpisodeFromSubFileName(subInfo.Name)
 		if err != nil {
-			s.log.Errorln("GetSubListFromFile4Series.GetVideoInfoFromFileName", subInfo.Name, err)
+			s.log.Errorln("SubInfos GetSubListFromFile4Series.GetVideoInfoFromFileFullPath", subInfo.Name, err)
 			continue
 		}
-		epsKey := model.GetEpisodeKeyName(info.Season, info.Episode)
+		// 这里的 episode 为 0,则是全季
+		epsKey := model.GetEpisodeKeyName(season, episode)
 		_, ok := allSubDict[epsKey]
 		if ok == false {
 			// 初始化
@@ -114,17 +108,20 @@ func (s Supplier) GetSubListFromFile4Series(seriesPath string) ([]common.Supplie
 		// 这一集下载后的30天内,都进行字幕的下载
 		if len(epsInfo.SubList) < 1 || epsInfo.ModifyTime.Add(dayRange).After(currentTime) == true {
 			// 添加
-			info, _, err := model.GetVideoInfoFromFileName(epsInfo.Title)
-			if err != nil {
-				s.log.Errorln("GetSubListFromFile4Series.GetVideoInfoFromFileName", epsInfo.Title, err)
-				continue
-			}
-			epsKey := model.GetEpisodeKeyName(info.Season, info.Episode)
+			epsKey := model.GetEpisodeKeyName(epsInfo.Season, epsInfo.Episode)
 			// 从一堆字幕里面找合适的
 			value, ok := allSubDict[epsKey]
 			// 是否有
 			if ok == true && len(value) > 0 {
 				subInfoNeedDownload = append(subInfoNeedDownload, value[0])
+			} else {
+				s.log.Infoln("Not Find Sub can be download", epsInfo.Title, epsInfo.Season, epsInfo.Episode)
+			}
+		} else {
+			if len(epsInfo.SubList) > 0 {
+				s.log.Infoln("Skip because find sub file", epsInfo.Title, epsInfo.Season, epsInfo.Episode)
+			} else if epsInfo.ModifyTime.Add(dayRange).After(currentTime) == false {
+				s.log.Infoln("Skip because 30 days pass", epsInfo.Title, epsInfo.Season, epsInfo.Episode)
 			}
 		}
 	}
@@ -147,7 +144,7 @@ func (s Supplier) GetSubListFromFile(filePath string) ([]common.SupplierSubInfo,
 		如果找不到,再靠文件名提取影片名称去查找
 	*/
 	// 得到这个视频文件名中的信息
-	info, _, err := model.GetVideoInfoFromFileName(filePath)
+	info, _, err := model.GetVideoInfoFromFileFullPath(filePath)
 	if err != nil {
 		return nil, err
 	}

+ 9 - 14
sub_supplier/zimuku/zimuku_test.go

@@ -1,6 +1,7 @@
 package zimuku
 
 import (
+	"github.com/allanpk716/ChineseSubFinder/series_helper"
 	"testing"
 )
 
@@ -42,8 +43,15 @@ func TestSupplier_GetSubListFromFile4Series(t *testing.T) {
 
 	//ser := "X:\\连续剧\\The Bad Batch"	// tt12708542
 	ser := "X:\\连续剧\\杀死伊芙 (2018)"	// tt12708542
+	//ser := "X:\\连续剧\\Money.Heist"
+
+	// 读取本地的视频和字幕信息
+	seriesInfo, err := series_helper.ReadSeriesInfoFromDir(ser)
+	if err != nil {
+		t.Fatal(err)
+	}
 	s := NewSupplier()
-	outList, err := s.GetSubListFromFile4Series(ser)
+	outList, err := s.GetSubListFromFile4Series(seriesInfo)
 	if err != nil {
 		t.Error(err)
 	}
@@ -53,16 +61,3 @@ func TestSupplier_GetSubListFromFile4Series(t *testing.T) {
 	}
 }
 
-func TestSupplier_GetSubListFromFile4Series1(t *testing.T) {
-
-	series := "X:\\连续剧\\杀死伊芙 (2018)"
-	//series := "X:\\连续剧\\Money.Heist"
-
-	s := NewSupplier()
-	file4Series, err := s.GetSubListFromFile4Series(series)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	println(file4Series)
-}