#!/bin/bash # Replace with the URL of your JSON file JSON_URL="https://raw.githubusercontent.com/yuhonas/free-exercise-db/main/dist/exercises.json" # Directory to save images and GIFs SAVE_DIR="exercise_images" # Create the main directory if it doesn't exist mkdir -p "$SAVE_DIR" # Fetch JSON data and iterate through exercises curl -s "$JSON_URL" | jq -c '.[]' | while read -r exercise; do # Extract exercise information from JSON name=$(echo "$exercise" | jq -r '.name') images=($(echo "$exercise" | jq -r '.images[]')) # Create a subdirectory for this exercise if it doesn't exist modified_name="${name//_/ -}" # Replace underscores with hyphens modified_name="${modified_name//\//-}" # Replace slashes with hyphens exercise_dir="$SAVE_DIR/$modified_name" if [ ! -d "$exercise_dir" ]; then mkdir -p "$exercise_dir" # Download images and create GIF for image in "${images[@]}"; do image_url="https://raw.githubusercontent.com/yuhonas/free-exercise-db/main/exercises/$image" image_filename=$(basename "$image") # Replace underscores with hyphens in the filename modified_image_filename="${image_filename//_/ -}" modified_image_filename="${modified_image_filename//\//-}" # Replace slashes with hyphens # Download the image to the exercise-specific directory with the modified filename wget -q "$image_url" -O "$exercise_dir/$modified_image_filename" done # Create a GIF for the exercise gif_output="$exercise_dir/$modified_name.gif" convert -delay 100 -loop 0 "${exercise_dir}/*" "$gif_output" fi done