Feat: emby more source

pull/156/head
zijiren233 10 months ago
parent bf88c7de21
commit d6b4ab1e2e

@ -55,12 +55,10 @@ func EmbyAuthorizationCacheWithUserIDInitFunc(userID, serverID string) (*EmbyUse
}
type EmbySource struct {
URLs []struct {
URL string
IsTranscode bool
Name string
}
Subtitles []struct {
URL string
IsTranscode bool
Name string
Subtitles []struct {
URL string
Type string
Name string
@ -160,24 +158,13 @@ func NewEmbyMovieCacheInitFunc(movie *model.Movie) func(ctx context.Context, arg
}
for i, v := range data.MediaSourceInfo {
if movie.Base.VendorInfo.Emby.Transcode && v.TranscodingUrl != "" {
resp.Sources[i].URLs = append(resp.Sources[i].URLs, struct {
URL string
IsTranscode bool
Name string
}{
URL: fmt.Sprintf("%s/emby%s", aucd.Host, v.TranscodingUrl),
Name: v.Name,
IsTranscode: true,
})
resp.Sources[i].URL = fmt.Sprintf("%s/emby%s", aucd.Host, v.TranscodingUrl)
resp.Sources[i].IsTranscode = true
resp.Sources[i].Name = v.Name
} else if v.DirectPlayUrl != "" {
resp.Sources[i].URLs = append(resp.Sources[i].URLs, struct {
URL string
IsTranscode bool
Name string
}{
URL: fmt.Sprintf("%s/emby%s", aucd.Host, v.DirectPlayUrl),
Name: v.Name,
})
resp.Sources[i].URL = fmt.Sprintf("%s/emby%s", aucd.Host, v.DirectPlayUrl)
resp.Sources[i].IsTranscode = false
resp.Sources[i].Name = v.Name
} else {
if v.Container == "" {
continue
@ -192,14 +179,8 @@ func NewEmbyMovieCacheInitFunc(movie *model.Movie) func(ctx context.Context, arg
query.Set("Static", "true")
query.Set("MediaSourceId", v.Id)
u.RawQuery = query.Encode()
resp.Sources[i].URLs = append(resp.Sources[i].URLs, struct {
URL string
IsTranscode bool
Name string
}{
URL: u.String(),
Name: v.Name,
})
resp.Sources[i].URL = u.String()
resp.Sources[i].Name = v.Name
}
for _, msi := range v.MediaStreamInfo {
switch msi.Type {

@ -1058,16 +1058,16 @@ func proxyVendorMovie(ctx *gin.Context, movie *op.Movie) {
ctx.AbortWithStatusJSON(http.StatusBadRequest, model.NewApiErrorResp(err))
return
}
if id >= len(embyC.Sources[source].URLs) {
if id >= len(embyC.Sources[source].URL) {
log.Errorf("proxy vendor movie error: %v", "id out of range")
ctx.AbortWithStatusJSON(http.StatusBadRequest, model.NewApiErrorStringResp("id out of range"))
return
}
if embyC.Sources[source].URLs[id].IsTranscode {
ctx.Redirect(http.StatusFound, embyC.Sources[source].URLs[id].URL)
if embyC.Sources[source].IsTranscode {
ctx.Redirect(http.StatusFound, embyC.Sources[source].URL)
return
}
err = proxyURL(ctx, embyC.Sources[source].URLs[id].URL, nil)
err = proxyURL(ctx, embyC.Sources[source].URL, nil)
if err != nil {
log.Errorf("proxy vendor movie error: %v", err)
}
@ -1263,33 +1263,38 @@ func genVendorMovie(ctx context.Context, user *op.User, opMovie *op.Movie, userA
}
if !movie.Base.Proxy {
for i, es := range data.Sources {
if len(es.URLs) == 0 {
if i != len(data.Sources)-1 {
continue
}
if movie.Base.Url == "" {
return nil, errors.New("no source")
}
if len(data.Sources) == 0 {
return nil, errors.New("no source")
}
movie.Base.Url = data.Sources[0].URL
for _, s := range data.Sources[0].Subtitles {
if movie.Base.Subtitles == nil {
movie.Base.Subtitles = make(map[string]*dbModel.Subtitle, len(data.Sources[0].Subtitles))
}
movie.Base.Url = es.URLs[0].URL
if len(es.Subtitles) == 0 {
continue
movie.Base.Subtitles[s.Name] = &dbModel.Subtitle{
URL: s.URL,
Type: s.Type,
}
for _, s := range es.Subtitles {
}
for _, s := range data.Sources[1:] {
if movie.Base.MoreSource == nil {
movie.Base.MoreSource = make(map[string]string, len(data.Sources)-1)
}
movie.Base.MoreSource[s.Name] = s.URL
for _, subt := range s.Subtitles {
if movie.Base.Subtitles == nil {
movie.Base.Subtitles = make(map[string]*dbModel.Subtitle, len(es.Subtitles))
movie.Base.Subtitles = make(map[string]*dbModel.Subtitle, len(s.Subtitles))
}
movie.Base.Subtitles[s.Name] = &dbModel.Subtitle{
URL: s.URL,
Type: s.Type,
movie.Base.Subtitles[subt.Name] = &dbModel.Subtitle{
URL: subt.URL,
Type: subt.Type,
}
}
}
} else {
for si, es := range data.Sources {
if len(es.URLs) == 0 {
if len(es.URL) == 0 {
if si != len(data.Sources)-1 {
continue
}
@ -1304,14 +1309,13 @@ func genVendorMovie(ctx context.Context, user *op.User, opMovie *op.Movie, userA
}
rawQuery := url.Values{}
rawQuery.Set("source", strconv.Itoa(si))
rawQuery.Set("id", strconv.Itoa(0))
rawQuery.Set("token", userToken)
u := url.URL{
Path: rawPath,
RawQuery: rawQuery.Encode(),
}
movie.Base.Url = u.String()
movie.Base.Type = utils.GetUrlExtension(es.URLs[0].URL)
movie.Base.Type = utils.GetUrlExtension(es.URL)
if len(es.Subtitles) == 0 {
continue

Loading…
Cancel
Save