Skip to content

Commit

Permalink
Add support for .mqv files
Browse files Browse the repository at this point in the history
plus minor fixes
  • Loading branch information
gabriel-vasile committed Apr 9, 2019
1 parent 0ff9399 commit c885b0e
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion matchers/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 0 additions & 7 deletions matchers/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
30 changes: 21 additions & 9 deletions matchers/video_ftyp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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)
}
1 change: 1 addition & 0 deletions mime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
4 changes: 2 additions & 2 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()...)
}
Expand Down
1 change: 1 addition & 0 deletions supported_mimes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added testdata/a.mqv
Binary file not shown.
3 changes: 2 additions & 1 deletion tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c885b0e

Please sign in to comment.