Passed
Push — master ( 929827...929f74 )
by Cyb3r
02:12
created

MetaStalk.utils.heic_parse.parse_heic()   A

Complexity

Conditions 4

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 15.2377

Importance

Changes 0
Metric Value
cc 4
eloc 9
nop 1
dl 0
loc 15
ccs 1
cts 9
cp 0.1111
crap 15.2377
rs 9.95
c 0
b 0
f 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