diff --git a/cmd/serve/dlna/cds.go b/cmd/serve/dlna/cds.go index 46bb7c192..94b37bf18 100644 --- a/cmd/serve/dlna/cds.go +++ b/cmd/serve/dlna/cds.go @@ -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), }) } diff --git a/fs/mimetype.go b/fs/mimetype.go index a0bfcd9fe..93f82172d 100644 --- a/fs/mimetype.go +++ b/fs/mimetype.go @@ -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) == "" {