Ver código fonte

修复视频列表提交连续剧一集下载字幕没有 SeriesRootDirPath 的问题

Signed-off-by: allan716 <[email protected]>
allan716 3 anos atrás
pai
commit
ce6d12daf6

+ 22 - 2
internal/backend/controllers/v1/video_list.go

@@ -1,6 +1,9 @@
 package v1
 
 import (
+	"errors"
+	"fmt"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/decode"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/video_scan_and_refresh_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/backend"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/common"
@@ -100,10 +103,27 @@ func (cb *ControllerBase) VideoListAddHandler(c *gin.Context) {
 		videoType = common.Series
 	}
 
-	bok, err := cb.cronHelper.DownloadQueue.Add(*TTaskqueue.NewOneJob(
+	oneJob := TTaskqueue.NewOneJob(
 		videoType, videoListAdd.PhysicalVideoFileFullPath, videoListAdd.TaskPriorityLevel,
 		videoListAdd.MediaServerInsideVideoID,
-	))
+	)
+
+	torrentInfo, err := decode.GetVideoInfoFromFileName(videoListAdd.PhysicalVideoFileFullPath)
+	if err != nil {
+		return
+	}
+
+	seriesInfoDirPath := decode.GetSeriesDirRootFPath(videoListAdd.PhysicalVideoFileFullPath)
+	if seriesInfoDirPath == "" {
+		err = errors.New(fmt.Sprintf("decode.GetSeriesDirRootFPath == Empty, %s", videoListAdd.PhysicalVideoFileFullPath))
+		return
+	}
+
+	oneJob.Season = torrentInfo.Season
+	oneJob.Episode = torrentInfo.Episode
+	oneJob.SeriesRootDirPath = seriesInfoDirPath
+
+	bok, err := cb.cronHelper.DownloadQueue.Add(*oneJob)
 	if err != nil {
 		return
 	}

+ 2 - 4
internal/logic/cron_helper/cron_helper.go

@@ -60,11 +60,9 @@ func NewCronHelper(fileDownloader *file_downloader.FileDownloader) *CronHelper {
 	ch.Downloader = downloader.NewDownloader(
 		sub_formatter.GetSubFormatter(ch.log, ch.Settings.AdvancedSettings.SubNameFormatter),
 		ch.FileDownloader, ch.DownloadQueue)
-	// 强制进行一次字幕源有效性检查
 
-	if ch.Settings.SpeedDevMode == false {
-		ch.Downloader.SupplierCheck()
-	}
+	// 强制进行一次字幕源有效性检查
+	ch.Downloader.SupplierCheck()
 
 	return &ch
 }

+ 21 - 13
internal/logic/pre_download_process/pre_download_proces.go

@@ -91,19 +91,27 @@ func (p *PreDownloadProcess) Init() *PreDownloadProcess {
 	}
 	// ------------------------------------------------------------------------
 	// 构建每个字幕站点下载者的实例
-	p.SubSupplierHub = subSupplier.NewSubSupplierHub(
-		//zimuku.NewSupplier(p.fileDownloader),
-		xunlei.NewSupplier(p.fileDownloader),
-		shooter.NewSupplier(p.fileDownloader),
-	)
-	if p.settings.SubtitleSources.AssrtSettings.Enabled == true &&
-		p.settings.SubtitleSources.AssrtSettings.Token != "" {
-		// 如果开启了 ASSRt 字幕源,则需要新增
-		p.SubSupplierHub.AddSubSupplier(assrt.NewSupplier(p.fileDownloader))
-	}
-	if common2.SubhdCode != "" {
-		// 如果找到 code 了,那么就可以继续用这个实例
-		p.SubSupplierHub.AddSubSupplier(subhd.NewSupplier(p.fileDownloader))
+	if p.settings.SpeedDevMode == true {
+
+		p.SubSupplierHub = subSupplier.NewSubSupplierHub(
+			assrt.NewSupplier(p.fileDownloader),
+		)
+	} else {
+
+		p.SubSupplierHub = subSupplier.NewSubSupplierHub(
+			//zimuku.NewSupplier(p.fileDownloader),
+			xunlei.NewSupplier(p.fileDownloader),
+			shooter.NewSupplier(p.fileDownloader),
+		)
+		if p.settings.SubtitleSources.AssrtSettings.Enabled == true &&
+			p.settings.SubtitleSources.AssrtSettings.Token != "" {
+			// 如果开启了 ASSRt 字幕源,则需要新增
+			p.SubSupplierHub.AddSubSupplier(assrt.NewSupplier(p.fileDownloader))
+		}
+		if common2.SubhdCode != "" {
+			// 如果找到 code 了,那么就可以继续用这个实例
+			p.SubSupplierHub.AddSubSupplier(subhd.NewSupplier(p.fileDownloader))
+		}
 	}
 	// ------------------------------------------------------------------------
 	// 清理自定义的 rod 缓存目录

+ 6 - 2
internal/logic/sub_supplier/assrt/assrt.go

@@ -170,6 +170,11 @@ func (s *Supplier) getSubListFromFile(videoFPath string, isMovie bool) ([]suppli
 
 	videoFileName := filepath.Base(videoFPath)
 
+	if searchSubResult.Sub.Subs == nil || len(searchSubResult.Sub.Subs) == 0 {
+		s.log.Infoln(s.GetSupplierName(), videoFileName, "No subtitle found")
+		return outSubInfoList, nil
+	}
+
 	for index, subInfo := range searchSubResult.Sub.Subs {
 
 		// 获取具体的下载地址
@@ -243,9 +248,8 @@ func (s *Supplier) getSubByKeyWord(keyword string) (SearchSubResult, error) {
 
 	var searchSubResult SearchSubResult
 
+	s.log.Infoln("Search KeyWord:", keyword)
 	tt := url.QueryEscape(keyword)
-	println(tt)
-
 	httpClient, err := my_util.NewHttpClient(s.settings.AdvancedSettings.ProxySettings)
 	if err != nil {
 		return searchSubResult, err

+ 2 - 1
internal/logic/sub_supplier/assrt/assrt_test.go

@@ -21,7 +21,8 @@ func TestSupplier_getSubListFromFile(t *testing.T) {
 	//videoFPath := "X:\\电影\\失控玩家 (2021)\\失控玩家 (2021).mp4"
 	//isMovie := true
 	defInstance()
-	videoFPath := "X:\\连续剧\\风骚律师 (2015)\\Season 6\\Better Call Saul - S06E05 - Black and Blue WEBDL-1080p.mkv"
+	videoFPath := "X:\\连续剧\\杀死伊芙 (2018)\\Season 4\\Killing Eve - S04E08 - Hello, Losers WEBDL-1080p.mkv"
+	//videoFPath := "X:\\连续剧\\风骚律师 (2015)\\Season 6\\Better Call Saul - S06E05 - Black and Blue WEBDL-1080p.mkv"
 	isMovie := false
 
 	got, err := assrtInstance.getSubListFromFile(videoFPath, isMovie)

+ 12 - 0
internal/pkg/decode/decode.go

@@ -279,6 +279,18 @@ func GetVideoInfoFromFileName(fileName string) (*PTN.TorrentInfo, error) {
 	return parse, nil
 }
 
+// GetSeriesDirRootFPath 从一集的绝对路径推断这个连续剧的根目录绝对路径
+func GetSeriesDirRootFPath(oneEpFPath string) string {
+
+	oneSeasonDirFPath := filepath.Dir(oneEpFPath)
+	oneSeriesDirFPath := filepath.Dir(oneSeasonDirFPath)
+	if IsFile(filepath.Join(oneSeriesDirFPath, MetadateTVNfo)) == true {
+		return oneSeriesDirFPath
+	} else {
+		return ""
+	}
+}
+
 //GetVideoInfoFromFileFullPath 从全文件路径推断文件信息
 func GetVideoInfoFromFileFullPath(videoFileFullPath string) (*PTN.TorrentInfo, time.Time, error) {
 

+ 3 - 3
internal/pkg/downloader/downloader.go

@@ -11,7 +11,7 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/pre_download_process"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/series_helper"
 	subSupplier "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier"
-	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/shooter"
+	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/assrt"
 	"github.com/allanpk716/ChineseSubFinder/internal/logic/sub_timeline_fixer"
 	"github.com/allanpk716/ChineseSubFinder/internal/models"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
@@ -134,7 +134,7 @@ func (d *Downloader) SupplierCheck() {
 
 	if d.settings.SpeedDevMode == true {
 		// 这里是调试使用的,指定了只用一个字幕源
-		subSupplierHub := subSupplier.NewSubSupplierHub(shooter.NewSupplier(d.fileDownloader))
+		subSupplierHub := subSupplier.NewSubSupplierHub(assrt.NewSupplier(d.fileDownloader))
 		d.subSupplierHub = subSupplierHub
 	} else {
 
@@ -367,7 +367,7 @@ func (d *Downloader) movieDlFunc(ctx context.Context, job taskQueue2.OneJob, dow
 func (d *Downloader) seriesDlFunc(ctx context.Context, job taskQueue2.OneJob, downloadIndex int64) error {
 
 	nowSubSupplierHub := d.subSupplierHub
-	if nowSubSupplierHub.Suppliers == nil || len(nowSubSupplierHub.Suppliers) < 1 {
+	if nowSubSupplierHub == nil || nowSubSupplierHub.Suppliers == nil || len(nowSubSupplierHub.Suppliers) < 1 {
 		d.log.Infoln("Wait SupplierCheck Update *subSupplierHub, movieDlFunc Skip this time")
 		return nil
 	}