|
|
@@ -20,17 +20,26 @@ OUTPUT_DIR_NAME = "output" |
|
|
|
def list_galleries_in(path): |
|
|
|
gallery_dirs = [f for f in os.scandir(path) if f.is_dir()] |
|
|
|
for gallery_dir in gallery_dirs: |
|
|
|
photos = list(list_photos_in(gallery_dir)) |
|
|
|
if len(photos) == 0: |
|
|
|
continue |
|
|
|
photos.sort(key=itemgetter("name")) |
|
|
|
|
|
|
|
metadata = {} |
|
|
|
metadata_path = os.path.join(gallery_dir.path, "metadata.yml") |
|
|
|
if os.path.exists(metadata_path): |
|
|
|
with open(metadata_path, "r") as metadata_file: |
|
|
|
metadata = yaml.load(metadata_file) |
|
|
|
|
|
|
|
private = False |
|
|
|
url = f"{gallery_dir.name}.html" |
|
|
|
output_path = gallery_dir.name |
|
|
|
password = metadata.get("password", None) |
|
|
|
if password: |
|
|
|
private = True |
|
|
|
url = f"{gallery_dir.name}-{password}.html" |
|
|
|
output_path = f"{output_path}-{password}" |
|
|
|
|
|
|
|
photos = list(list_photos_in(gallery_dir, output_path)) |
|
|
|
if len(photos) == 0: |
|
|
|
continue |
|
|
|
photos.sort(key=itemgetter("name")) |
|
|
|
|
|
|
|
# Try to get cover from metadata, if it doesn't exist, take one by |
|
|
|
# default. |
|
|
|
cover_photo = None |
|
|
@@ -44,11 +53,12 @@ def list_galleries_in(path): |
|
|
|
gallery = { |
|
|
|
"name": metadata.get("name", gallery_dir.name), |
|
|
|
"path": gallery_dir.path, |
|
|
|
"output_path": gallery_dir.name, |
|
|
|
"url": f"{gallery_dir.name}.html", |
|
|
|
"output_path": output_path, |
|
|
|
"url": url, |
|
|
|
"num_photos": len(photos), |
|
|
|
"photos": photos, |
|
|
|
"cover_photo": cover_photo, |
|
|
|
"private": private, |
|
|
|
} |
|
|
|
yield gallery |
|
|
|
|
|
|
@@ -61,13 +71,13 @@ def find_photo(photos, photo_name): |
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
def list_photos_in(gallery_dir): |
|
|
|
def list_photos_in(gallery_dir, gallery_output_path): |
|
|
|
photo_files = [ |
|
|
|
f for f in os.scandir(gallery_dir) if re.match(".+\.jpg", f.name, re.I) |
|
|
|
] |
|
|
|
for photo_file in photo_files: |
|
|
|
url = os.path.join(gallery_dir.name, photo_file.name) |
|
|
|
thumb_url = os.path.join(gallery_dir.name, f"thumb_{photo_file.name}") |
|
|
|
url = os.path.join(gallery_output_path, photo_file.name) |
|
|
|
thumb_url = os.path.join(gallery_output_path, f"thumb_{photo_file.name}") |
|
|
|
photo = { |
|
|
|
"name": photo_file.name, |
|
|
|
"path": photo_file.path, |
|
|
@@ -228,7 +238,7 @@ def main(): |
|
|
|
generate_index(output_path, galleries) |
|
|
|
print("✔️") |
|
|
|
for gallery in galleries: |
|
|
|
print(f"Generating {gallery['name']} gallery... ", end="") |
|
|
|
print(f"Generating {gallery['name']} gallery ({gallery['url']})... ", end="") |
|
|
|
generate_gallery(output_path, gallery) |
|
|
|
print("✔️") |
|
|
|
print("Galleries generated 🎉") |