mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 14:22:04 +08:00
serve dlna: fix missing mime types on Android causing missing videos
Before this fix serve dlna was only using the built in database of mime types to look up the mime types of files. On Android (and possibly other systems) this is very small. The symptoms of this problem was serve dlna only listing images and not videos. After this fix we use the backend's idea of the mime type if possible which will be more accurate. Fixes #3475
This commit is contained in:
parent
f67798d73e
commit
39ae7c7ac0
|
@ -1,6 +1,7 @@
|
|||
package dlna
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"log"
|
||||
|
@ -33,7 +34,7 @@ var mediaMimeTypeRegexp = regexp.MustCompile("^(video|audio|image)/")
|
|||
|
||||
// Turns the given entry and DMS host into a UPnP object. A nil object is
|
||||
// returned if the entry is not of interest.
|
||||
func (cds *contentDirectoryService) cdsObjectToUpnpavObject(cdsObject object, fileInfo os.FileInfo, host string) (ret interface{}, err error) {
|
||||
func (cds *contentDirectoryService) cdsObjectToUpnpavObject(cdsObject object, fileInfo vfs.Node, host string) (ret interface{}, err error) {
|
||||
obj := upnpav.Object{
|
||||
ID: cdsObject.ID(),
|
||||
Restricted: 1,
|
||||
|
@ -51,7 +52,15 @@ func (cds *contentDirectoryService) cdsObjectToUpnpavObject(cdsObject object, fi
|
|||
return
|
||||
}
|
||||
|
||||
mimeType := fs.MimeTypeFromName(fileInfo.Name())
|
||||
// Read the mime type from the fs.Object if possible,
|
||||
// otherwise fall back to working out what it is from the file path.
|
||||
var mimeType string
|
||||
if o, ok := fileInfo.DirEntry().(fs.Object); ok {
|
||||
mimeType = fs.MimeType(context.TODO(), o)
|
||||
} else {
|
||||
mimeType = fs.MimeTypeFromName(fileInfo.Name())
|
||||
}
|
||||
|
||||
mediaType := mediaMimeTypeRegexp.FindStringSubmatch(mimeType)
|
||||
if mediaType == nil {
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue
Block a user