mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-31 07:30:32 +00:00
Moving direct file access under /r/f/ so we can add /r/s/ for streaming
This commit is contained in:
parent
ac04ea3834
commit
0ee848edfe
@ -84,7 +84,7 @@ func (cds *contentDirectoryService) cdsObjectToUpnpavObject(cdsObject object, is
|
|||||||
URL: (&url.URL{
|
URL: (&url.URL{
|
||||||
Scheme: "http",
|
Scheme: "http",
|
||||||
Host: host,
|
Host: host,
|
||||||
Path: path.Join(resourcePath, cdsObject.Path),
|
Path: path.Join(resourcePath, resourceFilePath, cdsObject.Path),
|
||||||
}).String(),
|
}).String(),
|
||||||
ProtocolInfo: fmt.Sprintf("http-get:*:%s:%s", mimeType, dlna.ContentFeatures{
|
ProtocolInfo: fmt.Sprintf("http-get:*:%s:%s", mimeType, dlna.ContentFeatures{
|
||||||
SupportRange: true,
|
SupportRange: true,
|
||||||
@ -285,13 +285,13 @@ func (cds *contentDirectoryService) doMediaFiles(tracks model.MediaFiles, basePa
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO replace this with a streaming path
|
//TODO replace this with a streaming path
|
||||||
directFileAccessPath := path.Join(resourcePath, strings.TrimPrefix(track.Path, conf.Server.MusicFolder))
|
//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{
|
item.Res = append(item.Res, upnpav.Resource{
|
||||||
URL: (&url.URL{
|
URL: (&url.URL{
|
||||||
Scheme: "http",
|
Scheme: "http",
|
||||||
Host: host,
|
Host: host,
|
||||||
Path: directFileAccessPath,
|
Path: streamAccessPath,
|
||||||
}).String(),
|
}).String(),
|
||||||
ProtocolInfo: fmt.Sprintf("http-get:*:%s:%s", mimeType, dlna.ContentFeatures{
|
ProtocolInfo: fmt.Sprintf("http-get:*:%s:%s", mimeType, dlna.ContentFeatures{
|
||||||
SupportRange: false,
|
SupportRange: false,
|
||||||
|
|||||||
@ -33,6 +33,8 @@ const (
|
|||||||
serverField = "Linux/3.4 DLNADOC/1.50 UPnP/1.0 DMS/1.0"
|
serverField = "Linux/3.4 DLNADOC/1.50 UPnP/1.0 DMS/1.0"
|
||||||
rootDescPath = "/rootDesc.xml"
|
rootDescPath = "/rootDesc.xml"
|
||||||
resourcePath = "/r/"
|
resourcePath = "/r/"
|
||||||
|
resourceFilePath = "f"
|
||||||
|
resourceStreamPath = "s"
|
||||||
serviceControlURL = "/ctl"
|
serviceControlURL = "/ctl"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -275,35 +277,44 @@ func isAppropriatelyConfigured(intf net.Interface) bool {
|
|||||||
func (s *SSDPServer) resourceHandler(w http.ResponseWriter, r *http.Request) {
|
func (s *SSDPServer) resourceHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
remotePath := r.URL.Path
|
remotePath := r.URL.Path
|
||||||
|
|
||||||
localFile, _ := strings.CutPrefix(remotePath, "Music/Files/")
|
components := strings.Split(remotePath, "/")
|
||||||
localFilePath := path.Join(conf.Server.MusicFolder, localFile)
|
switch components[0] {
|
||||||
|
case resourceFilePath:
|
||||||
|
localFile, _ := strings.CutPrefix(remotePath, path.Join(resourceFilePath,"Music/Files"))
|
||||||
|
localFilePath := path.Join(conf.Server.MusicFolder, localFile)
|
||||||
|
|
||||||
log.Info(fmt.Sprintf("resource handler Executed with remote path: %s, localpath: %s", remotePath, localFilePath))
|
log.Info(fmt.Sprintf("resource handler Executed with remote path: %s, localpath: %s", remotePath, localFilePath))
|
||||||
|
|
||||||
fileStats, err := os.Stat(localFilePath)
|
fileStats, err := os.Stat(localFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
w.Header().Set("Content-Length", strconv.FormatInt(fileStats.Size(), 10))
|
||||||
|
|
||||||
|
// add some DLNA specific headers
|
||||||
|
if r.Header.Get("getContentFeatures.dlna.org") != "" {
|
||||||
|
w.Header().Set("contentFeatures.dlna.org", dms_dlna.ContentFeatures{
|
||||||
|
SupportRange: true,
|
||||||
|
}.String())
|
||||||
|
}
|
||||||
|
w.Header().Set("transferMode.dlna.org", "Streaming")
|
||||||
|
|
||||||
|
os.Open(localFilePath)
|
||||||
|
fileHandle, err := os.Open(localFilePath)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("file streaming error: %+v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer fileHandle.Close()
|
||||||
|
|
||||||
|
http.ServeContent(w, r, remotePath, time.Now(), fileHandle)
|
||||||
|
break;
|
||||||
|
case resourceStreamPath:
|
||||||
|
//TODO streaming endpoint
|
||||||
|
log.Debug(fmt.Sprintf("TODO IMPLEMENT THIS: %+v", r))
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Length", strconv.FormatInt(fileStats.Size(), 10))
|
|
||||||
|
|
||||||
// add some DLNA specific headers
|
|
||||||
if r.Header.Get("getContentFeatures.dlna.org") != "" {
|
|
||||||
w.Header().Set("contentFeatures.dlna.org", dms_dlna.ContentFeatures{
|
|
||||||
SupportRange: true,
|
|
||||||
}.String())
|
|
||||||
}
|
|
||||||
w.Header().Set("transferMode.dlna.org", "Streaming")
|
|
||||||
|
|
||||||
os.Open(localFilePath)
|
|
||||||
fileHandle, err := os.Open(localFilePath)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("file streaming error: %+v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer fileHandle.Close()
|
|
||||||
|
|
||||||
http.ServeContent(w, r, remotePath, time.Now(), fileHandle)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns /rootDesc.xml templated
|
// returns /rootDesc.xml templated
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user