diff --git a/distribusi/cli.py b/distribusi/cli.py
index 5421a69..4e03cf8 100644
--- a/distribusi/cli.py
+++ b/distribusi/cli.py
@@ -41,9 +41,9 @@ def build_argparser():
)
parser.add_argument(
- "-c",
- "--captions",
- help="Adds image captions based on EXIF metadata",
+ "-a",
+ "--alttexts",
+ help="Adds file alttext based on same named files",
action="store_true",
)
diff --git a/distribusi/distribusi.py b/distribusi/distribusi.py
index 0d2e23b..302099d 100644
--- a/distribusi/distribusi.py
+++ b/distribusi/distribusi.py
@@ -3,22 +3,23 @@ import os
import magic
from PIL import Image
-from exif import Image as ExifImage
from distribusi.page_template import html_footer, html_head
from distribusi.mappings import CODE_TYPES, FILE_TYPES, SUB_TYPES
MIME_TYPE = magic.Magic(mime=True)
-def caption(image):
+def add_alttext(full_path_image):
try:
- with open(image, "rb") as image_file:
- exif_image = ExifImage(image_file)
- caption = exif_image.communication
+ image_filename_no_ext = os.path.splitext(full_path_image)[0]
+ alttext_filename = f'{image_filename_no_ext}_alttext.txt'
+ if os.path.isfile(alttext_filename):
+ print(f"{image_filename_no_ext} has {alttext_filename}")
+ with open(alttext_filename, 'r') as alttext_file:
+ return alttext_file.read()
except Exception as e:
- print(e)
- caption = ""
- return caption
+ print(f"exception {e} raised while making alttext")
+ return
def thumbnail(full_path_image, name, args):
@@ -63,7 +64,6 @@ def check_distribusi_index(args, index):
"""
check whether a index.html file is generated by distribusi
"""
-
if not args.force:
with open(index, "r") as f:
if '' in f.read():
@@ -114,15 +114,15 @@ def handle_text_files(name, full_path):
def handle_image_files(name, full_path, args):
if args.thumbnail:
- caption = ""
thumbnail_filename = thumbnail(full_path, name, args)
if thumbnail_filename is None:
return
- if args.captions:
- caption = caption(full_path)
- return f""
-
- return FILE_TYPES[type_].format(name, caption)
+ if args.alttexts:
+ image_alttext = add_alttext(full_path)
+ if image_alttext is None:
+ return f''
+ return f''
+ return FILE_TYPES[type_].format(name, image_alttext)
def remove_index_html(root, files):
@@ -169,10 +169,13 @@ def distribusify(args, directory): # noqa
if name.endswith("_thumbnail.jpg"):
continue
+ if name.endswith("_alttext.txt"):
+ continue
+
full_path = os.path.join(root, name)
mime = MIME_TYPE.from_file(full_path)
type_, subtype = mime.split("/")
- caption = name
+ alttext = name
if args.verbose:
print("Found", name, "as", mime)
@@ -185,7 +188,7 @@ def distribusify(args, directory): # noqa
if tag is None:
continue
case _:
- tag = FILE_TYPES[type_].format(name, caption)
+ tag = FILE_TYPES[type_].format(name, alttext)
if subtype in SUB_TYPES:
tag = SUB_TYPES[subtype]
diff --git a/distribusi/mappings.py b/distribusi/mappings.py
index 668ea2e..677d2a3 100644
--- a/distribusi/mappings.py
+++ b/distribusi/mappings.py
@@ -1,7 +1,7 @@
CODE_TYPES = ["x-c", "x-shellscript", "x-python"]
FILE_TYPES = {
- "image": '',
+ "image": '',
"text": '{}',
"video": ("'),
"audio": (''),