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

MetaStalk.utils.heic_parse   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 41
ccs 9
cts 18
cp 0.5
rs 10
c 0
b 0
f 0
wmc 5

2 Functions

Rating   Name   Duplication   Size   Complexity  
A check_heic() 0 8 1
A parse_heic() 0 15 4
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