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,
}