Add ALT text to images

Correct static methods
Tidy up code
This commit is contained in:
Michał Gdula 2023-03-11 22:14:03 +00:00
parent e192554a0b
commit 3ee287d6e3
23 changed files with 427 additions and 430 deletions

View file

@ -1,5 +1,5 @@
"""
OnlyLegs - Metatada Parser
OnlyLegs - Metadata Parser
Parse metadata from images if available
otherwise get some basic information from the file
"""
@ -11,6 +11,7 @@ from PIL.ExifTags import TAGS
from .helpers import *
from .mapping import *
class Metadata:
"""
Metadata parser
@ -53,7 +54,8 @@ class Metadata:
return None
return self.format_data(self.encoded)
def format_data(self, encoded_exif): # pylint: disable=R0912 # For now, this is fine
@staticmethod
def format_data(encoded_exif):
"""
Formats the data into a dictionary
"""
@ -66,15 +68,15 @@ class Metadata:
# Thanks chatGPT xP
for key, value in encoded_exif.items():
for mapping_name, mapping in EXIF_MAPPING:
if key in mapping:
if len(mapping[key]) == 2:
exif[mapping_name][mapping[key][0]] = {
for mapping_name, mapping_val in EXIF_MAPPING:
if key in mapping_val:
if len(mapping_val[key]) == 2:
exif[mapping_name][mapping_val[key][0]] = {
'raw': value,
'formatted': getattr(helpers, mapping[key][1])(value),
'formatted': getattr(helpers, mapping_val[key][1])(value),
}
else:
exif[mapping_name][mapping[key][0]] = {
exif[mapping_name][mapping_val[key][0]] = {
'raw': value,
}

View file

@ -4,6 +4,7 @@ Metadata formatting helpers
"""
from datetime import datetime
def human_size(value):
"""
Formats the size of a file in a human readable format
@ -276,7 +277,10 @@ def lens_specification(value):
"""
Maps the value of the lens specification to a human readable format
"""
return str(value[0] / value[1]) + 'mm - ' + str(value[2] / value[3]) + 'mm'
try:
return str(value[0] / value[1]) + 'mm - ' + str(value[2] / value[3]) + 'mm'
except Exception as err:
return None
def compression_type(value):

View file

@ -61,4 +61,9 @@ FILE_MAPPING = {
'RatingPercent': ['Rating Percent', 'rating_percent'],
}
EXIF_MAPPING = [('Photographer', PHOTOGRAHER_MAPPING),('Camera', CAMERA_MAPPING),('Software', SOFTWARE_MAPPING),('File', FILE_MAPPING)]
EXIF_MAPPING = [
('Photographer', PHOTOGRAHER_MAPPING),
('Camera', CAMERA_MAPPING),
('Software', SOFTWARE_MAPPING),
('File', FILE_MAPPING)
]