فهرست منبع

完成整季字幕保存,且整季字幕优先级最高,会替换之前的字幕

Signed-off-by: allan716 <[email protected]>
allan716 4 سال پیش
والد
کامیت
c7685d1736
5فایلهای تغییر یافته به همراه40 افزوده شده و 18 حذف شده
  1. 3 3
      common/common.go
  2. 30 8
      downloader.go
  3. 2 2
      movie_helper/movieHelper.go
  4. 4 4
      series_helper/seriesHelper.go
  5. 1 1
      sub_supplier/zimuku/zimuku.go

+ 3 - 3
common/common.go

@@ -6,9 +6,9 @@ const HTMLTimeOut = 60 * time.Second	// HttpClient 超时时间
 const DownloadSubsPerSite = 1 // 默认,每个网站下载一个字幕,允许额外传参调整
 const DownloadSubsPerSite = 1 // 默认,每个网站下载一个字幕,允许额外传参调整
 
 
 const (
 const (
-	DebugFolder = "debugthings"
-	TmpFolder = "tmpthings"
-	DownloadSubDuring30Days = "720h"
+	DebugFolder              = "debugthings"
+	TmpFolder                = "tmpthings"
+	DownloadSubDuring3Months = "2160h"
 )
 )
 
 
 const (
 const (

+ 30 - 8
downloader.go

@@ -108,14 +108,19 @@ func (d Downloader) DownloadSub4Series(dir string) error {
 			d.log.Errorln("subSupplierHub.DownloadSub4Series", oneSeriesPath ,err)
 			d.log.Errorln("subSupplierHub.DownloadSub4Series", oneSeriesPath ,err)
 			return err
 			return err
 		}
 		}
-
 		// 只针对需要下载字幕的视频进行字幕的选择保存
 		// 只针对需要下载字幕的视频进行字幕的选择保存
 		for epsKey, episodeInfo := range seriesInfo.NeedDlEpsKeyList {
 		for epsKey, episodeInfo := range seriesInfo.NeedDlEpsKeyList {
 			// 匹配对应的 Eps 去处理
 			// 匹配对应的 Eps 去处理
 			d.oneVideoSelectBestSub(episodeInfo.FileFullPath, organizeSubFiles[epsKey])
 			d.oneVideoSelectBestSub(episodeInfo.FileFullPath, organizeSubFiles[epsKey])
 		}
 		}
-		// 这里会拿到一份季度字幕的列表比如,S1E0 S2E0 S3E0
-		d.saveFullSeasonSub(seriesInfo, organizeSubFiles)
+		// 这里会拿到一份季度字幕的列表比如,Key 是 S1E0 S2E0 S3E0,value 是新的存储位置
+		fullSeasonSubDict := d.saveFullSeasonSub(seriesInfo, organizeSubFiles)
+		// TODO 季度的字幕包,应该优先于零散的字幕吧,暂定就这样了,注意是全部都替换
+		for _, episodeInfo := range seriesInfo.EpList {
+			// 匹配对应的 Eps 去处理
+			seasonEpsKey := model.GetEpisodeKeyName(episodeInfo.Season, episodeInfo.Episode)
+			d.oneVideoSelectBestSub(episodeInfo.FileFullPath, fullSeasonSubDict[seasonEpsKey])
+		}
 	}
 	}
 	return nil
 	return nil
 }
 }
@@ -167,26 +172,43 @@ func (d Downloader) oneVideoSelectBestSub(oneVideoFullPath string, organizeSubFi
 }
 }
 
 
 // saveFullSeasonSub 这里就需要单独存储到连续剧每一季的文件夹的特殊文件夹中
 // saveFullSeasonSub 这里就需要单独存储到连续剧每一季的文件夹的特殊文件夹中
-func (d Downloader) saveFullSeasonSub(seriesInfo *common.SeriesInfo, organizeSubFiles map[string][]string) {
+func (d Downloader) saveFullSeasonSub(seriesInfo *common.SeriesInfo, organizeSubFiles map[string][]string) map[string][]string {
+
+	var fullSeasonSubDict = make(map[string][]string)
 
 
 	for _, season := range seriesInfo.SeasonDict {
 	for _, season := range seriesInfo.SeasonDict {
-		epsKey := model.GetEpisodeKeyName(season, 0)
-		subs, ok := organizeSubFiles[epsKey]
+		seasonKey := model.GetEpisodeKeyName(season, 0)
+		subs, ok := organizeSubFiles[seasonKey]
 		if ok == false {
 		if ok == false {
 			continue
 			continue
 		}
 		}
 		for _, sub := range subs {
 		for _, sub := range subs {
 			subFileName := filepath.Base(sub)
 			subFileName := filepath.Base(sub)
-			newSeasonSubRootPath := path.Join(seriesInfo.DirPath, epsKey)
+			newSeasonSubRootPath := path.Join(seriesInfo.DirPath, "Sub_"+seasonKey)
 			_ = os.MkdirAll(newSeasonSubRootPath, os.ModePerm)
 			_ = os.MkdirAll(newSeasonSubRootPath, os.ModePerm)
 			newSubFullPath := path.Join(newSeasonSubRootPath, subFileName)
 			newSubFullPath := path.Join(newSeasonSubRootPath, subFileName)
-			err := os.Rename(sub, newSubFullPath)
+			_, err := model.CopyFile(newSubFullPath, sub)
 			if err != nil {
 			if err != nil {
 				d.log.Errorln("saveFullSeasonSub", subFileName, err)
 				d.log.Errorln("saveFullSeasonSub", subFileName, err)
 				continue
 				continue
 			}
 			}
+			// 从字幕的文件名推断是 哪一季 的 那一集
+			_, gusSeason, gusEpisode, err := model.GetSeasonAndEpisodeFromSubFileName(subFileName)
+			if err != nil {
+				return nil
+			}
+			// 把整季的字幕缓存位置也提供出去,如果之前没有下载到的,这里返回出来的可以补上
+			seasonEpsKey := model.GetEpisodeKeyName(gusSeason, gusEpisode)
+			_, ok := fullSeasonSubDict[seasonEpsKey]
+			if ok == false {
+				// 初始化
+				fullSeasonSubDict[seasonEpsKey] = make([]string, 0)
+			}
+			fullSeasonSubDict[seasonEpsKey] = append(fullSeasonSubDict[seasonEpsKey], sub)
 		}
 		}
 	}
 	}
+
+	return fullSeasonSubDict
 }
 }
 
 
 // 在前面需要进行语言的筛选、排序,这里仅仅是存储
 // 在前面需要进行语言的筛选、排序,这里仅仅是存储

+ 2 - 2
movie_helper/movieHelper.go

@@ -106,12 +106,12 @@ func MovieNeedDlSub(videoFullPath string) (bool, error) {
 	}
 	}
 	// 资源下载的时间后的多少天内都进行字幕的自动下载,替换原有的字幕
 	// 资源下载的时间后的多少天内都进行字幕的自动下载,替换原有的字幕
 	currentTime := time.Now()
 	currentTime := time.Now()
-	dayRange, _ := time.ParseDuration(common.DownloadSubDuring30Days)
+	dayRange, _ := time.ParseDuration(common.DownloadSubDuring3Months)
 	_, modifyTime, err := model.GetVideoInfoFromFileFullPath(videoFullPath)
 	_, modifyTime, err := model.GetVideoInfoFromFileFullPath(videoFullPath)
 	if err != nil {
 	if err != nil {
 		return false, err
 		return false, err
 	}
 	}
-	// 30 天内,或者没有字幕都要进行下载
+	// 3个月内,或者没有字幕都要进行下载
 	if modifyTime.Add(dayRange).After(currentTime) == true || found == false {
 	if modifyTime.Add(dayRange).After(currentTime) == true || found == false {
 		// 需要下载的
 		// 需要下载的
 		return true, nil
 		return true, nil

+ 4 - 4
series_helper/seriesHelper.go

@@ -202,8 +202,8 @@ func GetSeriesList(dir string) ([]string, error) {
 func whichEpsNeedDownloadSub(seriesInfo *common.SeriesInfo) map[string]common.EpisodeInfo {
 func whichEpsNeedDownloadSub(seriesInfo *common.SeriesInfo) map[string]common.EpisodeInfo {
 	var needDlSubEpsList = make(map[string]common.EpisodeInfo, 0)
 	var needDlSubEpsList = make(map[string]common.EpisodeInfo, 0)
 	currentTime := time.Now()
 	currentTime := time.Now()
-	// 30 天
-	dayRange, _ := time.ParseDuration(common.DownloadSubDuring30Days)
+	// 3个月
+	dayRange, _ := time.ParseDuration(common.DownloadSubDuring3Months)
 	for _, epsInfo := range seriesInfo.EpList {
 	for _, epsInfo := range seriesInfo.EpList {
 		// 如果没有字幕,则加入下载列表
 		// 如果没有字幕,则加入下载列表
 		// 这一集下载后的30天内,都进行字幕的下载
 		// 这一集下载后的30天内,都进行字幕的下载
@@ -213,9 +213,9 @@ func whichEpsNeedDownloadSub(seriesInfo *common.SeriesInfo) map[string]common.Ep
 			needDlSubEpsList[epsKey] = epsInfo
 			needDlSubEpsList[epsKey] = epsInfo
 		} else {
 		} else {
 			if len(epsInfo.SubAlreadyDownloadedList) > 0 {
 			if len(epsInfo.SubAlreadyDownloadedList) > 0 {
-				model.GetLogger().Infoln("Skip because find sub file", epsInfo.Title, epsInfo.Season, epsInfo.Episode)
+				model.GetLogger().Infoln("Skip because find sub file and over 30 days,", epsInfo.Title, epsInfo.Season, epsInfo.Episode)
 			} else if epsInfo.ModifyTime.Add(dayRange).After(currentTime) == false {
 			} else if epsInfo.ModifyTime.Add(dayRange).After(currentTime) == false {
-				model.GetLogger().Infoln("Skip because 30 days pass", epsInfo.Title, epsInfo.Season, epsInfo.Episode)
+				model.GetLogger().Infoln("Skip because 30 days pass,", epsInfo.Title, epsInfo.Season, epsInfo.Episode)
 			}
 			}
 		}
 		}
 	}
 	}

+ 1 - 1
sub_supplier/zimuku/zimuku.go

@@ -182,7 +182,7 @@ func (s Supplier) whichEpisodeNeedDownloadSub(seriesInfo *common.SeriesInfo, All
 	for _, subInfo := range AllSeasonSubResult.SubInfos {
 	for _, subInfo := range AllSeasonSubResult.SubInfos {
 		_, season, episode, err := model.GetSeasonAndEpisodeFromSubFileName(subInfo.Name)
 		_, season, episode, err := model.GetSeasonAndEpisodeFromSubFileName(subInfo.Name)
 		if err != nil {
 		if err != nil {
-			s.log.Errorln("SubInfos GetSubListFromFile4Series.GetVideoInfoFromFileFullPath", subInfo.Name, err)
+			s.log.Errorln("whichEpisodeNeedDownloadSub.GetVideoInfoFromFileFullPath", subInfo.Name, err)
 			continue
 			continue
 		}
 		}
 		subInfo.Season = season
 		subInfo.Season = season