diff --git a/LICENSE b/LICENSE index 13b61daa..f1b456e9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 Gabriel Vasile +Copyright (c) 2018, 2019 Gabriel Vasile Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/matchers/signature.go b/matchers/signature.go index 29daacb1..a3364de4 100644 --- a/matchers/signature.go +++ b/matchers/signature.go @@ -111,7 +111,7 @@ func (xSig xmlSig) detect(in []byte) bool { } localNameIndex := bytes.Index(in, xSig.localName) - return 0 < localNameIndex && localNameIndex < bytes.Index(in, xSig.xmlns) + return localNameIndex != -1 && localNameIndex < bytes.Index(in, xSig.xmlns) } func detect(in []byte, sigs []sig) bool { diff --git a/matchers/video.go b/matchers/video.go index bae9ea3f..694104b2 100644 --- a/matchers/video.go +++ b/matchers/video.go @@ -56,13 +56,6 @@ func Mpeg(in []byte) bool { in[3] >= 0xB0 && in[3] <= 0xBF } -// QuickTime matches a QuickTime File Format file. -func QuickTime(in []byte) bool { - return len(in) > 12 && - (bytes.Equal(in[4:12], []byte("ftypqt ")) || - bytes.Equal(in[4:8], []byte("moov"))) -} - // Avi matches an Audio Video Interleaved file. func Avi(in []byte) bool { return len(in) > 16 && diff --git a/matchers/video_ftyp.go b/matchers/video_ftyp.go index 3fc35a87..2bb1d82c 100644 --- a/matchers/video_ftyp.go +++ b/matchers/video_ftyp.go @@ -28,6 +28,8 @@ var ( // Nero Digital AAC Audio ftypSig("NDAS"), } + qtSigs = []sig{ftypSig("qt "), ftypSig("moov")} + mqvSigs = []sig{ftypSig("mqt ")} m4aSigs = []sig{ftypSig("M4A ")} // TODO: add support for remaining video formats at ftyps.com ) @@ -37,22 +39,32 @@ func Mp4(in []byte) bool { return detect(in, mp4Sigs) } +// ThreeGP matches a 3GPP file. +func ThreeGP(in []byte) bool { + return detect(in, threeGPSigs) +} + +// ThreeG2 matches a 3GPP2 file. +func ThreeG2(in []byte) bool { + return detect(in, threeG2Sigs) +} + // AMp4 matches an audio MP4 file. func AMp4(in []byte) bool { return detect(in, amp4Sigs) } -// M4a matches an audio M4A file. -func M4a(in []byte) bool { - return detect(in, m4aSigs) +// QuickTime matches a QuickTime File Format file. +func QuickTime(in []byte) bool { + return detect(in, qtSigs) } -// ThreeGP matches a 3GPP file. -func ThreeGP(in []byte) bool { - return detect(in, threeGPSigs) +// Mqv matches a Sony / Mobile QuickTime file. +func Mqv(in []byte) bool { + return detect(in, mqvSigs) } -// ThreeG2 matches a 3GPP2 file. -func ThreeG2(in []byte) bool { - return detect(in, threeG2Sigs) +// M4a matches an audio M4A file. +func M4a(in []byte) bool { + return detect(in, m4aSigs) } diff --git a/mime_test.go b/mime_test.go index d1145d4e..9cc59982 100644 --- a/mime_test.go +++ b/mime_test.go @@ -48,6 +48,7 @@ var files = map[string]*Node{ "a.flv": Flv, "a.avi": Avi, "a.mov": QuickTime, + "a.mqv": Mqv, "a.mpeg": Mpeg, "a.mkv": Mkv, diff --git a/node.go b/node.go index 50f61463..1de058b2 100644 --- a/node.go +++ b/node.go @@ -72,8 +72,8 @@ func (n *Node) Tree() string { return printTree(n, 0) } -func (n *Node) flatten() (out []*Node) { - out = append(out, n) +func (n *Node) flatten() []*Node { + out := []*Node{n} for _, c := range n.children { out = append(out, c.flatten()...) } diff --git a/supported_mimes.md b/supported_mimes.md index 8c03ad49..34b0b072 100644 --- a/supported_mimes.md +++ b/supported_mimes.md @@ -38,6 +38,7 @@ Extension | MIME type **au** | audio/basic **mpeg** | video/mpeg **mov** | video/quicktime +**mqv** | video/quicktime **mp4** | video/mp4 **webm** | video/webm **3gp** | video/3gpp diff --git a/testdata/a.mqv b/testdata/a.mqv new file mode 100644 index 00000000..272a5c8d Binary files /dev/null and b/testdata/a.mqv differ diff --git a/tree.go b/tree.go index b6f401ab..bcf346ea 100644 --- a/tree.go +++ b/tree.go @@ -9,7 +9,7 @@ var Root = NewNode("application/octet-stream", "", matchers.True, SevenZ, Zip, Tar, Pdf, Doc, Xls, Ppt, Ps, Psd, Ogg, Png, Jpg, Gif, Webp, Tiff, Bmp, Ico, Mp3, Flac, Midi, Ape, MusePack, Amr, Wav, Aiff, Au, - Mpeg, QuickTime, Mp4, WebM, ThreeGP, ThreeG2, Avi, Flv, Mkv, AMp4, M4a, + Mpeg, QuickTime, Mqv, Mp4, WebM, ThreeGP, ThreeG2, Avi, Flv, Mkv, AMp4, M4a, Txt, Gzip, Class, Swf, Crx, Woff, Woff2, Wasm, ) @@ -80,6 +80,7 @@ var ( WebM = NewNode("video/webm", "webm", matchers.WebM) Mpeg = NewNode("video/mpeg", "mpeg", matchers.Mpeg) QuickTime = NewNode("video/quicktime", "mov", matchers.QuickTime) + Mqv = NewNode("video/quicktime", "mqv", matchers.Mqv) ThreeGP = NewNode("video/3gpp", "3gp", matchers.ThreeGP) ThreeG2 = NewNode("video/3gpp2", "3g2", matchers.ThreeG2) Avi = NewNode("video/x-msvideo", "avi", matchers.Avi)