mirror of
https://github.com/rclone/rclone.git
synced 2024-11-07 09:04:52 +01:00
dlna: set more correct mime type
The code currently hardcodes `text/srt` for all subtitles. `text/srt` is wrong, it seems `application/x-subrip` is the official extension coming from the official mime database, at least (and still works with the Samsung TV I tested with). Also add that one to `fs/ mimetype.go`. Compared to previous iterations of this PR, I dropped tests ensuring certain mime types are present - as detection still seems to be fairly platform-specific.
This commit is contained in:
parent
2e007f89c7
commit
00e073df1e
@ -101,9 +101,24 @@ func (cds *contentDirectoryService) cdsObjectToUpnpavObject(cdsObject object, fi
|
||||
Host: host,
|
||||
Path: path.Join(resPath, resource.Path()),
|
||||
}).String()
|
||||
|
||||
// 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 := resource.DirEntry().(fs.Object); ok {
|
||||
mimeType = fs.MimeType(context.TODO(), o)
|
||||
// If backend doesn't know what the mime type is then
|
||||
// try getting it from the file name
|
||||
if mimeType == "application/octet-stream" {
|
||||
mimeType = fs.MimeTypeFromName(resource.Name())
|
||||
}
|
||||
} else {
|
||||
mimeType = fs.MimeTypeFromName(resource.Name())
|
||||
}
|
||||
|
||||
item.Res = append(item.Res, upnpav.Resource{
|
||||
URL: subtitleURL,
|
||||
ProtocolInfo: fmt.Sprintf("http-get:*:%s:*", "text/srt"),
|
||||
ProtocolInfo: fmt.Sprintf("http-get:*:%s:*", mimeType),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ func init() {
|
||||
{"video/webm", ".webm"},
|
||||
{"video/x-msvideo", ".avi"},
|
||||
{"video/x-matroska", ".mpv,.mkv"},
|
||||
{"text/srt", ".srt"},
|
||||
{"application/x-subrip", ".srt"},
|
||||
} {
|
||||
for _, ext := range strings.Split(t.extensions, ",") {
|
||||
if mime.TypeByExtension(ext) == "" {
|
||||
|
Loading…
Reference in New Issue
Block a user