diff --git a/README.md b/README.md index 91157a1..752f093 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Mirva A tool to create a web gallery from a single folder of images. +Also .mp4 files are included in the gallery ## Installation diff --git a/mirva/__init__.py b/mirva/__init__.py index 617c9f3..2c50999 100644 --- a/mirva/__init__.py +++ b/mirva/__init__.py @@ -1,4 +1,4 @@ -__version__ = "20210821.0" +__version__ = "20210831.0" def get_version(): diff --git a/mirva/mirva.py b/mirva/mirva.py index 3273d72..a6e03cf 100755 --- a/mirva/mirva.py +++ b/mirva/mirva.py @@ -16,6 +16,9 @@ class Mirva: ) self.resource_dir = ".mirva" self.config_file = os.path.join(self.resource_dir, "config.cfg") + self.config_backup = os.path.join(self.resource_dir, "config.cfg.bkp") + self.image_match = re.compile(".*\.jpg$|.*\.jpeg$|.*\.png$|.*\.gif$|.*\.tif$", re.I) + self.video_match = re.compile(".*\.mp4$", re.I) self.get_options() os.chdir(self.options.folder) self.write_resources() @@ -24,8 +27,9 @@ class Mirva: self.create_config() print("Config created: Exiting without gallery creation. Check config first.") return - self.create_config() self.get_config() + if self.options.exif: + self.append_exif() self.create_posts() self.write_index() self.write_mediums() @@ -33,11 +37,11 @@ class Mirva: def create_config(self): - config = configparser.ConfigParser() - config.read(self.config_file) + self.config = configparser.ConfigParser() + self.config.read(self.config_file) config_changed = False - if not "SITE" in config: - config["SITE"] = { + if not "SITE" in self.config: + self.config["SITE"] = { "title": "", "sub_title": "", "intro": "", @@ -46,20 +50,14 @@ class Mirva: config_changed = True for f in self.file_list: - if not f in config: + if not f in self.config: title, _ = os.path.splitext(f) title = title.replace("_", " ") - config[f] = {"title": title, "description": ""} + self.config[f] = {"title": title, "description": ""} config_changed = True if config_changed: - print( - "Modified config: {}".format( - os.path.join(self.options.folder, self.config_file) - ) - ) - with open(self.config_file, "wt") as fp: - config.write(fp) + self.write_config() def create_posts(self): @@ -75,13 +73,28 @@ class Mirva: self.config = configparser.ConfigParser() self.config.read(self.config_file) + def write_config(self): + print( + "Modified config: {}".format( + os.path.join(self.options.folder, self.config_file) + ) + ) + if os.path.exists(self.config_file): + with open(self.config_file, "rt") as reader: + with open(self.config_backup, "wt") as writer: + writer.write(reader.read()) + + with open(self.config_file, "wt") as fp: + self.config.write(fp) + + def get_files(self): image_match = re.compile(".*\.jpg$|.*\.jpeg$|.*\.png$|.*\.gif$|.*\.tif$", re.I) files = [] for f in sorted(os.listdir(".")): if f.startswith("."): continue - if not image_match.match(f): + if not (self.image_match.match(f) or self.video_match.match(f)): continue files.append(f) return files @@ -95,7 +108,7 @@ class Mirva: ) # parser.add_argument("-v", default=False, action="store_true") parser.add_argument( - "--config", default=False, action="store_true", help="Write config and exit" + "--config", default=False, action="store_true", help="Write config and exit. Required if more images are added." ) parser.add_argument( "--force", @@ -103,6 +116,12 @@ class Mirva: action="store_true", help="Force regeneration of middle sized images", ) + parser.add_argument( + "--exif", + default=False, + action="store_true", + help="Append EXIF information to image descriptions", + ) parser.add_argument( "--version", action="version", @@ -218,6 +237,22 @@ function create_button(direction, to) {{ def get_post(self, image, title, content): + if self.video_match.match(image): + return """ +
""".format( + image=image, title=title, content=content + ) + return """