Self-hatred

[Bash] Download an Imgur album

If I see one more rectangle this morning, I will scream. Instead I am writing a very simple Imgur gallery downloader for a friend, using extant Bash utilities.

#!/bin/bash
wget $1
LIST=files.list
mv $(ls -1 .) $LIST 
# Strip the file down to the actual image links.
cat $LIST | grep href | grep jpg | grep -v rel > $LIST
# Could be a one-liner, but I like neatness.
cat $LIST | sed 's/<a href\="//g' | sed 's/">//g' > $LIST
# Download the files.
wget -i $LIST

In order:

  1. You invoke it with fetch $URL.
  2. The script uses grep to strip the file down to a raw list of relevant hyperlinks.
  3. sed strips the formatting.
  4. wget fetches the remaining files.

Categorised as: linux, programming


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>