detect video based on extension

This commit is contained in:
Vitaliy 2018-11-09 16:44:17 +02:00
parent cf87750009
commit c1dd71fe6e

View File

@ -233,7 +233,7 @@ func (i *File) GetFileType(checkContent bool) error {
mimetype = http.DetectContentType(buffer[:n]) 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" i.Type = "video"
return nil return nil
} }
@ -281,6 +281,17 @@ End:
return nil 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. // Checksum retrieves the checksum of a file.
func (i File) Checksum(algo string) (string, error) { func (i File) Checksum(algo string) (string, error) {