Преглед изворни кода

保存进度

Signed-off-by: allan716 <[email protected]>
allan716 пре 3 година
родитељ
комит
b922b0145a
4 измењених фајлова са 211 додато и 140 уклоњено
  1. 191 0
      pkg/my_util/search.go
  2. 10 0
      pkg/my_util/search_test.go
  3. 0 139
      pkg/my_util/util.go
  4. 10 1
      pkg/video_list_helper/subtitles.go

+ 191 - 0
pkg/my_util/search.go

@@ -0,0 +1,191 @@
+package my_util
+
+import (
+	"io/fs"
+	"os"
+	"path/filepath"
+	"strconv"
+	"strings"
+
+	"github.com/allanpk716/ChineseSubFinder/pkg/sub_parser_hub"
+
+	"github.com/allanpk716/ChineseSubFinder/pkg/decode"
+	"github.com/allanpk716/ChineseSubFinder/pkg/filter"
+	"github.com/allanpk716/ChineseSubFinder/pkg/sort_things"
+	"github.com/emirpasic/gods/maps/treemap"
+	"github.com/sirupsen/logrus"
+)
+
+// VideoNameSearchKeywordMaker 拼接视频搜索的 title 和 年份
+func VideoNameSearchKeywordMaker(l *logrus.Logger, title string, year string) string {
+	iYear, err := strconv.Atoi(year)
+	if err != nil {
+		// 允许的错误
+		l.Errorln("VideoNameSearchKeywordMaker", "year to int", err)
+		iYear = 0
+	}
+	searchKeyword := title
+	if iYear >= 2020 {
+		searchKeyword = searchKeyword + " " + year
+	}
+
+	return searchKeyword
+}
+
+// SearchMatchedVideoFileFromDirs 搜索符合后缀名的视频文件
+func SearchMatchedVideoFileFromDirs(l *logrus.Logger, dirs []string) (*treemap.Map, error) {
+
+	defer func() {
+		l.Infoln("SearchMatchedVideoFileFromDirs End")
+		l.Infoln(" --------------------------------------------------")
+	}()
+	l.Infoln(" --------------------------------------------------")
+	l.Infoln("SearchMatchedVideoFileFromDirs Start...")
+
+	var fileFullPathMap = treemap.NewWithStringComparator()
+	for _, dir := range dirs {
+
+		matchedVideoFile, err := SearchMatchedVideoFile(l, dir)
+		if err != nil {
+			return nil, err
+		}
+		value, found := fileFullPathMap.Get(dir)
+		if found == false {
+			fileFullPathMap.Put(dir, matchedVideoFile)
+		} else {
+			value = append(value.([]string), matchedVideoFile...)
+			fileFullPathMap.Put(dir, value)
+		}
+	}
+
+	fileFullPathMap.Each(func(seriesRootPathName interface{}, seriesNames interface{}) {
+
+		oneSeriesRootPathName := seriesRootPathName.(string)
+		fileFullPathList := seriesNames.([]string)
+		// 排序,从最新的到最早的
+		fileFullPathList = sort_things.SortByModTime(fileFullPathList)
+		for _, s := range fileFullPathList {
+			l.Debugln(s)
+		}
+		fileFullPathMap.Put(oneSeriesRootPathName, fileFullPathList)
+	})
+
+	return fileFullPathMap, nil
+}
+
+// SearchMatchedVideoFile 搜索符合后缀名的视频文件,现在也会把 BDMV 的文件搜索出来,但是这个并不是一个视频文件,需要在后续特殊处理
+func SearchMatchedVideoFile(l *logrus.Logger, dir string) ([]string, error) {
+
+	var fileFullPathList = make([]string, 0)
+	pathSep := string(os.PathSeparator)
+	files, err := os.ReadDir(dir)
+	if err != nil {
+		return nil, err
+	}
+	for _, curFile := range files {
+		fullPath := dir + pathSep + curFile.Name()
+		if curFile.IsDir() {
+			// 内层的错误就无视了
+			oneList, _ := SearchMatchedVideoFile(l, fullPath)
+			if oneList != nil {
+				fileFullPathList = append(fileFullPathList, oneList...)
+			}
+		} else {
+			// 这里就是文件了
+			bok, fakeBDMVVideoFile := FileNameIsBDMV(fullPath)
+			if bok == true {
+				// 这类文件后续的扫描字幕操作需要额外的处理
+				fileFullPathList = append(fileFullPathList, fakeBDMVVideoFile)
+				continue
+			}
+			if IsWantedVideoExtDef(curFile.Name()) == false {
+				// 不是期望的视频后缀名则跳过
+				continue
+			} else {
+				// 这里还有一种情况,就是蓝光, BDMV 下面会有一个 STREAM 文件夹,里面很多 m2ts 的视频组成
+				if filepath.Base(filepath.Dir(fullPath)) == "STREAM" {
+					l.Debugln("SearchMatchedVideoFile, Skip BDMV.STREAM:", fullPath)
+					continue
+				}
+
+				if filter.SkipFileInfo(l, curFile) == true {
+					continue
+				}
+
+				fileFullPathList = append(fileFullPathList, fullPath)
+			}
+		}
+	}
+	return fileFullPathList, nil
+}
+
+func SearchTVNfo(l *logrus.Logger, dir string) ([]string, error) {
+
+	var fileFullPathList = make([]string, 0)
+	pathSep := string(os.PathSeparator)
+	files, err := os.ReadDir(dir)
+	if err != nil {
+		return nil, err
+	}
+	for _, curFile := range files {
+		fullPath := dir + pathSep + curFile.Name()
+		if curFile.IsDir() {
+			// 内层的错误就无视了
+			oneList, _ := SearchTVNfo(l, fullPath)
+			if oneList != nil {
+				fileFullPathList = append(fileFullPathList, oneList...)
+			}
+		} else {
+			// 这里就是文件了
+			if strings.ToLower(curFile.Name()) != decode.MetadateTVNfo {
+				continue
+			} else {
+
+				if filter.SkipFileInfo(l, curFile) == true {
+					continue
+				}
+				fileFullPathList = append(fileFullPathList, fullPath)
+			}
+		}
+	}
+	return fileFullPathList, nil
+}
+
+// SearchSeriesAllEpsAndSubtitles 遍历这个连续剧目录下的所有视频文件,以及这个视频文件对应的字幕文件
+func SearchSeriesAllEpsAndSubtitles(l *logrus.Logger, dir string) {
+
+	pathVideoMap := make(map[string][]string, 0)
+	pathSubsMap := make(map[string][]string, 0)
+	err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
+		if err != nil {
+			return err
+		}
+		if d.IsDir() == true {
+			return nil
+		}
+		if IsWantedVideoExtDef(filepath.Ext(d.Name())) == true {
+			// 如果是符合视频的后缀名,那么就缓存起来
+			_, found := pathVideoMap[path]
+			if found == false {
+				pathVideoMap[path] = make([]string, 0)
+			}
+			pathVideoMap[path] = append(pathVideoMap[path], path)
+			return nil
+		}
+
+		if sub_parser_hub.IsSubExtWanted(filepath.Ext(d.Name())) == true {
+			// 如果是符合字幕的后缀名,那么就缓存起来
+			_, found := pathSubsMap[path]
+			if found == false {
+				pathSubsMap[path] = make([]string, 0)
+			}
+			pathSubsMap[path] = append(pathSubsMap[path], path)
+			return nil
+		}
+
+		return nil
+	})
+	if err != nil {
+		return
+	}
+}

+ 10 - 0
pkg/my_util/search_test.go

@@ -0,0 +1,10 @@
+package my_util
+
+import (
+	"testing"
+)
+
+func TestSearchSeriesAllEpsAndSubtitles(t *testing.T) {
+
+	SearchSeriesAllEpsAndSubtitles(nil, "X:\\连续剧\\Pantheon")
+}

+ 0 - 139
pkg/my_util/util.go

@@ -25,13 +25,9 @@ import (
 
 
 	"github.com/allanpk716/ChineseSubFinder/pkg/types/common"
 	"github.com/allanpk716/ChineseSubFinder/pkg/types/common"
 
 
-	"github.com/allanpk716/ChineseSubFinder/pkg/decode"
-	"github.com/allanpk716/ChineseSubFinder/pkg/filter"
 	"github.com/allanpk716/ChineseSubFinder/pkg/regex_things"
 	"github.com/allanpk716/ChineseSubFinder/pkg/regex_things"
 	"github.com/allanpk716/ChineseSubFinder/pkg/settings"
 	"github.com/allanpk716/ChineseSubFinder/pkg/settings"
-	"github.com/allanpk716/ChineseSubFinder/pkg/sort_things"
 	browser "github.com/allanpk716/fake-useragent"
 	browser "github.com/allanpk716/fake-useragent"
-	"github.com/emirpasic/gods/maps/treemap"
 	"github.com/go-resty/resty/v2"
 	"github.com/go-resty/resty/v2"
 	"github.com/google/uuid"
 	"github.com/google/uuid"
 	"github.com/sirupsen/logrus"
 	"github.com/sirupsen/logrus"
@@ -217,109 +213,6 @@ func IsFile(filePath string) bool {
 	return !s.IsDir()
 	return !s.IsDir()
 }
 }
 
 
-// VideoNameSearchKeywordMaker 拼接视频搜索的 title 和 年份
-func VideoNameSearchKeywordMaker(l *logrus.Logger, title string, year string) string {
-	iYear, err := strconv.Atoi(year)
-	if err != nil {
-		// 允许的错误
-		l.Errorln("VideoNameSearchKeywordMaker", "year to int", err)
-		iYear = 0
-	}
-	searchKeyword := title
-	if iYear >= 2020 {
-		searchKeyword = searchKeyword + " " + year
-	}
-
-	return searchKeyword
-}
-
-// SearchMatchedVideoFileFromDirs 搜索符合后缀名的视频文件
-func SearchMatchedVideoFileFromDirs(l *logrus.Logger, dirs []string) (*treemap.Map, error) {
-
-	defer func() {
-		l.Infoln("SearchMatchedVideoFileFromDirs End")
-		l.Infoln(" --------------------------------------------------")
-	}()
-	l.Infoln(" --------------------------------------------------")
-	l.Infoln("SearchMatchedVideoFileFromDirs Start...")
-
-	var fileFullPathMap = treemap.NewWithStringComparator()
-	for _, dir := range dirs {
-
-		matchedVideoFile, err := SearchMatchedVideoFile(l, dir)
-		if err != nil {
-			return nil, err
-		}
-		value, found := fileFullPathMap.Get(dir)
-		if found == false {
-			fileFullPathMap.Put(dir, matchedVideoFile)
-		} else {
-			value = append(value.([]string), matchedVideoFile...)
-			fileFullPathMap.Put(dir, value)
-		}
-	}
-
-	fileFullPathMap.Each(func(seriesRootPathName interface{}, seriesNames interface{}) {
-
-		oneSeriesRootPathName := seriesRootPathName.(string)
-		fileFullPathList := seriesNames.([]string)
-		// 排序,从最新的到最早的
-		fileFullPathList = sort_things.SortByModTime(fileFullPathList)
-		for _, s := range fileFullPathList {
-			l.Debugln(s)
-		}
-		fileFullPathMap.Put(oneSeriesRootPathName, fileFullPathList)
-	})
-
-	return fileFullPathMap, nil
-}
-
-// SearchMatchedVideoFile 搜索符合后缀名的视频文件,现在也会把 BDMV 的文件搜索出来,但是这个并不是一个视频文件,需要在后续特殊处理
-func SearchMatchedVideoFile(l *logrus.Logger, dir string) ([]string, error) {
-
-	var fileFullPathList = make([]string, 0)
-	pathSep := string(os.PathSeparator)
-	files, err := os.ReadDir(dir)
-	if err != nil {
-		return nil, err
-	}
-	for _, curFile := range files {
-		fullPath := dir + pathSep + curFile.Name()
-		if curFile.IsDir() {
-			// 内层的错误就无视了
-			oneList, _ := SearchMatchedVideoFile(l, fullPath)
-			if oneList != nil {
-				fileFullPathList = append(fileFullPathList, oneList...)
-			}
-		} else {
-			// 这里就是文件了
-			bok, fakeBDMVVideoFile := FileNameIsBDMV(fullPath)
-			if bok == true {
-				// 这类文件后续的扫描字幕操作需要额外的处理
-				fileFullPathList = append(fileFullPathList, fakeBDMVVideoFile)
-				continue
-			}
-			if IsWantedVideoExtDef(curFile.Name()) == false {
-				// 不是期望的视频后缀名则跳过
-				continue
-			} else {
-				// 这里还有一种情况,就是蓝光, BDMV 下面会有一个 STREAM 文件夹,里面很多 m2ts 的视频组成
-				if filepath.Base(filepath.Dir(fullPath)) == "STREAM" {
-					l.Debugln("SearchMatchedVideoFile, Skip BDMV.STREAM:", fullPath)
-					continue
-				}
-
-				if filter.SkipFileInfo(l, curFile) == true {
-					continue
-				}
-
-				fileFullPathList = append(fileFullPathList, fullPath)
-			}
-		}
-	}
-	return fileFullPathList, nil
-}
-
 // FileNameIsBDMV 是否是 BDMV 蓝光目录,符合返回 true,以及 fakseVideoFPath
 // FileNameIsBDMV 是否是 BDMV 蓝光目录,符合返回 true,以及 fakseVideoFPath
 func FileNameIsBDMV(id_bdmv_fileFPath string) (bool, string) {
 func FileNameIsBDMV(id_bdmv_fileFPath string) (bool, string) {
 	/*
 	/*
@@ -345,38 +238,6 @@ func FileNameIsBDMV(id_bdmv_fileFPath string) (bool, string) {
 	return false, ""
 	return false, ""
 }
 }
 
 
-func SearchTVNfo(l *logrus.Logger, dir string) ([]string, error) {
-
-	var fileFullPathList = make([]string, 0)
-	pathSep := string(os.PathSeparator)
-	files, err := os.ReadDir(dir)
-	if err != nil {
-		return nil, err
-	}
-	for _, curFile := range files {
-		fullPath := dir + pathSep + curFile.Name()
-		if curFile.IsDir() {
-			// 内层的错误就无视了
-			oneList, _ := SearchTVNfo(l, fullPath)
-			if oneList != nil {
-				fileFullPathList = append(fileFullPathList, oneList...)
-			}
-		} else {
-			// 这里就是文件了
-			if strings.ToLower(curFile.Name()) != decode.MetadateTVNfo {
-				continue
-			} else {
-
-				if filter.SkipFileInfo(l, curFile) == true {
-					continue
-				}
-				fileFullPathList = append(fileFullPathList, fullPath)
-			}
-		}
-	}
-	return fileFullPathList, nil
-}
-
 // IsWantedVideoExtDef 后缀名是否符合规则
 // IsWantedVideoExtDef 后缀名是否符合规则
 func IsWantedVideoExtDef(fileName string) bool {
 func IsWantedVideoExtDef(fileName string) bool {
 
 

+ 10 - 1
pkg/video_list_helper/subtitles.go

@@ -1,6 +1,8 @@
 package video_list_helper
 package video_list_helper
 
 
-import "github.com/allanpk716/ChineseSubFinder/pkg/sub_helper"
+import (
+	"github.com/allanpk716/ChineseSubFinder/pkg/sub_helper"
+)
 
 
 // GetMovieSubtitles 获取一部电影的字幕文件列表
 // GetMovieSubtitles 获取一部电影的字幕文件列表
 func (v *VideoListHelper) GetMovieSubtitles(movieFPath string) []string {
 func (v *VideoListHelper) GetMovieSubtitles(movieFPath string) []string {
@@ -14,3 +16,10 @@ func (v *VideoListHelper) GetMovieSubtitles(movieFPath string) []string {
 	outSubtitles = append(outSubtitles, subtitles...)
 	outSubtitles = append(outSubtitles, subtitles...)
 	return outSubtitles
 	return outSubtitles
 }
 }
+
+func (v *VideoListHelper) GetSeriesSubtitles(seriesDir string) []string {
+
+	// 一次性搜索这个连续剧所有的视频,然后针对每一集再搜索对应的字幕出来
+	// 1. 获取这个连续剧的所有视频
+	return nil
+}