fix: emby support more source proxy

pull/268/head
zijiren233 2 years ago
parent a09f9be692
commit b82a1544d3

@ -9,6 +9,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/golang-jwt/jwt/v5"
"github.com/synctv-org/synctv/cmd/flags"
"github.com/synctv-org/synctv/internal/conf"
"github.com/synctv-org/synctv/server/model"
"github.com/synctv-org/synctv/utils"
@ -60,6 +61,9 @@ func M3u8(ctx *gin.Context, u string, headers map[string]string, isM3u8File bool
if !isM3u8File {
return URL(ctx, u, headers, opts...)
}
if flags.Global.Dev {
ctx.Header(proxyURLHeader, u)
}
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
if err != nil {

@ -12,6 +12,7 @@ import (
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"github.com/synctv-org/synctv/cmd/flags"
"github.com/synctv-org/synctv/internal/conf"
"github.com/synctv-org/synctv/internal/settings"
"github.com/synctv-org/synctv/server/model"
@ -108,9 +109,15 @@ func NewProxyURLOptions(opts ...Option) *Options {
return o
}
const sliceSize = 1024 * 1024
const (
sliceSize = 1024 * 1024 * 2
proxyURLHeader = "X-Proxy-URL"
)
func URL(ctx *gin.Context, u string, headers map[string]string, opts ...Option) error {
if flags.Global.Dev {
ctx.Header(proxyURLHeader, u)
}
o := NewProxyURLOptions(opts...)
if !settings.AllowProxyToLocal.Get() {
if l, err := utils.ParseURLIsLocalIP(u); err != nil {
@ -136,7 +143,7 @@ func URL(ctx *gin.Context, u string, headers map[string]string, opts ...Option)
rsc := NewHTTPReadSeekCloser(u,
WithContext(c),
WithHeadersMap(headers),
WithPerLength(sliceSize*2),
WithPerLength(sliceSize*3),
)
defer rsc.Close()
if o.CacheKey == "" {

@ -124,6 +124,8 @@ func (c *SliceCacheProxy) Proxy(w http.ResponseWriter, r *http.Request) error {
return nil
}
const cacheStatusHeader = "X-Cache-Status"
func (c *SliceCacheProxy) setResponseHeaders(w http.ResponseWriter, byteRange *ByteRange, cacheItem *CacheItem, cached bool, isRangeRequest bool) {
// Copy headers excluding special ones
for k, v := range cacheItem.Metadata.Headers {
@ -136,9 +138,9 @@ func (c *SliceCacheProxy) setResponseHeaders(w http.ResponseWriter, byteRange *B
}
if cached {
w.Header().Set("Cache-Status", "HIT")
w.Header().Set(cacheStatusHeader, "HIT")
} else {
w.Header().Set("Cache-Status", "MISS")
w.Header().Set(cacheStatusHeader, "MISS")
}
w.Header().Set("Accept-Ranges", "bytes")
w.Header().Set("Content-Length", fmtContentLength(byteRange.Start, byteRange.End, cacheItem.Metadata.ContentTotalLength))

@ -313,8 +313,18 @@ func (s *EmbyVendorService) GenProxyMovieInfo(ctx context.Context, user *op.User
Path: rawPath,
RawQuery: rawQuery.Encode(),
}
movie.MovieBase.URL = u.String()
movie.MovieBase.Type = utils.GetURLExtension(es.URL)
if si == 0 {
movie.MovieBase.URL = u.String()
movie.MovieBase.Type = utils.GetURLExtension(es.URL)
} else {
movie.MovieBase.MoreSources = append(movie.MovieBase.MoreSources,
&dbModel.MoreSource{
Name: es.Name,
URL: u.String(),
},
)
}
if len(es.Subtitles) == 0 {
continue

@ -313,8 +313,18 @@ func (s *EmbyVendorService) GenProxyMovieInfo(ctx context.Context, user *op.User
Path: rawPath,
RawQuery: rawQuery.Encode(),
}
movie.MovieBase.URL = u.String()
movie.MovieBase.Type = utils.GetURLExtension(es.URL)
if si == 0 {
movie.MovieBase.URL = u.String()
movie.MovieBase.Type = utils.GetURLExtension(es.URL)
} else {
movie.MovieBase.MoreSources = append(movie.MovieBase.MoreSources,
&dbModel.MoreSource{
Name: es.Name,
URL: u.String(),
},
)
}
if len(es.Subtitles) == 0 {
continue

Loading…
Cancel
Save