diff --git a/lib/file.go b/lib/file.go index 9b7fc899..86b82ebb 100644 --- a/lib/file.go +++ b/lib/file.go @@ -233,7 +233,7 @@ func (i *File) GetFileType(checkContent bool) error { mimetype = http.DetectContentType(buffer[:n]) } - if strings.HasPrefix(mimetype, "video") || strings.HasSuffix(mimetype, "octet-stream") { + if strings.HasPrefix(mimetype, "video") || isVideoExtension(i.Extension) { i.Type = "video" return nil } @@ -281,6 +281,17 @@ End: return nil } +func isVideoExtension(ext string) (res bool) { + res = false + ext = strings.ToUpper(strings.Replace(ext, ".", "", -1)) + for _, v := range []string{"3GP", "3G2", "ASF", "WMA", "WMV", "AVI", "DIVX", "F4V", "EVO", "FLV", "MKV", "MK3D", "MKA", "MKS", "WEBM", "MCF", "MP4", "MPG", "MPEG", "M2P", "PS", "TS", "M2TS", "MXF", "OGG", "MOV", "QT", "RMVB", "VOB"} { + if strings.EqualFold(ext, v) { + res = true + break + } + } + return res +} // Checksum retrieves the checksum of a file. func (i File) Checksum(algo string) (string, error) {