Skip to content

Commit

Permalink
Merge pull request h2non#150 from CatKasha/patch-1
Browse files Browse the repository at this point in the history
improved mp3 detection
  • Loading branch information
h2non authored Nov 17, 2023
2 parents d6a2dc5 + 96ea46b commit 017eb95
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions filetype/types/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,25 @@ def __init__(self):
)

def match(self, buf):
return (len(buf) > 2 and
((buf[0] == 0x49 and
buf[1] == 0x44 and
buf[2] == 0x33) or
(buf[0] == 0xFF and
buf[1] == 0xF2) or
(buf[0] == 0xFF and
buf[1] == 0xF3) or
(buf[0] == 0xFF and
buf[1] == 0xFB)))
if len(buf) > 2:
if (
buf[0] == 0x49 and
buf[1] == 0x44 and
buf[2] == 0x33
):
return True

if buf[0] == 0xFF:
if (
buf[1] == 0xE2 or # MPEG 2.5 with error protection
buf[1] == 0xE3 or # MPEG 2.5 w/o error protection
buf[1] == 0xF2 or # MPEG 2 with error protection
buf[1] == 0xF3 or # MPEG 2 w/o error protection
buf[1] == 0xFA or # MPEG 1 with error protection
buf[1] == 0xFB # MPEG 1 w/o error protection
):
return True
return False


class M4a(Type):
Expand Down

0 comments on commit 017eb95

Please sign in to comment.