@@ -3,7 +3,9 @@ package emby
33import (
44 "encoding/json"
55 "fmt"
6+ "net/url"
67 "regexp"
8+ "strconv"
79 "strings"
810)
911
@@ -70,16 +72,15 @@ func RewritePlaybackInfoWithReport(body []byte, itemID string, publicURL string,
7072 }
7173 sourceID , _ := source ["Id" ].(string )
7274 sessionID := SessionID (itemID , sourceID , index )
73- transcodeURL := fmt .Sprintf ("/streambridge/transcode/%s/master.m3u8" , sessionID )
74- if len (rawQuery ) > 0 && rawQuery [0 ] != "" {
75- transcodeURL += "?" + rawQuery [0 ]
76- }
77-
7875 beforeDirectPlay , _ := source ["SupportsDirectPlay" ].(bool )
7976 beforeTranscode , _ := source ["SupportsTranscoding" ].(bool )
8077 beforeDirectStreamURL , _ := source ["DirectStreamUrl" ].(string )
8178 beforeTranscodingURL , _ := source ["TranscodingUrl" ].(string )
8279 sourceReport := sourceReportFromMap (source )
80+ transcodeURL := fmt .Sprintf ("/streambridge/transcode/%s/master.m3u8" , sessionID )
81+ if enrichedQuery := transcodeQueryForSource (firstRawQuery (rawQuery ), sourceID , sourceReport .AudioStreams ); enrichedQuery != "" {
82+ transcodeURL += "?" + enrichedQuery
83+ }
8384 sourceReport .Index = index
8485 sourceReport .ID = sourceID
8586 sourceReport .SessionID = sessionID
@@ -132,6 +133,27 @@ func RewritePlaybackInfoWithReport(body []byte, itemID string, publicURL string,
132133 return out , true , report , nil
133134}
134135
136+ func firstRawQuery (rawQuery []string ) string {
137+ if len (rawQuery ) == 0 {
138+ return ""
139+ }
140+ return rawQuery [0 ]
141+ }
142+
143+ func transcodeQueryForSource (rawQuery string , sourceID string , audioStreams []AudioStreamReport ) string {
144+ query , err := url .ParseQuery (rawQuery )
145+ if err != nil {
146+ return rawQuery
147+ }
148+ if sourceID != "" && query .Get ("MediaSourceId" ) == "" {
149+ query .Set ("MediaSourceId" , sourceID )
150+ }
151+ if query .Get ("AudioStreamIndex" ) == "" && len (audioStreams ) > 0 {
152+ query .Set ("AudioStreamIndex" , strconv .Itoa (audioStreams [0 ].Index ))
153+ }
154+ return query .Encode ()
155+ }
156+
135157func sourceReportFromMap (source map [string ]any ) SourceReport {
136158 report := SourceReport {
137159 Name : stringValue (source , "Name" ),
0 commit comments