Fix #628: Add setting to transcode stream

This commit is contained in:
Drew Weymouth
2025-05-31 10:12:57 -07:00
parent 0fd8b4621b
commit 265e4f961f
9 changed files with 74 additions and 15 deletions
+8 -2
View File
@@ -142,7 +142,10 @@ type ThemeConfig struct {
}
type TranscodingConfig struct {
ForceRawFile bool
ForceRawFile bool
RequestTranscode bool
Codec string
MaxBitRateKBPS int
}
type PeakMeterConfig struct {
@@ -260,7 +263,10 @@ func DefaultConfig(appVersionTag string) *Config {
PreventClipping: true,
},
Transcoding: TranscodingConfig{
ForceRawFile: false,
ForceRawFile: false,
RequestTranscode: false,
Codec: "opus",
MaxBitRateKBPS: 160,
},
Theme: ThemeConfig{
Appearance: "Dark",
@@ -332,12 +332,19 @@ func (j *jellyfinMediaProvider) SetFavorite(params mediaprovider.RatingFavoriteP
return err
}
func (j *jellyfinMediaProvider) GetStreamURL(trackID string, forceRaw bool) (string, error) {
return j.client.GetStreamURL(trackID)
func (j *jellyfinMediaProvider) GetStreamURL(trackID string, transcode *mediaprovider.TranscodeSettings, forceRaw bool) (string, error) {
var jfTranscode *jellyfin.TranscodeOptions
if transcode != nil {
jfTranscode = &jellyfin.TranscodeOptions{
AudioCodec: transcode.Codec,
AudioBitRate: uint32(transcode.BitRateKBPS * 1000),
}
}
return j.client.GetStreamURL(trackID, jfTranscode)
}
func (j *jellyfinMediaProvider) DownloadTrack(trackID string) (io.Reader, error) {
url, err := j.client.GetStreamURL(trackID)
url, err := j.client.GetStreamURL(trackID, nil)
if err != nil {
return nil, err
}
+6 -1
View File
@@ -184,6 +184,11 @@ type LoginResponse struct {
IsAuthError bool
}
type TranscodeSettings struct {
Codec string
BitRateKBPS int
}
type Server interface {
Login(username, password string) LoginResponse
MediaProvider() MediaProvider
@@ -234,7 +239,7 @@ type MediaProvider interface {
GetFavorites() (Favorites, error)
GetStreamURL(trackID string, forceRaw bool) (string, error)
GetStreamURL(trackID string, transcodeSettings *TranscodeSettings, forceRaw bool) (string, error)
GetTopTracks(artist Artist, count int) ([]*Track, error)
@@ -234,9 +234,12 @@ func (s *subsonicMediaProvider) GetSimilarTracks(artistID string, count int) ([]
return sharedutil.MapSlice(tr, toTrack), nil
}
func (s *subsonicMediaProvider) GetStreamURL(trackID string, forceRaw bool) (string, error) {
func (s *subsonicMediaProvider) GetStreamURL(trackID string, transcode *mediaprovider.TranscodeSettings, forceRaw bool) (string, error) {
m := make(map[string]string)
if forceRaw {
if transcode != nil {
m["format"] = transcode.Codec
m["maxBitRate"] = strconv.Itoa(transcode.BitRateKBPS)
} else if forceRaw {
m["format"] = "raw"
}
u, err := s.client.GetStreamURL(trackID, m)
+8 -1
View File
@@ -652,7 +652,14 @@ func (p *playbackEngine) setTrack(idx int, next bool, startTime float64) error {
item := p.playQueue[idx]
meta = item.Metadata()
if tr, ok := item.(*mediaprovider.Track); ok {
url, err = p.sm.Server.GetStreamURL(tr.ID, p.transcodeCfg.ForceRawFile)
var ts *mediaprovider.TranscodeSettings
if p.transcodeCfg.RequestTranscode {
ts = &mediaprovider.TranscodeSettings{
Codec: p.transcodeCfg.Codec,
BitRateKBPS: p.transcodeCfg.MaxBitRateKBPS,
}
}
url, err = p.sm.Server.GetStreamURL(tr.ID, ts, p.transcodeCfg.ForceRawFile)
} else {
url = item.(*mediaprovider.RadioStation).StreamURL
}