mirror of
https://github.com/navidrome/navidrome.git
synced 2025-05-17 18:46:55 +03:00
Redirecting away from raw file paths to stream endpoints
This commit is contained in:
parent
fd2456d63e
commit
545b266c7f
@ -284,8 +284,6 @@ func (cds *contentDirectoryService) doMediaFiles(tracks model.MediaFiles, basePa
|
|||||||
Res: make([]upnpav.Resource, 0, 1),
|
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)
|
streamAccessPath := path.Join(resourcePath, resourceStreamPath, track.ID)
|
||||||
item.Res = append(item.Res, upnpav.Resource{
|
item.Res = append(item.Res, upnpav.Resource{
|
||||||
URL: (&url.URL{
|
URL: (&url.URL{
|
||||||
@ -318,12 +316,6 @@ func floatToDurationString(totalSeconds32 float32) string {
|
|||||||
return fmt.Sprintf("%02d:%02d:%02d.%03d", hours, minutes, seconds, ms)
|
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) {
|
func (cds *contentDirectoryService) doAlbums(albums model.Albums, basepath string, ret []interface{}, host string) ([]interface{}, error) {
|
||||||
for _, album := range albums {
|
for _, album := range albums {
|
||||||
child := object{
|
child := object{
|
||||||
|
@ -89,6 +89,8 @@ func New(ds model.DataStore, broker events.Broker, mediastreamer core.MediaStrea
|
|||||||
ModelNumber: consts.Version,
|
ModelNumber: consts.Version,
|
||||||
RootDeviceUUID: makeDeviceUUID("Navidrome"),
|
RootDeviceUUID: makeDeviceUUID("Navidrome"),
|
||||||
waitChan: make(chan struct{}),
|
waitChan: make(chan struct{}),
|
||||||
|
ms: mediastreamer,
|
||||||
|
art: artwork,
|
||||||
},
|
},
|
||||||
ms: mediastreamer,
|
ms: mediastreamer,
|
||||||
art: artwork,
|
art: artwork,
|
||||||
@ -321,37 +323,25 @@ func (s *SSDPServer) resourceHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.ServeContent(w, r, remotePath, time.Now(), fileHandle)
|
http.ServeContent(w, r, remotePath, time.Now(), fileHandle)
|
||||||
break;
|
break;
|
||||||
case resourceStreamPath:
|
case resourceStreamPath:
|
||||||
//TODO streaming endpoint
|
|
||||||
log.Debug(fmt.Sprintf("TODO IMPLEMENT THIS: %+v", r))
|
|
||||||
|
|
||||||
//Copypasta stream.go:52
|
//Copypasta stream.go:52
|
||||||
|
|
||||||
id := components[1]
|
fileId := components[1]
|
||||||
|
|
||||||
ctx := r.Context()
|
//TODO figure out format, bitrate
|
||||||
/*
|
stream, err := s.ms.NewStream(r.Context(), fileId, "mp3", 0, 0)
|
||||||
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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Error("Error streaming file", "id", fileId, err)
|
||||||
|
//TODO throw 500
|
||||||
//eturn nil, err
|
//eturn nil, err
|
||||||
}
|
}
|
||||||
log.Debug("2")
|
|
||||||
// Make sure the stream will be closed at the end, to avoid leakage
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := stream.Close(); err != nil && log.IsGreaterOrEqualTo(log.LevelDebug) {
|
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-Type-Options", "nosniff")
|
||||||
w.Header().Set("X-Content-Duration", strconv.FormatFloat(float64(stream.Duration()), 'G', -1, 32))
|
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)
|
http.ServeContent(w, r, stream.Name(), stream.ModTime(), stream)
|
||||||
log.Debug("5")
|
|
||||||
break;
|
break;
|
||||||
case resourceArtPath:
|
case resourceArtPath:
|
||||||
log.Debug("1a")
|
log.Debug("1a")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user