浏览代码

修复 WebUI 触发视频列表扫描功能,emby 部分调试完成

Signed-off-by: allan716 <[email protected]>
allan716 3 年之前
父节点
当前提交
f1df1edb6d

+ 11 - 17
internal/backend/controllers/v1/video_list.go

@@ -3,7 +3,6 @@ package v1
 import (
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/video_scan_and_refresh_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/backend"
-	"github.com/allanpk716/ChineseSubFinder/internal/types/task_queue"
 	"github.com/gin-gonic/gin"
 	"net/http"
 )
@@ -69,7 +68,13 @@ func (cb *ControllerBase) RefreshVideoListHandler(c *gin.Context) {
 		}
 
 		pathUrlMap := cb.StaticFileSystemBackEnd.GetPathUrlMap()
-		cb.MovieInfos, cb.SeasonInfos = cb.videoScanAndRefreshHelper.ScrabbleUpVideoList(scanVideoResult, pathUrlMap)
+
+		cb.MovieInfos = make([]backend.MovieInfo, 0)
+		cb.SeasonInfos = make([]backend.SeasonInfo, 0)
+		MovieInfos, SeasonInfos := cb.videoScanAndRefreshHelper.ScrabbleUpVideoList(scanVideoResult, pathUrlMap)
+
+		cb.MovieInfos = append(cb.MovieInfos, MovieInfos...)
+		cb.SeasonInfos = append(cb.SeasonInfos, SeasonInfos...)
 		// 并且如果是 Emby 那么会在页面上出现一个刷新字幕列表的按钮(这个需要 Emby 中video 的 ID)
 	}()
 
@@ -78,26 +83,15 @@ func (cb *ControllerBase) RefreshVideoListHandler(c *gin.Context) {
 	return
 }
 
-func (cb ControllerBase) VideoListHandler(c *gin.Context) {
+func (cb *ControllerBase) VideoListHandler(c *gin.Context) {
 	var err error
 	defer func() {
 		// 统一的异常处理
 		cb.ErrorProcess(c, "VideoListHandler", err)
 	}()
 
-	bok, allJobs, err := cb.cronHelper.DownloadQueue.GetAllJobs()
-	if err != nil {
-		return
-	}
-
-	if bok == false {
-		c.JSON(http.StatusOK, backend.ReplyAllJobs{
-			AllJobs: make([]task_queue.OneJob, 0),
-		})
-		return
-	}
-
-	c.JSON(http.StatusOK, backend.ReplyAllJobs{
-		AllJobs: allJobs,
+	c.JSON(http.StatusOK, backend.ReplyVideoList{
+		MovieInfos:  cb.MovieInfos,
+		SeasonInfos: cb.SeasonInfos,
 	})
 }

+ 14 - 4
internal/pkg/video_scan_and_refresh_helper/video_scan_and_refresh_helper.go

@@ -239,6 +239,10 @@ func (v *VideoScanAndRefreshHelper) FilterMovieAndSeriesNeedDownload(scanVideoRe
 
 func (v *VideoScanAndRefreshHelper) ScrabbleUpVideoList(scanVideoResult *ScanVideoResult, pathUrlMap map[string]string) ([]backend.MovieInfo, []backend.SeasonInfo) {
 
+	defer func() {
+		scanVideoResult = nil
+	}()
+
 	if scanVideoResult.Normal != nil && v.settings.EmbySettings.Enable == false {
 		return v.scrabbleUpVideoListNormal(scanVideoResult.Normal, pathUrlMap)
 	}
@@ -261,7 +265,8 @@ func (v *VideoScanAndRefreshHelper) scrabbleUpVideoListNormal(normal *NormalScan
 	// 电影
 	movieProcess := func(ctx context.Context, inData interface{}) error {
 
-		scrabbleUpVideoMovieNormalInput := inData.(*ScrabbleUpVideoMovieNormalInput)
+		taskData := inData.(*task_control.TaskData)
+		scrabbleUpVideoMovieNormalInput := taskData.DataEx.(*ScrabbleUpVideoMovieNormalInput)
 		oneMovieDirRootPath := scrabbleUpVideoMovieNormalInput.OneMovieDirRootPath
 		oneMovieFPath := scrabbleUpVideoMovieNormalInput.OneMovieFPath
 
@@ -332,7 +337,8 @@ func (v *VideoScanAndRefreshHelper) scrabbleUpVideoListNormal(normal *NormalScan
 	// seriesDirMap: dir <--> seriesList
 	seriesProcess := func(ctx context.Context, inData interface{}) error {
 
-		scrabbleUpVideoSeriesNormalInput := inData.(*ScrabbleUpVideoSeriesNormalInput)
+		taskData := inData.(*task_control.TaskData)
+		scrabbleUpVideoSeriesNormalInput := taskData.DataEx.(*ScrabbleUpVideoSeriesNormalInput)
 		oneSeriesRootPathName := scrabbleUpVideoSeriesNormalInput.OneSeriesRootPathName
 		oneSeriesRootDir := scrabbleUpVideoSeriesNormalInput.OneSeriesRootDir
 
@@ -436,7 +442,8 @@ func (v *VideoScanAndRefreshHelper) scrabbleUpVideoListEmby(emby *EmbyScanVideoR
 
 	movieProcess := func(ctx context.Context, inData interface{}) error {
 
-		scrabbleUpVideoMovieEmbyInput := inData.(ScrabbleUpVideoMovieEmbyInput)
+		taskData := inData.(*task_control.TaskData)
+		scrabbleUpVideoMovieEmbyInput := taskData.DataEx.(ScrabbleUpVideoMovieEmbyInput)
 		oneMovieMixInfo := scrabbleUpVideoMovieEmbyInput.OneMovieMixInfo
 		// 首先需要找到对应的最长的视频媒体库路径,x://ABC  x://ABC/DEF
 		for _, oneMovieDirPath := range sortMoviePaths {
@@ -511,7 +518,8 @@ func (v *VideoScanAndRefreshHelper) scrabbleUpVideoListEmby(emby *EmbyScanVideoR
 	// Emby 过滤,连续剧
 	seriesProcess := func(ctx context.Context, inData interface{}) error {
 
-		scrabbleUpVideoSeriesEmbyInput := inData.(ScrabbleUpVideoSeriesEmbyInput)
+		taskData := inData.(*task_control.TaskData)
+		scrabbleUpVideoSeriesEmbyInput := taskData.DataEx.(ScrabbleUpVideoSeriesEmbyInput)
 
 		oneSeasonInfo := scrabbleUpVideoSeriesEmbyInput.OneSeasonInfo
 		oneEpsMixInfo := scrabbleUpVideoSeriesEmbyInput.OneEpsMixInfo
@@ -632,6 +640,8 @@ func (v *VideoScanAndRefreshHelper) scrabbleUpVideoListEmby(emby *EmbyScanVideoR
 			}
 		}
 		v.taskControl.Hold()
+
+		seasonInfos = append(seasonInfos, oneSeasonInfo)
 	}
 
 	return movieInfos, seasonInfos