Skip to content

Commit

Permalink
Merge pull request #109 from fraang/master
Browse files Browse the repository at this point in the history
types/video: Fix differentiation between Matroska and WebM files
  • Loading branch information
h2non authored Apr 19, 2022
2 parents 557042f + 008a59b commit b5c7694
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions filetype/types/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,9 @@ def __init__(self):
)

def match(self, buf):
return ((len(buf) > 15 and
buf[0] == 0x1A and buf[1] == 0x45 and
buf[2] == 0xDF and buf[3] == 0xA3 and
buf[4] == 0x93 and buf[5] == 0x42 and
buf[6] == 0x82 and buf[7] == 0x88 and
buf[8] == 0x6D and buf[9] == 0x61 and
buf[10] == 0x74 and buf[11] == 0x72 and
buf[12] == 0x6F and buf[13] == 0x73 and
buf[14] == 0x6B and buf[15] == 0x61) or
(len(buf) > 38 and
buf[31] == 0x6D and buf[32] == 0x61 and
buf[33] == 0x74 and buf[34] == 0x72 and
buf[35] == 0x6f and buf[36] == 0x73 and
buf[37] == 0x6B and buf[38] == 0x61))
contains_ebml_element = buf.startswith(b'\x1A\x45\xDF\xA3')
contains_doctype_element = buf.find(b'\x42\x82\x88matroska') > -1
return contains_ebml_element and contains_doctype_element


class Webm(Type):
Expand All @@ -97,12 +86,9 @@ def __init__(self):
)

def match(self, buf):
return (len(buf) > 3 and
buf[0] == 0x1A and
buf[1] == 0x45 and
buf[2] == 0xDF and
buf[3] == 0xA3)

contains_ebml_element = buf.startswith(b'\x1A\x45\xDF\xA3')
contains_doctype_element = buf.find(b'\x42\x82\x84webm') > -1
return contains_ebml_element and contains_doctype_element

class Mov(IsoBmff):
"""
Expand Down

0 comments on commit b5c7694

Please sign in to comment.