Browse Source

完成基础的一级目录刷新和获取逻辑,以及 poster 的 url 获取逻辑

Signed-off-by: allan716 <[email protected]>
allan716 3 years ago
parent
commit
5068efc82e

+ 4 - 0
internal/backend/base_router.go

@@ -84,7 +84,11 @@ func InitRouter(
 		GroupV1.GET("/video/list/refresh-status", cbV1.RefreshVideoListStatusHandler)
 		GroupV1.GET("/video/list", cbV1.VideoListHandler)
 		GroupV1.POST("/video/list/add", cbV1.VideoListAddHandler)
+
 		GroupV1.POST("/video/list/refresh_main_list", cbV1.RefreshMainList)
+		GroupV1.GET("/video/list/video_main_list", cbV1.VideoMainList)
+		GroupV1.POST("/video/list/movie_poster", cbV1.MoviePoster)
+		GroupV1.POST("/video/list/series_poster", cbV1.SeriesPoster)
 	}
 
 	GroupAPIV1 := router.Group("/api/v1")

+ 89 - 0
internal/backend/controllers/v1/video_list.go

@@ -6,6 +6,8 @@ import (
 	"net/http"
 	"time"
 
+	"github.com/allanpk716/ChineseSubFinder/pkg/path_helper"
+
 	backend2 "github.com/allanpk716/ChineseSubFinder/pkg/types/backend"
 	"github.com/allanpk716/ChineseSubFinder/pkg/types/common"
 	TTaskqueue "github.com/allanpk716/ChineseSubFinder/pkg/types/task_queue"
@@ -190,6 +192,9 @@ func (cb *ControllerBase) VideoListHandler(c *gin.Context) {
 	})
 }
 
+//--------------------------------------------
+
+// RefreshMainList 重构后的视频列表,比如 x:\电影\壮志凌云\壮志凌云.mp4 或者是连续剧的 x:\连续剧\绝命毒师 根目录
 func (cb *ControllerBase) RefreshMainList(c *gin.Context) {
 
 	var err error
@@ -248,3 +253,87 @@ func (cb *ControllerBase) RefreshMainList(c *gin.Context) {
 		Status: "running"})
 	return
 }
+
+// VideoMainList 获取电影和连续剧的基础结构
+func (cb *ControllerBase) VideoMainList(c *gin.Context) {
+
+	var err error
+	defer func() {
+		// 统一的异常处理
+		cb.ErrorProcess(c, "MoviePoster", err)
+	}()
+	outMovieInfos, outSeasonInfo, err := cb.cronHelper.Downloader.GetMovieInfoAndSeasonInfoV2()
+	if err != nil {
+		cb.log.Errorln("GetMovieInfoAndSeasonInfoV2", err)
+		return
+	}
+
+	c.JSON(http.StatusOK, backend2.ReplyMainList{
+		MovieInfos:  outMovieInfos,
+		SeasonInfos: outSeasonInfo,
+	})
+}
+
+// MoviePoster 获取电影海报
+func (cb *ControllerBase) MoviePoster(c *gin.Context) {
+
+	var err error
+	defer func() {
+		// 统一的异常处理
+		cb.ErrorProcess(c, "MoviePoster", err)
+	}()
+
+	movieInfo := backend2.MovieInfoV2{}
+	err = c.ShouldBindJSON(&movieInfo)
+	if err != nil {
+		return
+	}
+
+	// 然后还需要将这个全路径信息转换为 静态文件服务器对应的路径返回给前端
+	desUrl, found := cb.GetPathUrlMap()[movieInfo.MainRootDirFPath]
+	if found == false {
+		// 没有找到对应的 URL
+		errMessage := fmt.Sprintf("MoviePoster.GetPathUrlMap can not find url for path %s", movieInfo.MainRootDirFPath)
+		cb.log.Warningln(errMessage)
+		err = errors.New(errMessage)
+		return
+	}
+	posterFPath := cb.videoListHelper.GetMoviePoster(movieInfo.VideoFPath)
+	posterUrl := path_helper.ChangePhysicalPathToSharePath(posterFPath, movieInfo.MainRootDirFPath, desUrl)
+
+	c.JSON(http.StatusOK, backend2.PosterInfo{
+		Url: posterUrl,
+	})
+}
+
+// SeriesPoster 从一个连续剧的根目录中,获取连续剧的海报
+func (cb *ControllerBase) SeriesPoster(c *gin.Context) {
+
+	var err error
+	defer func() {
+		// 统一的异常处理
+		cb.ErrorProcess(c, "SeriesPoster", err)
+	}()
+
+	seriesInfo := backend2.SeasonInfoV2{}
+	err = c.ShouldBindJSON(&seriesInfo)
+	if err != nil {
+		return
+	}
+
+	// 然后还需要将这个全路径信息转换为 静态文件服务器对应的路径返回给前端
+	desUrl, found := cb.GetPathUrlMap()[seriesInfo.MainRootDirFPath]
+	if found == false {
+		// 没有找到对应的 URL
+		errMessage := fmt.Sprintf("SeriesPoster.GetPathUrlMap can not find url for path %s", seriesInfo.MainRootDirFPath)
+		cb.log.Warningln(errMessage)
+		err = errors.New(errMessage)
+		return
+	}
+	posterFPath := cb.videoListHelper.GetSeriesPoster(seriesInfo.RootDirPath)
+	posterUrl := path_helper.ChangePhysicalPathToSharePath(posterFPath, seriesInfo.MainRootDirFPath, desUrl)
+
+	c.JSON(http.StatusOK, backend2.PosterInfo{
+		Url: posterUrl,
+	})
+}

+ 16 - 10
pkg/downloader/cache_info.go

@@ -272,15 +272,18 @@ func (d *Downloader) SetMovieAndSeasonInfoV2(mainList *vsh.NormalScanVideoResult
 
 	if mainList != nil && mainList.MoviesDirMap != nil && mainList.MoviesDirMap.Size() > 0 {
 
-		for _, movieDirs := range mainList.MoviesDirMap.Values() {
+		mainList.MoviesDirMap.Any(func(movieDirRootPath interface{}, moviesFPath interface{}) bool {
 
-			for _, movieDir := range movieDirs.([]string) {
+			oneMovieDirRootPath := movieDirRootPath.(string)
+			for _, movieFPath := range moviesFPath.([]string) {
 				movieInfos = append(movieInfos, backend2.MovieInfoV2{
-					Name:       filepath.Base(movieDir),
-					VideoFPath: movieDir,
+					Name:             filepath.Base(movieFPath),
+					MainRootDirFPath: oneMovieDirRootPath,
+					VideoFPath:       movieFPath,
 				})
 			}
-		}
+			return false
+		})
 
 		err = strcut_json.ToFile(movieInfosFileName, movieInfos)
 		if err != nil {
@@ -290,15 +293,18 @@ func (d *Downloader) SetMovieAndSeasonInfoV2(mainList *vsh.NormalScanVideoResult
 
 	if mainList != nil && mainList.SeriesDirMap != nil && mainList.SeriesDirMap.Size() > 0 {
 
-		for _, seriesDirs := range mainList.SeriesDirMap.Values() {
+		mainList.SeriesDirMap.Any(func(seriesRootPathName interface{}, seriesNames interface{}) bool {
 
-			for _, seriesDir := range seriesDirs.([]string) {
+			oneSeriesRootPathName := seriesRootPathName.(string)
+			for _, oneSeriesRootDir := range seriesNames.([]string) {
 				seasonInfos = append(seasonInfos, backend2.SeasonInfoV2{
-					Name:        filepath.Base(seriesDir),
-					RootDirPath: seriesDir,
+					Name:             filepath.Base(oneSeriesRootDir),
+					MainRootDirFPath: oneSeriesRootPathName,
+					RootDirPath:      oneSeriesRootDir,
 				})
 			}
-		}
+			return false
+		})
 
 		err = strcut_json.ToFile(seasonInfosFileName, seasonInfos)
 		if err != nil {

+ 3 - 2
pkg/types/backend/reply_movie_list.go

@@ -10,6 +10,7 @@ type MovieInfo struct {
 }
 
 type MovieInfoV2 struct {
-	Name       string `json:"name"`
-	VideoFPath string `json:"video_f_path"` // x:\电影\壮志凌云\壮志凌云.mp4
+	Name             string `json:"name"`
+	MainRootDirFPath string `json:"main_root_dir_f_path"` // x:\电影
+	VideoFPath       string `json:"video_f_path"`         // x:\电影\壮志凌云\壮志凌云.mp4
 }

+ 5 - 0
pkg/types/backend/reply_poster.go

@@ -0,0 +1,5 @@
+package backend
+
+type PosterInfo struct {
+	Url string `json:"url"` // 静态文件服务器中的图片地址
+}

+ 3 - 2
pkg/types/backend/reply_series_list.go

@@ -18,6 +18,7 @@ type OneVideoInfo struct {
 }
 
 type SeasonInfoV2 struct {
-	Name        string `json:"name"`
-	RootDirPath string `json:"root_dir_path"` // x:\连续剧\绝命毒师
+	Name             string `json:"name"`
+	MainRootDirFPath string `json:"main_root_dir_f_path"` // x:\连续剧
+	RootDirPath      string `json:"root_dir_path"`        // x:\连续剧\绝命毒师
 }