From 545b266c7f67e7dc274099cf9c4509fc1d533c24 Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Sat, 8 Feb 2025 16:52:15 +0000 Subject: [PATCH] Redirecting away from raw file paths to stream endpoints --- dlna/contenddirectoryservice.go | 8 -------- dlna/dlnaserver.go | 26 ++++++++------------------ 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/dlna/contenddirectoryservice.go b/dlna/contenddirectoryservice.go index 850ca68ad..ef2e0bb54 100644 --- a/dlna/contenddirectoryservice.go +++ b/dlna/contenddirectoryservice.go @@ -284,8 +284,6 @@ func (cds *contentDirectoryService) doMediaFiles(tracks model.MediaFiles, basePa Res: make([]upnpav.Resource, 0, 1), } - //TODO replace this with a streaming path - //directFileAccessPath := path.Join(resourcePath, resourceFilePath, "Music/Files", strings.TrimPrefix(track.Path, conf.Server.MusicFolder)) streamAccessPath := path.Join(resourcePath, resourceStreamPath, track.ID) item.Res = append(item.Res, upnpav.Resource{ URL: (&url.URL{ @@ -318,12 +316,6 @@ func floatToDurationString(totalSeconds32 float32) string { return fmt.Sprintf("%02d:%02d:%02d.%03d", hours, minutes, seconds, ms) } -func (cds *contentDirectoryService) doAlbum(album *model.Album, basepath string, ret []interface{}, host string) ([]interface{}, error) { - log.Debug(fmt.Sprintf("TODO: doAlbum Called with : '%+v', '%s'", album, basepath)) - panic("doAlbum Called!") - return ret, nil -} - func (cds *contentDirectoryService) doAlbums(albums model.Albums, basepath string, ret []interface{}, host string) ([]interface{}, error) { for _, album := range albums { child := object{ diff --git a/dlna/dlnaserver.go b/dlna/dlnaserver.go index 06f1ed04e..fd0ecbcb5 100644 --- a/dlna/dlnaserver.go +++ b/dlna/dlnaserver.go @@ -89,6 +89,8 @@ func New(ds model.DataStore, broker events.Broker, mediastreamer core.MediaStrea ModelNumber: consts.Version, RootDeviceUUID: makeDeviceUUID("Navidrome"), waitChan: make(chan struct{}), + ms: mediastreamer, + art: artwork, }, ms: mediastreamer, art: artwork, @@ -321,37 +323,25 @@ func (s *SSDPServer) resourceHandler(w http.ResponseWriter, r *http.Request) { http.ServeContent(w, r, remotePath, time.Now(), fileHandle) break; case resourceStreamPath: - //TODO streaming endpoint - log.Debug(fmt.Sprintf("TODO IMPLEMENT THIS: %+v", r)) - //Copypasta stream.go:52 - id := components[1] + fileId := components[1] - ctx := r.Context() - /* - maxBitRate := p.IntOr("maxBitRate", 0) - format, _ := p.String("format") - timeOffset := p.IntOr("timeOffset", 0) -*/ //TODO figure out format, bitrate -log.Debug(fmt.Sprintf("1 %+v | comp: %+v",id, components)) - stream, err := s.ms.NewStream(ctx, id, "mp3", 0, 0) + //TODO figure out format, bitrate + stream, err := s.ms.NewStream(r.Context(), fileId, "mp3", 0, 0) if err != nil { + log.Error("Error streaming file", "id", fileId, err) + //TODO throw 500 //eturn nil, err } - log.Debug("2") - // Make sure the stream will be closed at the end, to avoid leakage defer func() { if err := stream.Close(); err != nil && log.IsGreaterOrEqualTo(log.LevelDebug) { - log.Error("Error closing stream", "id", id, "file", stream.Name(), err) + log.Error("Error closing stream", "id", fileId, "file", stream.Name(), err) } }() - log.Debug("3") w.Header().Set("X-Content-Type-Options", "nosniff") w.Header().Set("X-Content-Duration", strconv.FormatFloat(float64(stream.Duration()), 'G', -1, 32)) - log.Debug("4") http.ServeContent(w, r, stream.Name(), stream.ModTime(), stream) - log.Debug("5") break; case resourceArtPath: log.Debug("1a")