Browse Source

修复电影字幕保存时候传递丢失的问题

Signed-off-by: allan716 <[email protected]>
allan716 4 years ago
parent
commit
cb3afe2885
7 changed files with 30 additions and 12 deletions
  1. 12 0
      common/reqParam.go
  2. 4 1
      downloader.go
  3. 2 1
      downloader_test.go
  4. 1 0
      main.go
  5. 2 3
      mark_system/marking_system.go
  6. 5 4
      model/sub_helper.go
  7. 4 3
      sub_supplier/subSupplierHub.go

+ 12 - 0
common/reqParam.go

@@ -6,6 +6,7 @@ type ReqParam struct {
 	SaveMultiSub bool		// 存储每个网站 Top1 的字幕
 	DebugMode bool			// 调试标志位
 	Threads   int			// 同时并发的线程数(准确来说在go中不是线程,是 goroutine)
+	SubTypePriority  int	// 字幕下载的优先级,0 是自动,1 是 srt 优先,2 是 ass/ssa 优先
 	HttpProxy string		// HttpClient 相关
 	UserAgent string		// HttpClient 相关
 	Referer   string		// HttpClient 相关
@@ -13,3 +14,14 @@ type ReqParam struct {
 	Charset   string		// HttpClient 相关
 	Topic	  int			// 搜索结果的时候,返回 Topic N 以内的
 }
+
+func NewReqParam() *ReqParam {
+	r := ReqParam{
+		UserExtList: make([]string, 0),
+		SaveMultiSub: false,
+		DebugMode: false,
+		Threads: 2,
+		SubTypePriority: 0,
+	}
+	return &r
+}

+ 4 - 1
downloader.go

@@ -39,12 +39,15 @@ func NewDownloader(_reqParam ...common.ReqParam) *Downloader {
 		if downloader.reqParam.Topic > 0 && downloader.reqParam.Topic != downloader.topic {
 			downloader.topic = downloader.reqParam.Topic
 		}
+
 		// 并发线程的范围控制
 		if downloader.reqParam.Threads <= 0 {
 			downloader.reqParam.Threads = 2
 		} else if downloader.reqParam.Threads >= 10 {
 			downloader.reqParam.Threads = 10
 		}
+	} else {
+		downloader.reqParam = *common.NewReqParam()
 	}
 
 	var sitesSequence = make([]string, 0)
@@ -53,7 +56,7 @@ func NewDownloader(_reqParam ...common.ReqParam) *Downloader {
 	sitesSequence = append(sitesSequence, common.SubSiteSubHd)
 	sitesSequence = append(sitesSequence, common.SubSiteXunLei)
 	sitesSequence = append(sitesSequence, common.SubSiteShooter)
-	downloader.mk = mark_system.NewMarkingSystem(sitesSequence)
+	downloader.mk = mark_system.NewMarkingSystem(sitesSequence, downloader.reqParam.SubTypePriority)
 
 	return &downloader
 }

+ 2 - 1
downloader_test.go

@@ -17,7 +17,8 @@ func TestDownloader_DownloadSub4Movie(t *testing.T) {
 	//dirRoot := "X:\\电影"
 
 	dl := NewDownloader(common.ReqParam{
-		SaveMultiSub: true,
+		SaveMultiSub: false,
+		SubTypePriority: 1,
 	})
 	err = dl.DownloadSub4Movie(dirRoot)
 	if err != nil {

+ 1 - 0
main.go

@@ -50,6 +50,7 @@ func main() {
 		DebugMode: config.DebugMode,
 		SaveMultiSub: config.SaveMultiSub,
 		Threads: config.Threads,
+		SubTypePriority: config.SubTypePriority,
 	})
 	//任务还没执行完,下一次执行时间到来,下一次执行就跳过不执行
 	c := cron.New(cron.WithChain(cron.SkipIfStillRunning(cron.DefaultLogger)))

+ 2 - 3
mark_system/marking_system.go

@@ -15,7 +15,6 @@ type MarkingSystem struct {
 	SubTypePriority int					// 字幕格式的优先级
 	subParserHub *model.SubParserHub
 }
-// TODO 在这里添加字幕格式选择的逻辑
 
 func NewMarkingSystem(subSiteSequence []string, subTypePriority int) *MarkingSystem {
 	mk := MarkingSystem{subSiteSequence: subSiteSequence,
@@ -35,7 +34,7 @@ func (m MarkingSystem) SelectOneSubFile(organizeSubFiles []string) *common.SubPa
 		if ok == false {
 			continue
 		}
-		info := model.FindChineseBestSubtitle(value)
+		info := model.FindChineseBestSubtitle(value, m.SubTypePriority)
 		if info != nil {
 			finalSubFile = *info
 			return &finalSubFile
@@ -52,7 +51,7 @@ func (m MarkingSystem) SelectEachSiteTop1SubFile(organizeSubFiles []string) ([]s
 	subInfoDict := m.parseSubFileInfo(organizeSubFiles)
 	for siteName, infos := range subInfoDict {
 		// 每个网站保存一个
-		info := model.FindChineseBestSubtitle(infos)
+		info := model.FindChineseBestSubtitle(infos, m.SubTypePriority)
 		if info != nil {
 			outSiteName = append(outSiteName, siteName)
 			outSubParserFileInfos = append(outSubParserFileInfos, *info)

+ 5 - 4
model/sub_helper.go

@@ -124,10 +124,11 @@ func FindChineseBestSubtitle(subs []common.SubParserFileInfo, subTypePriority in
 						return &info
 					}
 				}
-			}
-			// 优先双语
-			if IsBilingualSubtitle(info.Lang) == true {
-				return &info
+			} else {
+				// 优先双语
+				if IsBilingualSubtitle(info.Lang) == true {
+					return &info
+				}
 			}
 		}
 	}

+ 4 - 3
sub_supplier/subSupplierHub.go

@@ -53,11 +53,12 @@ func (d SubSupplierHub) DownloadSub4Movie(videoFullPath string, index int) ([]st
 		if err != nil {
 			return nil, err
 		}
-		// 因为是下载电影,所以直接返回第一个就好了,默认应该key是 S-1E-1
+		// 因为是下载电影,需要合并返回
+		var outSubFileFullPathList = make([]string, 0)
 		for s, _ := range organizeSubFiles {
-			return organizeSubFiles[s], nil
+			outSubFileFullPathList = append(outSubFileFullPathList, organizeSubFiles[s]...)
 		}
-		return nil, nil
+		return outSubFileFullPathList, nil
 	} else {
 		// 无需下载字幕
 		return nil, nil