Skip to content

Instantly share code, notes, and snippets.

@nsapa
Created April 19, 2022 01:31
Show Gist options
  • Save nsapa/a13c24ef314f850210458833b06703ed to your computer and use it in GitHub Desktop.
Save nsapa/a13c24ef314f850210458833b06703ed to your computer and use it in GitHub Desktop.
Convert webp thumbnail to jpg on IA item
#!/bin/bash
set -o errexit # abort on nonzero exitstatus
set -o nounset # abort on unbound variable
set -o pipefail # don't hide errors within pipes
set -x
URL=${1}
TEMP_DIR=$(mktemp -d)
ITEM_NAME=$(echo $URL | cut -d/ -f5)
WEBP_FILENAME=$(ia metadata $ITEM_NAME | jq .files[].name | grep .webp)
if [ $(echo $WEBP_FILENAME | grep \" | wc -l) -eq 0 ]; then
echo No .webp in this item
exit
fi
WEBP_FILENAME=$(echo $WEBP_FILENAME | sed -e 's/"//g')
pushd "${TEMP_DIR}"
wget https://archive.org/download/${ITEM_NAME}/${WEBP_FILENAME}
convert -- ${WEBP_FILENAME} ${ITEM_NAME}.jpg
ia upload ${ITEM_NAME} ${ITEM_NAME}.jpg
rm -- ${WEBP_FILENAME} ${ITEM_NAME}.jpg
popd
rmdir $TEMP_DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment