From c1dd71fe6e9576ef2a51f6e6dcb88240ba9e6d9c Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 9 Nov 2018 16:44:17 +0200 Subject: [PATCH] detect video based on extension --- lib/file.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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) {