]> jfr.im git - yt-dlp.git/blame - yt_dlp/compat/imghdr.py
[ffmpeg] Set `ffmpeg_location` in a contextvar
[yt-dlp.git] / yt_dlp / compat / imghdr.py
CommitLineData
5792c950 1tests = {
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}
6
7
8def what(path):
9 """Detect format of image (Currently supports jpeg, png, webp only)
10 Ref: https://github.com/python/cpython/blob/3.10/Lib/imghdr.py
11 """
12 with open(path, 'rb') as f:
13 head = f.read(12)
14 return next((type_ for type_, test in tests.items() if test(head)), None)