Skip to content

Instantly share code, notes, and snippets.

@chapmanjacobd
Last active May 9, 2024 00:50
Show Gist options
  • Select an option

  • Save chapmanjacobd/b8c0f14c67452fb9c541c6b66607c3d7 to your computer and use it in GitHub Desktop.

Select an option

Save chapmanjacobd/b8c0f14c67452fb9c541c6b66607c3d7 to your computer and use it in GitHub Desktop.
import os
import subprocess
from xklb.mediafiles import process_image
from xklb.utils import objects, web
COMICS = [
{
"title": "#1: Training Day",
"writer": "Ben Paddon",
"artist": "JjAR",
"pages": [
{
"file": "01-00.png",
"writer": "Oh, this cover...",
"artist": "",
},
{
"file": "01-01.png",
"writer": "Many years ago...",
"artist": "",
},
...
},
]
BASE_URL = "https://jumpleads.zone/comic/"
def download_image(url, file_path):
response = web.requests_session().get(url)
response.raise_for_status()
with open(file_path, 'wb') as file:
file.write(response.content)
def embed_description(file_path, text):
subprocess.run(['exiftool', '-overwrite_original', '-XMP:Description={}'.format(text), file_path])
def main():
for comic in COMICS:
comic_dir = os.path.join('.', comic['title'])
os.makedirs(comic_dir, exist_ok=True)
for page in comic['pages']:
file_path = os.path.join(comic_dir, page['file'])
download_image(BASE_URL + page['file'], file_path)
file_path = process_image.process_path(objects.NoneSpace(max_image_width=2400, max_image_height=2400), file_path)
descriptions = []
if page.get('writer'):
descriptions.append("Writer's Notes: " + page['writer'])
if page.get('artist'):
descriptions.append("Artist's Notes: " + page['artist'])
if descriptions:
description = '\n\n'.join(descriptions)
embed_description(file_path, description)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment