Passed
Branch master (929f74)
by Cyb3r
01:56
created

MetaStalk.utils.heic_parse.check_heic()   A

Complexity

Conditions 1

Size

Total Lines 8
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 0
dl 0
loc 8
ccs 2
cts 2
cp 1
crap 1
rs 10
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