Server changes/Sonarr
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/ponzischeme89/memby/server/internal/emby"
|
||||
@@ -40,15 +41,18 @@ func (s *Server) handlePlayback(w http.ResponseWriter, r *http.Request, sess sto
|
||||
}
|
||||
cred := credentials(sess)
|
||||
|
||||
raw, err := s.emby.Item(ctx, cred, itemID, "RunTimeTicks,SeriesName")
|
||||
if err != nil {
|
||||
s.writeUpstreamError(w, err, "could not load the item")
|
||||
return
|
||||
}
|
||||
item, err := emby.Summarise(raw)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusBadGateway, "unreadable item from emby")
|
||||
return
|
||||
item, hinted := playbackHint(r, itemID)
|
||||
if !hinted {
|
||||
raw, err := s.emby.Item(ctx, cred, itemID, "RunTimeTicks,SeriesName")
|
||||
if err != nil {
|
||||
s.writeUpstreamError(w, err, "could not load the item")
|
||||
return
|
||||
}
|
||||
item, err = emby.Summarise(raw)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusBadGateway, "unreadable item from emby")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
target := item
|
||||
@@ -78,6 +82,31 @@ func (s *Server) handlePlayback(w http.ResponseWriter, r *http.Request, sess sto
|
||||
})
|
||||
}
|
||||
|
||||
// Current clients already know the selected item's type, title and cached resume point.
|
||||
// Accepting those as hints removes one serial Emby request from every launch. Older
|
||||
// clients omit them and retain the authoritative lookup above.
|
||||
func playbackHint(r *http.Request, itemID string) (emby.Summary, bool) {
|
||||
itemType := strings.TrimSpace(r.URL.Query().Get("type"))
|
||||
switch {
|
||||
case strings.EqualFold(itemType, "Movie"):
|
||||
itemType = "Movie"
|
||||
case strings.EqualFold(itemType, "Episode"):
|
||||
itemType = "Episode"
|
||||
case strings.EqualFold(itemType, "Series"):
|
||||
itemType = "Series"
|
||||
default:
|
||||
return emby.Summary{}, false
|
||||
}
|
||||
resumeMs, _ := strconv.ParseInt(r.URL.Query().Get("resumePositionMs"), 10, 64)
|
||||
item := emby.Summary{
|
||||
ID: itemID,
|
||||
Name: strings.TrimSpace(r.URL.Query().Get("title")),
|
||||
Type: itemType,
|
||||
}
|
||||
item.UserData.PlaybackPositionTicks = max64(resumeMs, 0) * ticksPerMillisecond
|
||||
return item, true
|
||||
}
|
||||
|
||||
// firstPlayableEpisode prefers the server's next-up choice and falls back to episode one.
|
||||
func (s *Server) firstPlayableEpisode(ctx context.Context, cred emby.Credentials, seriesID string) (*emby.Summary, error) {
|
||||
nextUp, err := s.emby.NextUp(ctx, cred, url.Values{
|
||||
|
||||
Reference in New Issue
Block a user