فهرست منبع

修复字幕文件名称乱码无法保存的问题

Signed-off-by: 716 <[email protected]>
716 4 سال پیش
والد
کامیت
aa6c8f961c
10فایلهای تغییر یافته به همراه57 افزوده شده و 21 حذف شده
  1. 1 0
      charset/charset.go
  2. 5 4
      downloader_test.go
  3. 1 0
      go.mod
  4. 1 0
      go.sum
  5. 1 1
      mark_system/marking_system.go
  6. 14 2
      model/deal_sub.go
  7. 18 0
      model/decode.go
  8. 11 11
      model/sub_helper.go
  9. 1 1
      series_helper/seriesHelper.go
  10. 4 2
      sub_supplier/subSupplierHub.go

+ 1 - 0
charset/charset.go

@@ -54,6 +54,7 @@ var charsetAlias = map[string]string{
 	"hzgb2312": "HZ-GB-2312",
 	"GB2312":   "HZ-GB-2312",
 	"gb2312":   "HZ-GB-2312",
+	"GB-18030": "GB18030",
 }
 
 func Convert(dstCharset Charset, srcCharset Charset, src string) (dst string, err error) {

+ 5 - 4
downloader_test.go

@@ -7,10 +7,10 @@ import (
 
 func TestDownloader_DownloadSub4Movie(t *testing.T) {
 	var err error
-	//dirRoot := "X:\\电影\\Spiral From the Book of Saw (2021)"
+	dirRoot := "X:\\电影\\Spiral From the Book of Saw (2021)"
 	//dirRoot := "X:\\电影\\Oslo (2021)"
 	//dirRoot := "X:\\电影\\The Devil All the Time (2020)"
-	dirRoot := "X:\\电影\\21座桥 (2019)"
+	//dirRoot := "X:\\电影\\21座桥 (2019)"
 	//dirRoot := "X:\\电影\\An Invisible Sign (2010)"
 	//dirRoot := "X:\\电影\\送你一朵小红花 (2020)"
 	//dirRoot := "X:\\电影\\冰海陷落 (2018)"
@@ -29,10 +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:\\连续剧"
 

+ 1 - 0
go.mod

@@ -46,6 +46,7 @@ require (
 	golang.org/x/sys v0.0.0-20210503173754-0981d6026fa6 // indirect
 	golang.org/x/text v0.3.6
 	gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
+	gopkg.in/errgo.v2 v2.1.0
 	gopkg.in/ini.v1 v1.62.0 // indirect
 	gopkg.in/yaml.v2 v2.4.0 // indirect
 	gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect

+ 1 - 0
go.sum

@@ -435,6 +435,7 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33
 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
+gopkg.in/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8=
 gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
 gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
 gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=

+ 1 - 1
mark_system/marking_system.go

@@ -105,7 +105,7 @@ func (m MarkingSystem) parseSubFileInfo(organizeSubFiles []string) map[string][]
 		}
 		if subFileInfo == nil {
 			// 说明这个字幕无法解析
-			m.log.Warnln(oneSubFileFullPath, "DetermineFileTypeFromFile is nill")
+			m.log.Warnln("MarkingSystem.parseSubFileInfo", oneSubFileFullPath, "DetermineFileTypeFromFile is nill")
 			continue
 		}
 

+ 14 - 2
model/deal_sub.go

@@ -2,12 +2,24 @@ package model
 
 import (
 	"github.com/allanpk716/ChineseSubFinder/common"
+	"path/filepath"
 	"strconv"
 )
 
 // GetFrontNameAndOrgName 返回的名称包含,那个网站下载的,这个网站中排名第几,文件名
-func GetFrontNameAndOrgName(info common.SupplierSubInfo) string {
-	return "[" + info.FromWhere + "]_" + strconv.FormatInt(info.TopN,10) + "_" + info.Name
+func GetFrontNameAndOrgName(info *common.SupplierSubInfo) string {
+
+	infoName := ""
+	path, err := GetVideoInfoFromFileName(info.Name)
+	if err != nil {
+		GetLogger().Warnln("", err)
+		infoName = info.Name
+	} else {
+		infoName = path.Title + "_S" + strconv.Itoa(path.Season) + "E" + strconv.Itoa(path.Episode) + filepath.Ext(info.Name)
+	}
+	info.Name = infoName
+
+	return "[" + info.FromWhere + "]_" + strconv.FormatInt(info.TopN,10) + "_" + infoName
 }
 
 // AddFrontName 添加文件的前缀

+ 18 - 0
model/decode.go

@@ -220,6 +220,24 @@ func GetImdbInfo4OneSeriesEpisode(oneEpFPath string) (common.VideoIMDBInfo, erro
 	return imdbInfo, common.CanNotFindEpAiredTime
 }
 
+// GetVideoInfoFromFileName 从文件名推断文件信息
+func GetVideoInfoFromFileName(fileName string) (*PTN.TorrentInfo, error) {
+
+	parse, err := PTN.Parse(fileName)
+	if err != nil {
+		return nil, err
+	}
+	compile, err := regexp.Compile(regFixTitle2)
+	if err != nil {
+		return nil, err
+	}
+	match := compile.ReplaceAllString(parse.Title, "")
+	match = strings.TrimRight(match, "")
+	parse.Title = match
+
+	return parse, nil
+}
+
 //GetVideoInfoFromFileFullPath 从全文件路径推断文件信息
 func GetVideoInfoFromFileFullPath(videoFileFullPath string) (*PTN.TorrentInfo, time.Time, error) {
 

+ 11 - 11
model/sub_helper.go

@@ -26,16 +26,16 @@ func OrganizeDlSubFiles(tmpFolderName string, subInfos []common.SupplierSubInfo)
 	// 第三方的解压库,首先不支持 io.Reader 的操作,也就是得缓存到本地硬盘再读取解压
 	// 且使用 walk 会无法解压 rar,得指定具体的实例,太麻烦了,直接用通用的接口得了,就是得都缓存下来再判断
 	// 基于以上两点,写了一堆啰嗦的逻辑···
-	for _, subInfo := range subInfos {
+	for i, _ := range subInfos {
 		// 先存下来,保存是时候需要前缀,前缀就是从那个网站下载来的
-		nowFileSaveFullPath := path.Join(tmpFolderFullPath, GetFrontNameAndOrgName(subInfo))
-		err = utils.OutputFile(nowFileSaveFullPath, subInfo.Data)
+		nowFileSaveFullPath := path.Join(tmpFolderFullPath, GetFrontNameAndOrgName(&subInfos[i]))
+		err = utils.OutputFile(nowFileSaveFullPath, subInfos[i].Data)
 		if err != nil {
-			GetLogger().Errorln("getFrontNameAndOrgName - OutputFile",subInfo.FromWhere, subInfo.Name, subInfo.TopN, err)
+			GetLogger().Errorln("getFrontNameAndOrgName - OutputFile",subInfos[i].FromWhere, subInfos[i].Name, subInfos[i].TopN, err)
 			continue
 		}
-		nowExt := strings.ToLower(subInfo.Ext)
-		epsKey := GetEpisodeKeyName(subInfo.Season, subInfo.Episode)
+		nowExt := strings.ToLower(subInfos[i].Ext)
+		epsKey := GetEpisodeKeyName(subInfos[i].Season, subInfos[i].Episode)
 		_, ok := siteSubInfoDict[epsKey]
 		if ok == false {
 			// 不存在则实例化
@@ -51,7 +51,7 @@ func OrganizeDlSubFiles(tmpFolderName string, subInfos []common.SupplierSubInfo)
 		} else {
 			// 那么就是需要解压的文件了
 			// 解压,给一个单独的文件夹
-			unzipTmpFolder := path.Join(tmpFolderFullPath, subInfo.FromWhere)
+			unzipTmpFolder := path.Join(tmpFolderFullPath, subInfos[i].FromWhere)
 			err = os.MkdirAll(unzipTmpFolder, os.ModePerm)
 			if err != nil {
 				return nil, err
@@ -59,23 +59,23 @@ func OrganizeDlSubFiles(tmpFolderName string, subInfos []common.SupplierSubInfo)
 			err = UnArchiveFile(nowFileSaveFullPath, unzipTmpFolder)
 			// 解压完成后,遍历受支持的字幕列表,加入缓存列表
 			if err != nil {
-				GetLogger().Errorln("archiver.UnArchive", subInfo.FromWhere, subInfo.Name, subInfo.TopN, err)
+				GetLogger().Errorln("archiver.UnArchive", subInfos[i].FromWhere, subInfos[i].Name, subInfos[i].TopN, err)
 				continue
 			}
 			// 搜索这个目录下的所有符合字幕格式的文件
 			subFileFullPaths, err := SearchMatchedSubFile(unzipTmpFolder)
 			if err != nil {
-				GetLogger().Errorln("searchMatchedSubFile", subInfo.FromWhere, subInfo.Name, subInfo.TopN, err)
+				GetLogger().Errorln("searchMatchedSubFile", subInfos[i].FromWhere, subInfos[i].Name, subInfos[i].TopN, err)
 				continue
 			}
 			// 这里需要给这些下载到的文件进行改名,加是从那个网站来的前缀,后续好查找
 			for _, fileFullPath := range subFileFullPaths {
-				newSubName := AddFrontName(subInfo, filepath.Base(fileFullPath))
+				newSubName := AddFrontName(subInfos[i], filepath.Base(fileFullPath))
 				newSubNameFullPath := path.Join(tmpFolderFullPath, newSubName)
 				// 改名
 				err = os.Rename(fileFullPath, newSubNameFullPath)
 				if err != nil {
-					GetLogger().Errorln("os.Rename", subInfo.FromWhere, subInfo.Name, subInfo.TopN, err)
+					GetLogger().Errorln("os.Rename", subInfos[i].FromWhere, subInfos[i].Name, subInfos[i].TopN, err)
 					continue
 				}
 				// 加入缓存列表

+ 1 - 1
series_helper/seriesHelper.go

@@ -75,7 +75,7 @@ func ReadSeriesInfoFromDir(seriesDir string, imdbInfo *imdb.Title) (*common.Seri
 		}
 		if subParserFileInfo == nil {
 			// 说明这个字幕无法解析
-			model.GetLogger().Warnln(seriesInfo.DirPath, "DetermineFileTypeFromFile is nill")
+			model.GetLogger().Warnln("ReadSeriesInfoFromDir", seriesInfo.DirPath, "DetermineFileTypeFromFile is nill")
 			continue
 		}
 		epsKey := model.GetEpisodeKeyName(info.Season, info.Episode)

+ 4 - 2
sub_supplier/subSupplierHub.go

@@ -87,6 +87,8 @@ func (d SubSupplierHub) DownloadSub4Series(seriesDirPath string, index int) (*co
 	// 整理字幕,比如解压什么的
 	// 每一集 SxEx - 对应解压整理后的字幕列表
 	organizeSubFiles, err := model.OrganizeDlSubFiles(filepath.Base(seriesDirPath), subInfos)
-
-	return seriesInfo, organizeSubFiles, errors.Newf("OrganizeDlSubFiles %v %v", seriesDirPath , err)
+	if err != nil {
+		return nil, nil, errors.Newf("OrganizeDlSubFiles %v %v", seriesDirPath , err)
+	}
+	return seriesInfo, organizeSubFiles, nil
 }