diff --git a/internal/cache/alist.go b/internal/cache/alist.go index 9b12223..e0ac8ad 100644 --- a/internal/cache/alist.go +++ b/internal/cache/alist.go @@ -145,8 +145,9 @@ func NewAlistMovieCacheInitFunc(movie *model.Movie) func(ctx context.Context, ar var ( serverID string err error + truePath string ) - serverID, movie.Base.VendorInfo.Alist.Path, err = model.GetAlistServerIdFromPath(movie.Base.VendorInfo.Alist.Path) + serverID, truePath, err = model.GetAlistServerIdFromPath(movie.Base.VendorInfo.Alist.Path) if err != nil { return nil, err } @@ -161,7 +162,7 @@ func NewAlistMovieCacheInitFunc(movie *model.Movie) func(ctx context.Context, ar fg, err := cli.FsGet(ctx, &alist.FsGetReq{ Host: aucd.Host, Token: aucd.Token, - Path: movie.Base.VendorInfo.Alist.Path, + Path: truePath, Password: movie.Base.VendorInfo.Alist.Password, }) if err != nil { @@ -179,7 +180,7 @@ func NewAlistMovieCacheInitFunc(movie *model.Movie) func(ctx context.Context, ar fo, err := cli.FsOther(ctx, &alist.FsOtherReq{ Host: aucd.Host, Token: aucd.Token, - Path: movie.Base.VendorInfo.Alist.Path, + Path: truePath, Password: movie.Base.VendorInfo.Alist.Password, Method: "video_preview", }) diff --git a/internal/cache/emby.go b/internal/cache/emby.go index 98eb3e5..47d9fba 100644 --- a/internal/cache/emby.go +++ b/internal/cache/emby.go @@ -82,8 +82,9 @@ func NewEmbyMovieCacheInitFunc(movie *model.Movie) func(ctx context.Context, arg var ( serverID string err error + truePath string ) - serverID, movie.Base.VendorInfo.Emby.Path, err = model.GetEmbyServerIdFromPath(movie.Base.VendorInfo.Emby.Path) + serverID, truePath, err = model.GetEmbyServerIdFromPath(movie.Base.VendorInfo.Emby.Path) if err != nil { return nil, err } @@ -103,7 +104,7 @@ func NewEmbyMovieCacheInitFunc(movie *model.Movie) func(ctx context.Context, arg data, err := cli.GetItem(ctx, &emby.GetItemReq{ Host: aucd.Host, Token: aucd.ApiKey, - ItemId: movie.Base.VendorInfo.Emby.Path, + ItemId: truePath, }) if err != nil { return nil, err diff --git a/internal/op/movie.go b/internal/op/movie.go index 6f15c72..eeb2db9 100644 --- a/internal/op/movie.go +++ b/internal/op/movie.go @@ -29,6 +29,17 @@ type Movie struct { embyCache atomic.Pointer[cache.EmbyMovieCache] } +func (m *Movie) ClearCache() { + m.alistCache.Store(nil) + + bmc := m.bilibiliCache.Swap(nil) + if bmc != nil { + bmc.NoSharedMovie.Clear() + } + + m.embyCache.Store(nil) +} + func (m *Movie) AlistCache() *cache.AlistMovieCache { c := m.alistCache.Load() if c == nil { @@ -121,7 +132,10 @@ func (m *Movie) initChannel() error { }() case "http", "https": c := m.compareAndSwapInitChannel() - c.InitHlsPlayer(hls.WithGenTsNameFunc(genTsName)) + err := c.InitHlsPlayer(hls.WithGenTsNameFunc(genTsName)) + if err != nil { + return err + } go func() { for { if c.Closed() { @@ -233,8 +247,6 @@ func (movie *Movie) validateVendorMovie() error { default: return fmt.Errorf("vendor not implement validate") } - - return nil } func (m *Movie) Terminate() error { @@ -245,14 +257,11 @@ func (m *Movie) Terminate() error { return err } } - bmc := m.bilibiliCache.Swap(nil) - if bmc != nil { - bmc.NoSharedMovie.Clear() - } return nil } func (m *Movie) Update(movie *model.BaseMovie) error { m.Movie.Base = *movie + m.ClearCache() return m.Terminate() }