mapillary_downloader

Mapillary data downloader.

mapillary_downloader.webp_converter

WebP image conversion utilities.

check_cwebp_available

def check_cwebp_available()

Check if cwebp binary is available.

Returns:

convert_to_webp

def convert_to_webp(jpg_path, output_path=None, delete_original=True)

Convert a JPG image to WebP format, preserving EXIF metadata.

Arguments:

Returns:

Path object to the new WebP file, or None if conversion failed

mapillary_downloader.exif_writer

EXIF metadata writer for Mapillary images.

decimal_to_dms

def decimal_to_dms(decimal)

Convert decimal degrees to degrees, minutes, seconds format for EXIF.

Arguments:

Returns:

Tuple of ((degrees, 1), (minutes, 1), (seconds, 100)) as rational numbers

timestamp_to_exif_datetime

def timestamp_to_exif_datetime(timestamp)

Convert Unix timestamp to EXIF datetime string.

Arguments:

Returns:

String in format “YYYY:MM:DD HH:MM:SS”

write_exif_to_image

def write_exif_to_image(image_path, metadata)

Write EXIF metadata from Mapillary API to downloaded image.

Arguments:

Returns:

True if successful, False otherwise

mapillary_downloader.utils

Utility functions for formatting and display.

format_size

def format_size(bytes_count)

Format bytes as human-readable size.

Arguments:

Returns:

Formatted string (e.g. “1.23 GB”, “456.78 MB”)

format_time

def format_time(seconds)

Format seconds as human-readable time.

Arguments:

Returns:

Formatted string (e.g. “2h 15m”, “45m 30s”, “30s”)

mapillary_downloader.tar_sequences

Tar sequence directories for efficient Internet Archive uploads.

tar_sequence_directories

def tar_sequence_directories(collection_dir)

Tar all sequence directories in a collection for faster IA uploads.

Arguments:

Returns:

Tuple of (tarred_count, total_files_tarred)

mapillary_downloader.ia_check

Check if collections exist on Internet Archive.

check_ia_exists

def check_ia_exists(collection_name)

Check if a collection exists on Internet Archive.

Arguments:

Returns:

Boolean indicating if the collection exists on IA

mapillary_downloader.__main__

CLI entry point.

main

def main()

Main CLI entry point.

mapillary_downloader.downloader

Main downloader logic.

get_cache_dir

def get_cache_dir()

Get XDG cache directory for staging downloads.

Returns:

Path to cache directory for mapillary_downloader

MapillaryDownloader Objects

class MapillaryDownloader()

Handles downloading Mapillary data for a user.

__init__

def __init__(client,
             output_dir,
             username=None,
             quality=None,
             workers=None,
             tar_sequences=True,
             convert_webp=False,
             check_ia=True)

Initialize the downloader.

Arguments:

download_user_data

def download_user_data(bbox=None, convert_webp=False)

Download all images for a user.

Arguments:

mapillary_downloader.worker

Worker process for parallel image download and conversion.

download_and_convert_image

def download_and_convert_image(image_data, output_dir, quality, convert_webp,
                               access_token)

Download and optionally convert a single image.

This function is designed to run in a worker process.

Arguments:

Returns:

Tuple of (image_id, bytes_downloaded, success, error_msg)

mapillary_downloader.logging_config

Logging configuration with colored output for TTY.

ColoredFormatter Objects

class ColoredFormatter(logging.Formatter)

Formatter that adds color to log levels when output is a TTY.

__init__

def __init__(fmt=None, datefmt=None, use_color=True)

Initialize the formatter.

Arguments:

format

def format(record)

Format the log record with colors if appropriate.

Arguments:

Returns:

Formatted log string

setup_logging

def setup_logging(level=logging.INFO)

Set up logging with timestamps and colored output.

Arguments:

add_file_handler

def add_file_handler(log_file, level=logging.INFO)

Add a file handler to the logger for archival.

Arguments:

mapillary_downloader.ia_meta

Internet Archive metadata generation for Mapillary collections.

parse_collection_name

def parse_collection_name(directory)

Parse username and quality from directory name.

Arguments:

Returns:

Tuple of (username, quality) or (None, None) if parsing fails

get_date_range

def get_date_range(metadata_file)

Get first and last captured_at dates from metadata.jsonl.gz.

Arguments:

Returns:

Tuple of (first_date, last_date) as ISO format strings, or (None, None)

count_images

def count_images(metadata_file)

Count number of images in metadata.jsonl.gz.

Arguments:

Returns:

Number of images

write_meta_tag

def write_meta_tag(meta_dir, tag, values)

Write metadata tag files in rip format.

Arguments:

generate_ia_metadata

def generate_ia_metadata(collection_dir)

Generate Internet Archive metadata for a Mapillary collection.

Arguments:

Returns:

True if successful, False otherwise

mapillary_downloader.client

Mapillary API client.

MapillaryClient Objects

class MapillaryClient()

Client for interacting with Mapillary API v4.

__init__

def __init__(access_token)

Initialize the client with an access token.

Arguments:

get_user_images

def get_user_images(username, bbox=None, limit=2000)

Get images uploaded by a specific user.

Arguments:

Yields:

Image data dictionaries

download_image

def download_image(image_url, output_path)

Download an image from a URL.

Arguments:

Returns:

Number of bytes downloaded if successful, 0 otherwise