Max Kaye's Site

Max's Microblog

Replies

TOC
`giphy-dl` script (in the style of youtube-dl for giphy)

make sure to chmod +x it and should just work (provided you have curl and extended grep support)

#!/usr/bin/env bash

FILENAME="$1"
GIPHY_CODE_OR_URL="$2"

if [ -z "$FILENAME" ] || [ -z "$2" ]; then
  echo "usage: $0 GIF_NAME GIPHY_URL_OR_CODE"
  exit 1
fi

CODE_FROM_URL=$(echo "$GIPHY_CODE_OR_URL" | egrep -o 'media\/([A-Za-z0-9]{12,})\/giphy' | cut -d '/' -f 2)

if [ -z "$CODE_FROM_URL" ]; then
  CODE_FROM_URL=$(echo "$GIPHY_CODE_OR_URL" | egrep -o '[A-Za-z0-9]{12,}')
fi

echo "saving to: $FILENAME.mp4"
echo "dling gif from: $GIPHY_CODE_OR_URL"
echo "giphy code: $CODE_FROM_URL"

curl "https://media.giphy.com/media/$CODE_FROM_URL/giphy.mp4" --output "$FILENAME.mp4"

xdg-open "$FILENAME.mp4" || true