Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Check if a file with ASINs is provided
- if [ "$#" -ne 1 ]; then
- echo "Usage: $0 <asin_list_file>"
- exit 1
- fi
- ASIN_FILE=$1
- # Check if the file exists
- if [ ! -f "$ASIN_FILE" ]; then
- echo "File not found: $ASIN_FILE"
- exit 1
- fi
- # Create a directory to store the downloaded covers
- mkdir -p covers
- # Loop through each ASIN in the file
- while IFS= read -r asin; do
- # Trim any whitespace
- asin=$(echo "$asin" | xargs)
- # Construct the high-resolution URL
- high_res_url="https://ec2.images-amazon.com/images/P/$asin.01.MAIN._SCRM_.jpg"
- echo "Attempting to download high-res cover for ASIN: $asin"
- # Download the high-resolution cover
- curl -o "covers/${asin}.jpg" "$high_res_url"
- # Check if the file exists and get its size
- if [ -f "covers/${asin}.jpg" ]; then
- file_size=$(wc -c < "covers/${asin}.jpg") # Get file size in bytes
- # Check for invalid file sizes
- if [ "$file_size" -eq 43 ] || [ "$file_size" -eq 36 ]; then
- echo "High-res file is invalid (size: $file_size bytes), attempting lower-res."
- # Construct the lower-resolution URL
- low_res_url="https://images-na.ssl-images-amazon.com/images/P/$asin._SX1600_.jpg"
- curl -o "covers/${asin}.jpg" "$low_res_url"
- fi
- else
- echo "Failed to download high-res image for ASIN: $asin"
- fi
- done < "$ASIN_FILE"
- echo "Download complete. Covers saved in the 'covers' directory."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement