Last active
May 4, 2021 02:08
-
-
Save Cryptkeeper/bfc1ebed83c06f940115cd3324278871 to your computer and use it in GitHub Desktop.
Download and timestamp all images from a given eBay listing URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
function _ebaydl_find_hashes { | |
local URL="$1" | |
local DIR="$2" | |
local SIZES=(64 500 1600) | |
curl --silent "$URL" | grep -E -o "https?://i.ebayimg.com/images/g/[0-9A-Za-z~-]{15,16}/s-l[0-9]{2,}.[a-z]{3,4}" | sort | cut -d"/" -f6 | uniq | while read -r HASH | |
do | |
echo "$HASH" | |
for SIZE in ${SIZES[@]} | |
do | |
local IMG_URL="https://i.ebayimg.com/images/g/$HASH/s-l$SIZE.jpg" | |
wget --quiet --output-document "${DIR}/${HASH}_${SIZE}.jpg" "$IMG_URL" | |
done | |
done | |
} | |
function _ebaydl_stamp { | |
local URL="$1" | |
local NAME="$2" | |
local ID="$3" | |
local DIR="$4" | |
local DATE=$(date) | |
echo "url = $URL\nname = $NAME\nid = $ID\ndate = $DATE" > "$DIR/stamp.txt" | |
} | |
function _ebaydl_get_name { | |
local URL="$1" | |
NAME=$(curl --silent "$URL" | grep -E -o "(<title>).+(<\/title>)") | |
NAME=${NAME#"<title>"} # trim prefix | |
NAME=${NAME%" | eBay</title>"} # trim suffix | |
NAME=$(echo $NAME | xargs) # trim whitespace | |
NAME=$(echo $NAME | sed -e 's/\//_/g' | sed -e 's/&/_/g') # strip symbols | |
} | |
function ebaydl { | |
URL="$1" | |
_ebaydl_get_name "$URL" | |
echo "name: $NAME" | |
ID=$(echo "$URL" | cut -d"/" -f5 | cut -d"?" -f1) | |
echo "id: $ID" | |
DIR="${NAME}_${ID}" | |
mkdir "$DIR" | |
_ebaydl_find_hashes "$URL" "$DIR" | |
_ebaydl_stamp "$URL" "$NAME" "$ID" "$DIR" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment