Feat: alist related

pull/150/head
zijiren233 2 years ago
parent 4abf1694f7
commit 45d036a36d

@ -33,7 +33,7 @@ require (
github.com/sirupsen/logrus v1.9.3
github.com/soheilhy/cmux v0.1.5
github.com/spf13/cobra v1.8.0
github.com/synctv-org/vendors v0.3.3-0.20240508085634-2526fdda244b
github.com/synctv-org/vendors v0.3.3-0.20240508122446-dd74d8cbee7d
github.com/ulule/limiter/v3 v3.11.2
github.com/zencoder/go-dash/v3 v3.0.3
github.com/zijiren233/gencontainer v0.0.0-20240507135401-7a9c8355bb2c

@ -363,8 +363,8 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/synctv-org/vendors v0.3.3-0.20240508085634-2526fdda244b h1:1loucE5sKLtPWBE7orAm4LvIC6QpchMKYO3AOlIu9vM=
github.com/synctv-org/vendors v0.3.3-0.20240508085634-2526fdda244b/go.mod h1:S3Xhi+MOjg0OOyUxwfCBLG5EuNYQNqjq/J07CptZ0Rw=
github.com/synctv-org/vendors v0.3.3-0.20240508122446-dd74d8cbee7d h1:8cojxYZmrb+Xp8s5nTJ5cEVNfXm7LoRYfDhc+eIsW9U=
github.com/synctv-org/vendors v0.3.3-0.20240508122446-dd74d8cbee7d/go.mod h1:S3Xhi+MOjg0OOyUxwfCBLG5EuNYQNqjq/J07CptZ0Rw=
github.com/tetratelabs/wazero v1.7.1 h1:QtSfd6KLc41DIMpDYlJdoMc6k7QTN246DM2+n2Y/Dx8=
github.com/tetratelabs/wazero v1.7.1/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=

@ -7,6 +7,7 @@ import (
"fmt"
"io"
"net/http"
"strings"
"time"
"github.com/synctv-org/synctv/internal/db"
@ -90,9 +91,10 @@ const (
)
type AlistMovieCacheData struct {
URL string
Provider string
Ali *AlistAliCache
URL string
Subtitles map[string]string
Provider string
Ali *AlistAliCache
}
type AlistAliCache struct {
@ -200,6 +202,27 @@ func NewAlistMovieCacheInitFunc(movie *model.Movie) func(ctx context.Context, ar
URL: fg.RawUrl,
Provider: fg.Provider,
}
prefix := strings.TrimSuffix(truePath, fg.Name)
for _, related := range fg.Related {
if related.Type == 4 {
resp, err := cli.FsGet(ctx, &alist.FsGetReq{
Host: aucd.Host,
Token: aucd.Token,
Path: prefix + related.Name,
Password: movie.Base.VendorInfo.Alist.Password,
UserAgent: args[0].UserAgent,
})
if err != nil {
return nil, err
}
if cache.Subtitles == nil {
cache.Subtitles = make(map[string]string)
}
cache.Subtitles[resp.Name] = resp.RawUrl
}
}
if fg.Provider == AlistProviderAli {
fo, err := cli.FsOther(ctx, &alist.FsOtherReq{
Host: aucd.Host,

@ -1172,6 +1172,16 @@ func genVendorMovie(ctx context.Context, user *op.User, opMovie *op.Movie, userA
return nil, err
}
for name, url := range data.Subtitles {
if movie.Base.Subtitles == nil {
movie.Base.Subtitles = make(map[string]*dbModel.Subtitle, len(data.Subtitles))
}
movie.Base.Subtitles[name] = &dbModel.Subtitle{
URL: url,
Type: utils.GetFileExtension(name),
}
}
switch data.Provider {
case cache.AlistProviderAli:
rawPath, err := url.JoinPath("/api/movie/proxy", movie.RoomID, movie.ID)

@ -338,6 +338,10 @@ func MapToHttpCookie(m map[string]string) []*http.Cookie {
return c
}
func GetFileExtension(f string) string {
return strings.TrimLeft(filepath.Ext(f), ".")
}
func GetUrlExtension(u string) string {
if u == "" {
return ""
@ -346,7 +350,7 @@ func GetUrlExtension(u string) string {
if err != nil {
return ""
}
return strings.TrimLeft(filepath.Ext(p.Path), ".")
return GetFileExtension(p.Path)
}
var (

Loading…
Cancel
Save