Bahai.media File Downloader

Use this tool to generate a download manifest for specific image categories. This allows you to download full-resolution images while preserving the category structure (bahai.media categories become folders and sub-folders on your computer).

Step 1: Select Categories

Search for categories and check the boxes for the ones you want. (Press the icon to show sub-categories)

  • Start typing above to find categories.
0 categories selected

Success! Found 0 images.

Download manifest.json

Step 2: Run the Downloader

Save the code below as download_images.py in the same folder as your media_manifest.json and run it.

import json
import os
import requests
import shutil

# Configuration
MANIFEST_FILE = 'media_manifest.json'

def process_file(url, path, file_hash, seen_hashes):
    os.makedirs(os.path.dirname(path), exist_ok=True)
    if file_hash in seen_hashes:
        existing_path = seen_hashes[file_hash]
        if not os.path.exists(path):
            try:
                print(f"Linking: {path} -> {existing_path}")
                os.link(existing_path, path)
            except OSError:
                print(f"Copying local: {path}")
                shutil.copyfile(existing_path, path)
        return

    if os.path.exists(path):
        print(f"Skipping (exists): {path}")
        if file_hash: seen_hashes[file_hash] = path
        return

    print(f"Downloading: {path}")
    try:
        r = requests.get(url, stream=True)
        r.raise_for_status()
        with open(path, 'wb') as f:
            for chunk in r.iter_content(chunk_size=8192):
                f.write(chunk)
        if file_hash: seen_hashes[file_hash] = path
    except Exception as e:
        print(f"Error downloading {path}: {e}")

def main():
    if not os.path.exists(MANIFEST_FILE):
        print(f"Error: {MANIFEST_FILE} not found.")
        return
    with open(MANIFEST_FILE, 'r', encoding='utf-8') as f:
        data = json.load(f)
    print(f"Starting download of {data['count']} files...")
    seen_hashes = {}
    for file in data['files']:
        process_file(file['url'], file['path'], file.get('hash'), seen_hashes)
    print("\nDownload complete.")

if __name__ == "__main__":
    main()