Total Complexity | 5 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Coverage | 50% |
Changes | 0 |
1 | """heic_parse |
||
2 | --- |
||
3 | |||
4 | Deals with heic and heif exif |
||
5 | """ |
||
6 | 1 | import io |
|
7 | 1 | import exifread |
|
8 | |||
9 | 1 | try: |
|
10 | 1 | import pyheif |
|
11 | heic_enabled = True |
||
12 | 1 | except ImportError: |
|
13 | 1 | heic_enabled = False |
|
14 | |||
15 | |||
16 | 1 | def check_heic(): |
|
17 | """check_heic |
||
18 | --- |
||
19 | |||
20 | Returns: |
||
21 | [bool] -- Whether or not pyheif was imported |
||
22 | """ |
||
23 | 1 | return heic_enabled |
|
24 | |||
25 | |||
26 | 1 | def parse_heic(item: str) -> dict: |
|
27 | """parse_heic |
||
28 | --- |
||
29 | The parses heic files |
||
30 | """ |
||
31 | heif_file = pyheif.read_heif(item) |
||
32 | if not heif_file.metadata: |
||
33 | return {} |
||
34 | for metadata in heif_file.metadata: |
||
35 | |||
36 | if metadata['type'] == 'Exif': |
||
37 | fstream = io.BytesIO(metadata['data'][6:]) |
||
38 | |||
39 | return exifread.process_file(fstream) |
||
40 | return {} |
||
41 |