Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Image
- **psd** - ``image/vnd.adobe.photoshop``
- **ico** - ``image/x-icon``
- **heic** - ``image/heic``
- **avif** - ``image/avif``

Video
^^^^^
Expand Down
1 change: 1 addition & 0 deletions filetype/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
image.Ico(),
image.Heic(),
image.Dcm(),
image.Avif(),
)

# Supported video types
Expand Down
25 changes: 25 additions & 0 deletions filetype/types/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,28 @@ def __init__(self):
def match(self, buf):
return buf[:10] == bytearray([0x67, 0x69, 0x6d, 0x70, 0x20,
0x78, 0x63, 0x66, 0x20, 0x76])


class Avif(IsoBmff):
"""
Implements the AVIF image type matcher.
"""
MIME = 'image/avif'
EXTENSION = 'avif'

def __init__(self):
super(Avif, self).__init__(
mime=Avif.MIME,
extension=Avif.EXTENSION
)

def match(self, buf):
if not self._is_isobmff(buf):
return False

major_brand, minor_version, compatible_brands = self._get_ftyp(buf)
if major_brand == 'avif':
return True
if major_brand in ['mif1', 'msf1'] and 'avif' in compatible_brands:
return True
return False
Binary file added tests/fixtures/sample.avif
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ def test_guess_heic(self):
self.assertEqual(kind.mime, 'image/heic')
self.assertEqual(kind.extension, 'heic')

def test_guess_avif(self):
kind = filetype.guess(FIXTURES + '/sample.avif')
self.assertTrue(kind is not None)
self.assertEqual(kind.mime, 'image/avif')
self.assertEqual(kind.extension, 'avif')

def test_guess_mp4(self):
kind = filetype.guess(FIXTURES + '/sample.mp4')
self.assertTrue(kind is not None)
Expand Down