Jelajahi Sumber

完成 emby api check path 的 web api 接口

Signed-off-by: 716 <[email protected]>
716 3 tahun lalu
induk
melakukan
31725efce5

File diff ditekan karena terlalu besar
+ 1 - 13424
frontend/package-lock.json


+ 28 - 9
internal/backend/controllers/base/path_things.go

@@ -1,7 +1,9 @@
 package base
 
 import (
+	"github.com/allanpk716/ChineseSubFinder/internal/logic/emby_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/settings"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/backend"
 	"github.com/gin-gonic/gin"
 	"net/http"
@@ -45,13 +47,30 @@ func (cb ControllerBase) CheckEmbyPathHandler(c *gin.Context) {
 	}
 	// 需要使用 Emby 做列表转换,从发送过来的 emby_media_path 进行推算,拼接 cfs_media_path 地址,然后读取这个文件夹或者视频是否存在
 	// 暂定还是以最近的 Emby 视频列表,再去匹配
-	//if my_util.IsDir(reqCheckPath.Path) == true {
-	//	c.JSON(http.StatusOK, backend.ReplyCheckEmbyPath{
-	//		Valid: true,
-	//	})
-	//} else {
-	//	c.JSON(http.StatusOK, backend.ReplyCheckEmbyPath{
-	//		Valid: false,
-	//	})
-	//}
+	emSettings := settings.EmbySettings{
+		Enable:                true,
+		AddressUrl:            reqCheckPath.AddressUrl,
+		APIKey:                reqCheckPath.APIKey,
+		MaxRequestVideoNumber: 2000,
+		SkipWatched:           false,
+		MoviePathsMapping:     make(map[string]string, 0),
+		SeriesPathsMapping:    make(map[string]string, 0),
+	}
+
+	if reqCheckPath.PathType == "movie" {
+		emSettings.MoviePathsMapping[reqCheckPath.CFSMediaPath] = reqCheckPath.EmbyMediaPath
+	} else {
+		emSettings.SeriesPathsMapping[reqCheckPath.CFSMediaPath] = reqCheckPath.EmbyMediaPath
+	}
+
+	emHelper := emby_helper.NewEmbyHelper(emSettings)
+
+	outList, err := emHelper.CheckPath(reqCheckPath.PathType)
+	if err != nil {
+		return
+	}
+
+	c.JSON(http.StatusOK, backend.ReplyCheckEmbyPath{
+		MediaList: outList,
+	})
 }

+ 59 - 1
internal/logic/emby_helper/embyhelper.go

@@ -5,6 +5,7 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/common"
 	embyHelper "github.com/allanpk716/ChineseSubFinder/internal/pkg/emby_api"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/log_helper"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/settings"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_parser_hub"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/emby"
@@ -504,14 +505,71 @@ func (em *EmbyHelper) GetInternalEngSubAndExChineseEnglishSub(videoId string) (b
 	return true, inSubList, exSubList, nil
 }
 
-func (em *EmbyHelper) CheckPath(CFSMediaPath, EmbyMediaPath string) ([]string, error) {
+func (em *EmbyHelper) CheckPath(pathType string) ([]string, error) {
 
 	// 获取最近的影片列表
 	items, err := em.embyApi.GetRecentlyItems()
 	if err != nil {
 		return nil, err
 	}
+	// 获取电影和连续剧的文件夹名称
+	var EpisodeIdList = make([]string, 0)
+	var MovieIdList = make([]string, 0)
+	// 分类
+	for index, item := range items.Items {
+		if item.Type == videoTypeEpisode {
+			// 这个里面可能混有其他的内容,比如目标是连续剧,但是 emby_helper 其实会把其他的混合内容也标记进去
+			EpisodeIdList = append(EpisodeIdList, item.Id)
+			log_helper.GetLogger().Debugln("Episode:", index, item.SeriesName, item.ParentIndexNumber, item.IndexNumber)
+		} else if item.Type == videoTypeMovie {
+			// 这个里面可能混有其他的内容,比如目标是连续剧,但是 emby_helper 其实会把其他的混合内容也标记进去
+			MovieIdList = append(MovieIdList, item.Id)
+			log_helper.GetLogger().Debugln("Movie:", index, item.Name)
+		} else {
+			log_helper.GetLogger().Debugln("GetRecentlyItems - Is not a goal video type:", index, item.Name, item.Type)
+		}
+	}
+
+	outCount := 0
+	outList := make([]string, 0)
+
+	if pathType == "movie" {
+		// 过滤出有效的电影、连续剧的资源出来
+		filterMovieList, err := em.filterEmbyVideoList(MovieIdList, true)
+		if err != nil {
+			return nil, err
+		}
+
+		for _, info := range filterMovieList {
+
+			if my_util.IsFile(info.PhysicalVideoFileFullPath) == true {
+				outList = append(outList, info.PhysicalVideoFileFullPath)
+				outCount++
+				if outCount > 5 {
+					break
+				}
+			}
+		}
+
+	} else {
+		filterSeriesList, err := em.filterEmbyVideoList(EpisodeIdList, false)
+		if err != nil {
+			return nil, err
+		}
+
+		for _, info := range filterSeriesList {
+
+			if my_util.IsFile(info.PhysicalVideoFileFullPath) == true {
+				outList = append(outList, info.PhysicalVideoFileFullPath)
+				outCount++
+				if outCount > 5 {
+					break
+				}
+			}
+		}
+	}
 
+	return outList, nil
 }
 
 type InputData struct {

+ 5 - 4
internal/types/backend/req_check_emby_path.go

@@ -1,8 +1,9 @@
 package backend
 
 type ReqCheckEmbyPath struct {
-	AddressUrl    string `json:"address_url"  binding:"required"`
-	APIKey        string `json:"api_key"  binding:"required"`
-	CFSMediaPath  string `json:"cfs_media_path"  binding:"required"`
-	EmbyMediaPath string `json:"emby_media_path"  binding:"required"`
+	AddressUrl    string `json:"address_url" binding:"required"`
+	APIKey        string `json:"api_key" binding:"required"`
+	PathType      string `json:"path_type" binding:"required"`
+	CFSMediaPath  string `json:"cfs_media_path" binding:"required"`
+	EmbyMediaPath string `json:"emby_media_path" binding:"required"`
 }

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini