Browse Source

去除跳过已下载的设置逻辑,如果下载的视频30天内,都进行字幕的下载,超过30天则不下载,除非没有字幕在当前目录下

Signed-off-by: 716 <[email protected]>
716 4 years ago
parent
commit
fc0b8f52c0
5 changed files with 49 additions and 14 deletions
  1. 1 0
      common/common.go
  2. 1 1
      downloader.go
  3. 5 1
      main.go
  4. 40 10
      sub_supplier/subSupplierHub.go
  5. 2 2
      sub_supplier/zimuku/zimuku.go

+ 1 - 0
common/common.go

@@ -8,6 +8,7 @@ const DownloadSubsPerSite = 1 // 默认,每个网站下载一个字幕,允
 const (
 	DebugFolder = "debugthings"
 	TmpFolder = "tmpthings"
+	DownloadSubDuring30Days = "720h"
 )
 
 const (

+ 1 - 1
downloader.go

@@ -70,7 +70,7 @@ func (d Downloader) DownloadSub4Movie(dir string) error {
 	// 一个视频文件同时多个站点查询,阻塞完毕后,在进行下一个
 	for i, oneVideoFullPath := range nowVideoList {
 		// 字幕都下载缓存好了,需要抉择存哪一个,优先选择中文双语的,然后到中文
-		organizeSubFiles, err := subSupplierHub.DownloadSub4Movie(oneVideoFullPath, i, d.reqParam.FoundExistSubFileThanSkip)
+		organizeSubFiles, err := subSupplierHub.DownloadSub4Movie(oneVideoFullPath, i)
 		if err != nil {
 			d.log.Errorln("subSupplierHub.DownloadSub4Movie", oneVideoFullPath ,err)
 			continue

+ 5 - 1
main.go

@@ -55,6 +55,11 @@ func main() {
 	c := cron.New(cron.WithChain(cron.SkipIfStillRunning(cron.DefaultLogger)))
 	// 定时器
 	entryID, err := c.AddFunc("@every " + config.EveryTime, func() {
+		defer func() {
+			log.Infoln("Download Timer End...")
+		}()
+
+		log.Infoln("Download Timer Started...")
 		// 开始下载
 		err := downloader.DownloadSub4Movie(config.MovieFolder)
 		if err != nil {
@@ -78,7 +83,6 @@ func main() {
 
 	c.Start()
 
-	log.Infoln("Download Timer Started...")
 	// 阻塞
 	select {}
 }

+ 40 - 10
sub_supplier/subSupplierHub.go

@@ -12,6 +12,7 @@ import (
 	"path/filepath"
 	"strconv"
 	"strings"
+	"time"
 )
 
 type SubSupplierHub struct {
@@ -32,32 +33,61 @@ func NewSubSupplierHub(one _interface.ISupplier,_inSupplier ..._interface.ISuppl
 	return &s
 }
 
-// DownloadSub4Movie 某一个视频的字幕下载,下载完毕后,返回下载缓存每个字幕的位置
-func (d SubSupplierHub) DownloadSub4Movie(videoFullPath string, index int, foundExistSubFileThanSkip bool) ([]string, error) {
+// DownloadSub4Movie 某一个电影字幕下载,下载完毕后,返回下载缓存每个字幕的位置
+func (d SubSupplierHub) DownloadSub4Movie(videoFullPath string, index int) ([]string, error) {
 	// 先清理缓存文件夹
 	err := model.ClearTmpFolder()
 	if err != nil {
 		d.log.Error(err)
 	}
 
-	// TODO 这里可以考虑改为,要么就是视频内封有字幕(得研究下怎么判断) 。要么,就是在视频上线(影片上映时间,电影院时间 or DVD 时间,资源能够下载的时间?)后的多少天内都进行字幕的自动下载,替换原有的字幕
-	// 是否需要跳过有字幕文件的视频
-	if foundExistSubFileThanSkip == true {
-		found, err := d.videoHasSub(videoFullPath)
+	// 资源下载的时间后的多少天内都进行字幕的自动下载,替换原有的字幕
+	// 30 天
+	currentTime := time.Now()
+	dayRange, _ := time.ParseDuration(common.DownloadSubDuring30Days)
+	_, modifyTime, err := model.GetVideoInfoFromFileName(videoFullPath)
+	if err != nil {
+		return nil, err
+	}
+	// 视频下面有不有字幕
+	found, err := d.videoHasSub(videoFullPath)
+	if err != nil {
+		return nil, err
+	}
+	var organizeSubFiles []string
+	// 30 天内,或者没有字幕都要进行下载( TODO 但是如果是中文电影就无需下载,这个需要额外的判断)
+	if modifyTime.Add(dayRange).After(currentTime) == true || found == false {
+		// 需要下载更新
+		subInfos := d.downloadSub4OneVideo(videoFullPath, index)
+		organizeSubFiles, err = d.organizeDlSubFiles(subInfos)
 		if err != nil {
 			return nil, err
 		}
+	} else {
+		if modifyTime.Add(dayRange).After(currentTime) == false {
+			d.log.Infoln("Skip", videoFullPath, "Sub Download, because movie has sub and downloaded more than 30 days")
+			return nil, nil
+		}
 		if found == true {
 			d.log.Infoln("Skip", videoFullPath, "Sub Download, because sub file found")
 			return nil, nil
 		}
+
+		return nil, nil
 	}
-	subInfos := d.downloadSub4OneVideo(videoFullPath, index)
-	organizeSubFiles, err := d.organizeDlSubFiles(subInfos)
+
+	return organizeSubFiles, nil
+}
+
+// DownloadSub4Series 某一个视频的字幕下载,下载完毕后,返回下载缓存每个字幕的位置
+func (d SubSupplierHub) DownloadSub4Series(seriesDirPath string, index int) ([]string, error) {
+	// 先清理缓存文件夹
+	err := model.ClearTmpFolder()
 	if err != nil {
-		return nil, err
+		d.log.Error(err)
 	}
-	return organizeSubFiles, nil
+
+	return nil, nil
 }
 
 // downloadSub4OneVideo 为这个视频下载字幕,所有网站找到的字幕都会汇总输出

+ 2 - 2
sub_supplier/zimuku/zimuku.go

@@ -104,11 +104,11 @@ func (s Supplier) GetSubListFromFile4Series(seriesPath string) ([]common.Supplie
 	var subInfoNeedDownload = make([]SubInfo, 0)
 	currentTime := time.Now()
 	// 30 天
-	dayRange, _ := time.ParseDuration("720h")
+	dayRange, _ := time.ParseDuration(common.DownloadSubDuring30Days)
 	for _, epsInfo := range seriesInfo.EpList {
 		// 如果没有字幕,则加入下载列表
 		// 这一集下载后的30天内,都进行字幕的下载
-		if len(epsInfo.SubList) < 1 || epsInfo.ModifyTime.Add(dayRange).Before(currentTime) == true {
+		if len(epsInfo.SubList) < 1 || epsInfo.ModifyTime.Add(dayRange).After(currentTime) == true {
 			// 添加
 			info, _, err := model.GetVideoInfoFromFileName(epsInfo.Title)
 			if err != nil {