/
path_things.go
78 lines (66 loc) · 2.14 KB
/
path_things.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package base
import (
"net/http"
"github.com/ChineseSubFinder/ChineseSubFinder/pkg"
backend2 "github.com/ChineseSubFinder/ChineseSubFinder/pkg/types/backend"
"github.com/ChineseSubFinder/ChineseSubFinder/pkg/logic/emby_helper"
"github.com/ChineseSubFinder/ChineseSubFinder/pkg/settings"
"github.com/gin-gonic/gin"
)
func (cb *ControllerBase) CheckPathHandler(c *gin.Context) {
var err error
defer func() {
// 统一的异常处理
cb.ErrorProcess(c, "CheckPathHandler", err)
}()
reqCheckPath := backend2.ReqCheckPath{}
err = c.ShouldBindJSON(&reqCheckPath)
if err != nil {
return
}
if pkg.IsDir(reqCheckPath.Path) == true {
c.JSON(http.StatusOK, backend2.ReplyCheckPath{
Valid: true,
})
} else {
c.JSON(http.StatusOK, backend2.ReplyCheckPath{
Valid: false,
})
}
}
func (cb *ControllerBase) CheckEmbyPathHandler(c *gin.Context) {
var err error
defer func() {
// 统一的异常处理
cb.ErrorProcess(c, "CheckEmbyPathHandler", err)
}()
reqCheckPath := backend2.ReqCheckEmbyPath{}
err = c.ShouldBindJSON(&reqCheckPath)
if err != nil {
return
}
// 需要使用 Emby 做列表转换,从发送过来的 emby_media_path 进行推算,拼接 cfs_media_path 地址,然后读取这个文件夹或者视频是否存在
// 暂定还是以最近的 Emby 视频列表,再去匹配
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(cb.fileDownloader.MediaInfoDealers)
outList, err := emHelper.CheckPath(&emSettings, reqCheckPath.PathType, emSettings.MaxRequestVideoNumber)
if err != nil {
return
}
c.JSON(http.StatusOK, backend2.ReplyCheckEmbyPath{
MediaList: outList,
})
}