Transforms a PostgreSQL gallery2 database into three forms:
- a static HTML site
- a JSON file representing all artwork on a flat structure
- a JSON file representing all artwork, structured around albums
Written to assist in rescuing a friend's site contents, so not intended as suitable for any generic need - use at your own risk.
~ mrbarge
Install dependencies (notably psycopg2
for interaction with PostgreSQL):
pip install -r requirements.txt
Prepare a configuration file config.ini
containing database credentials and site
directories (used only for forming page links, only html_dir
needs to exist as the place
where output files are written):
[default]
DB_NAME=tv_fanart_gallery
DB_USER=user
DB_PASS=pass
DB_HOST=127.0.0.1
[site]
html_dir=.
art_dir=artwork
thumbs_dir=thumbs
Flat JSON representation of all artwork. The albums
key is a ordered list of the
album hierachy in which the artwork resides.
{
"art": [
{
"id": 131,
"title": "artwork title",
"summary": "artwork summary",
"description": "artwork desc",
"filename": "artwork1.jpg",
"filepath": "albumdir/artwork1.jpg",
"filesize": 100000,
"mimetype": "image/jpeg",
"owner": {
"username": "user",
"fullname": "user",
"email": "user@example.com"
},
"albums": [
{
"name": "root album",
"dir_name": "."
},
{
"name": "sub album",
"dir_name": "sub_album"
}
]
},
]
}
JSON representation of all artwork, structured in order of containing album.
{
"albums": [
{
"id": 1,
"title": "Album name",
"filename": "albumdir/",
"filepath": "",
"owner": {
"username": "user",
"fullname": "user",
"email": "user@example.com"
},
"art": [
# all artwork at this album level is listed here
{
"id": 131,
"title": "artwork title",
"summary": "artwork summary",
"description": "artwork desc",
"filename": "artwork1.jpg",
"filepath": "albumdir/artwork1.jpg",
"filesize": 100000,
"mimetype": "image/jpeg",
"owner": {
"username": "user",
"fullname": "user",
"email": "user@example.com"
},
}
],
"children": [
# child albums are nested here
]
}
]
}
HTML files are generated in the directory specified by the html_dir
configuration in
the config file.
Links to thumbnails and artwork are based on the values specified by thumbs_dir
and
art_dir
respectively. Thumbnails are not generated by the script itself.