Skip to content

Commit 017eb95

Browse files
authored
Merge pull request #150 from CatKasha/patch-1
improved mp3 detection
2 parents d6a2dc5 + 96ea46b commit 017eb95

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

filetype/types/audio.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,25 @@ def __init__(self):
4040
)
4141

4242
def match(self, buf):
43-
return (len(buf) > 2 and
44-
((buf[0] == 0x49 and
45-
buf[1] == 0x44 and
46-
buf[2] == 0x33) or
47-
(buf[0] == 0xFF and
48-
buf[1] == 0xF2) or
49-
(buf[0] == 0xFF and
50-
buf[1] == 0xF3) or
51-
(buf[0] == 0xFF and
52-
buf[1] == 0xFB)))
43+
if len(buf) > 2:
44+
if (
45+
buf[0] == 0x49 and
46+
buf[1] == 0x44 and
47+
buf[2] == 0x33
48+
):
49+
return True
50+
51+
if buf[0] == 0xFF:
52+
if (
53+
buf[1] == 0xE2 or # MPEG 2.5 with error protection
54+
buf[1] == 0xE3 or # MPEG 2.5 w/o error protection
55+
buf[1] == 0xF2 or # MPEG 2 with error protection
56+
buf[1] == 0xF3 or # MPEG 2 w/o error protection
57+
buf[1] == 0xFA or # MPEG 1 with error protection
58+
buf[1] == 0xFB # MPEG 1 w/o error protection
59+
):
60+
return True
61+
return False
5362

5463

5564
class M4a(Type):

0 commit comments

Comments
 (0)