Advertisement
kileko

Untitled

Sep 23rd, 2024
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Check if a file with ASINs is provided
  4. if [ "$#" -ne 1 ]; then
  5. echo "Usage: $0 <asin_list_file>"
  6. exit 1
  7. fi
  8.  
  9. ASIN_FILE=$1
  10.  
  11. # Check if the file exists
  12. if [ ! -f "$ASIN_FILE" ]; then
  13. echo "File not found: $ASIN_FILE"
  14. exit 1
  15. fi
  16.  
  17. # Create a directory to store the downloaded covers
  18. mkdir -p covers
  19.  
  20. # Loop through each ASIN in the file
  21. while IFS= read -r asin; do
  22. # Trim any whitespace
  23. asin=$(echo "$asin" | xargs)
  24.  
  25. # Construct the high-resolution URL
  26. high_res_url="https://ec2.images-amazon.com/images/P/$asin.01.MAIN._SCRM_.jpg"
  27. echo "Attempting to download high-res cover for ASIN: $asin"
  28.  
  29. # Download the high-resolution cover
  30. curl -o "covers/${asin}.jpg" "$high_res_url"
  31.  
  32. # Check if the file exists and get its size
  33. if [ -f "covers/${asin}.jpg" ]; then
  34. file_size=$(wc -c < "covers/${asin}.jpg") # Get file size in bytes
  35.  
  36. # Check for invalid file sizes
  37. if [ "$file_size" -eq 43 ] || [ "$file_size" -eq 36 ]; then
  38. echo "High-res file is invalid (size: $file_size bytes), attempting lower-res."
  39.  
  40. # Construct the lower-resolution URL
  41. low_res_url="https://images-na.ssl-images-amazon.com/images/P/$asin._SX1600_.jpg"
  42. curl -o "covers/${asin}.jpg" "$low_res_url"
  43. fi
  44. else
  45. echo "Failed to download high-res image for ASIN: $asin"
  46. fi
  47. done < "$ASIN_FILE"
  48.  
  49. echo "Download complete. Covers saved in the 'covers' directory."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement