]>
jfr.im git - yt-dlp.git/blob - yt_dlp/compat/imghdr.py
2 'webp': lambda h
: h
[0:4] == b
'RIFF' and h
[8:] == b
'WEBP',
3 'png': lambda h
: h
[:8] == b
'\211PNG\r\n\032\n',
4 'jpeg': lambda h
: h
[6:10] in (b
'JFIF', b
'Exif'),
5 'gif': lambda h
: h
[:6] in (b
'GIF87a', b
'GIF89a'),
9 def what(file=None, h
=None):
10 """Detect format of image (Currently supports jpeg, png, webp, gif only)
11 Ref: https://github.com/python/cpython/blob/3.10/Lib/imghdr.py
14 with open(file, 'rb') as f
:
16 return next((type_
for type_
, test
in tests
.items() if test(h
)), None)