Browse Source

修复 HTTP API 提交连续剧一集下载字幕没有 SeriesRootDirPath 的问题

Signed-off-by: allan716 <[email protected]>
allan716 3 years ago
parent
commit
1515e60dd3
1 changed files with 20 additions and 0 deletions
  1. 20 0
      internal/backend/controllers/v1/api.go

+ 20 - 0
internal/backend/controllers/v1/api.go

@@ -1,8 +1,11 @@
 package v1
 
 import (
+	"errors"
+	"fmt"
 	"github.com/allanpk716/ChineseSubFinder/internal/dao"
 	"github.com/allanpk716/ChineseSubFinder/internal/models"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/decode"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/backend"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/common"
@@ -45,6 +48,23 @@ func (cb *ControllerBase) AddJobHandler(c *gin.Context) {
 		videoType, videoListAdd.PhysicalVideoFileFullPath, videoListAdd.TaskPriorityLevel,
 		videoListAdd.MediaServerInsideVideoID,
 	)
+
+	if videoListAdd.VideoType == 1 {
+		// 连续剧的时候需要额外提交信息
+		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
+		}
+		nowJob.Season = torrentInfo.Season
+		nowJob.Episode = torrentInfo.Episode
+		nowJob.SeriesRootDirPath = seriesInfoDirPath
+	}
+
 	bok, err := cb.cronHelper.DownloadQueue.Add(*nowJob)
 	if err != nil {
 		return