Browse Source

Support metadata for galleries

Name and cover can now be changed.
master
Marien Fressinaud 5 years ago
parent
commit
9a69dd9fe8

+ 28
- 4
boop.py View File

@@ -3,6 +3,7 @@
import os
import shutil
import re
import yaml

from operator import itemgetter

@@ -22,21 +23,44 @@ def list_galleries_in(path):
photos = list(list_photos_in(gallery_dir))
if len(photos) == 0:
continue

photos.sort(key=itemgetter("name"))
cover_index = (len(gallery_dir.name) + 42) % len(photos)

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)

# Try to get cover from metadata, if it doesn't exist, take one by
# default.
cover_photo = None
cover_name = metadata.get("cover")
if cover_name:
cover_photo = find_photo(photos, cover_name)
if cover_photo is None:
cover_index = (len(gallery_dir.name) + 42) % len(photos)
cover_photo = photos[cover_index]

gallery = {
"name": gallery_dir.name,
"name": metadata.get("name", gallery_dir.name),
"path": gallery_dir.path,
"output_path": gallery_dir.name,
"url": f"{gallery_dir.name}.html",
"num_photos": len(photos),
"photos": photos,
"cover_photo": photos[cover_index],
"cover_photo": cover_photo,
}
yield gallery


def find_photo(photos, photo_name):
for photo in photos:
if photo["name"] == photo_name:
return photo
else:
return None


def list_photos_in(gallery_dir):
photo_files = [
f for f in os.scandir(gallery_dir) if re.match(".+\.jpg", f.name, re.I)

+ 3
- 0
photos/2013_08_2013_12_Trondheim/metadata.yml View File

@@ -0,0 +1,3 @@
---
name: "3. Trondheim"
cover: "DSC00179.jpg"

+ 0
- 0
photos/2013_08_Bergen/.keep View File


+ 3
- 0
photos/2013_08_Bergen/metadata.yml View File

@@ -0,0 +1,3 @@
---
name: "1. Bergen"
cover: "DSC00100.jpg"

+ 0
- 0
photos/2013_08_Trondheim/.keep View File


+ 0
- 0
photos/2013_08_hiking_five_fifty_two/.keep View File


+ 3
- 0
photos/2013_08_hiking_five_fifty_two/metadata.yml View File

@@ -0,0 +1,3 @@
---
name: "2. Hiking five fifty-two"
cover: "DSC00133.jpg"

+ 0
- 0
photos/2013_09_5_hours_walk/.keep View File


+ 3
- 0
photos/2013_09_5_hours_walk/metadata.yml View File

@@ -0,0 +1,3 @@
---
name: "4. 5 hours walk"
cover: "DSC00302.jpg"

+ 0
- 0
photos/2013_10_Trondheim/.keep View File


+ 0
- 0
photos/2013_12_Prague/.keep View File


+ 3
- 0
photos/2013_12_Prague/metadata.yml View File

@@ -0,0 +1,3 @@
---
name: "5. Prague"
cover: "DSC00425.jpg"

+ 0
- 0
photos/2013_12_campus/.keep View File


+ 0
- 0
photos/2015_03-2015_04-Tour_de_France/.keep View File


+ 3
- 0
photos/2015_03-2015_04-Tour_de_France/metadata.yml View File

@@ -0,0 +1,3 @@
---
name: "6. Tour de France"
cover: "07_Blois_02542.jpg"

+ 0
- 0
photos/2015_05-2015_06_Tour_Europe/.keep View File


+ 3
- 0
photos/2015_05-2015_06_Tour_Europe/metadata.yml View File

@@ -0,0 +1,3 @@
---
name: "7. Tour d’Europe"
cover: "06_Tchou_tchou_03411.jpg"

+ 0
- 0
photos/2017-05_2017-06_Royaume_Uni/.keep View File


+ 3
- 0
photos/2017-05_2017-06_Royaume_Uni/metadata.yml View File

@@ -0,0 +1,3 @@
---
name: "8. Royaume-Uni"
cover: "DSC03695.JPG"

+ 0
- 0
photos/2018-06_Moucheraclette/.keep View File


+ 3
- 0
photos/2018-06_Moucheraclette/metadata.yml View File

@@ -0,0 +1,3 @@
---
name: "9. Moucheraclette"
cover: "DSC04034.JPG"

+ 1
- 0
requirements.txt View File

@@ -1,2 +1,3 @@
Jinja2
Pillow
pyyaml

Loading…
Cancel
Save