diff --git a/mutagen/aac.py b/mutagen/aac.py index 274b20df..79851cea 100644 --- a/mutagen/aac.py +++ b/mutagen/aac.py @@ -408,12 +408,34 @@ def load(self, filething): def add_tags(self): raise AACError("doesn't support tags") + @staticmethod + def _is_probably_adts_header(header: bytes) -> bool: + if len(header) < 9: + return False + + # Syncword + if not (header[0] == 0xFF): + return False + if not (header[1] & 0xF0 == 0xF0): + return False + + # Layer + if not (header[1] & 0b0000_0110 == 0): + return False + + # Sampling index + if ((header[2] & 0b0011_1100) >> 2) > 0xC: + return False + + return True + @staticmethod def score(filename, fileobj, header): filename = filename.lower() s = endswith(filename, ".aac") or endswith(filename, ".adts") or \ endswith(filename, ".adif") s += b"ADIF" in header + s += int(AAC._is_probably_adts_header(header)) return s diff --git a/tests/test_aac.py b/tests/test_aac.py index ea1e9b20..1db959ad 100644 --- a/tests/test_aac.py +++ b/tests/test_aac.py @@ -10,14 +10,14 @@ class TADTS(TestCase): def setUp(self): - original = os.path.join(DATA_DIR, "empty.aac") - self.filename = get_temp_copy(original) + self.original = os.path.join(DATA_DIR, "empty.aac") + self.filename = get_temp_copy(self.original) tag = ID3() tag.add(TIT1(text=[u"a" * 5000], encoding=3)) tag.save(self.filename) - self.aac = AAC(original) + self.aac = AAC(self.original) self.aac_id3 = AAC(self.filename) def tearDown(self): @@ -52,6 +52,11 @@ def test_pprint(self): self.assertEqual(self.aac.pprint(), self.aac_id3.pprint()) self.assertTrue("ADTS" in self.aac.pprint()) + def test_score_no_ext(self): + with open(self.original, "rb") as fileobj: + header = fileobj.read(128) + self.failUnless(AAC.score("empty", fileobj, header)) + class TADIF(TestCase):