Skip to content

Commit

Permalink
retab
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex committed Jan 24, 2016
1 parent df7d48b commit 23f2552
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
74 changes: 37 additions & 37 deletions imgur.sh
@@ -1,64 +1,64 @@
#!/bin/bash

#############################################################
# Script to download all images in an imgur.com album
# to disk.
# USAGE: ./imgur.sh http://imgur.com/a/id
# Script to download all images in an imgur.com album
# to disk.
# USAGE: ./imgur.sh http://imgur.com/a/id
#
#############################################################

url=('')
ass=".tmp"

usage(){
echo "USAGE: ./imgur.sh http://imgur.com/a/id"
echo "USAGE: ./imgur.sh http://imgur.com/a/id"
}

url=$1

if [[ -z $url ]]
then
usage
exit 1
usage
exit 1
fi

if [[ "$url" =~ "imgur.com/a/" ]]
then
curl -s $url > $ass
title=$(awk -F \" '/data-cover/ {print $6; exit}' $ass)
if [[ -z $title ]]
then
title=$(awk -F \" '/data-cover/ {print $8}' $ass)
fi
curl -s $url > $ass
title=$(awk -F \" '/data-cover/ {print $6; exit}' $ass)
if [[ -z $title ]]
then
title=$(awk -F \" '/data-cover/ {print $8}' $ass)
fi

title=${title// /_}
title=${title// /_}

dir="${title//[^a-zA-Z0-9_]/}"
dir="${title//[^a-zA-Z0-9_]/}"

if [[ -d $dir ]]
then
echo "Directory exists, you may have downloaded this album before."
exit 1
else
if [[ -z $dir ]]
then
echo "Empty album most likely, using a random integer name"
dir=$((RANDOM))
fi
echo "Saving to $dir/"
mkdir -p $dir
fi
if [[ -d $dir ]]
then
echo "Directory exists, you may have downloaded this album before."
exit 1
else
if [[ -z $dir ]]
then
echo "Empty album most likely, using a random integer name"
dir=$((RANDOM))
fi
echo "Saving to $dir/"
mkdir -p $dir
fi

for image in $(awk -F \" '/data-src/ {print $10}' $ass | sed /^$/d | sed s/s.jpg/.jpg/)
do
filename=$(sed s/http:\\/\\/i.imgur.com\\/// <<< $image)
curl -# $image > "$dir/$filename"
ftype=$(file "$dir/$filename" | grep PNG | wc -l)
if [[ $ftype == 1 ]]
then
mv "$dir/$filename" "$dir/${filename//.jpg/.png}"
fi
done
for image in $(awk -F \" '/data-src/ {print $10}' $ass | sed /^$/d | sed s/s.jpg/.jpg/)
do
filename=$(sed s/http:\\/\\/i.imgur.com\\/// <<< $image)
curl -# $image > "$dir/$filename"
ftype=$(file "$dir/$filename" | grep PNG | wc -l)
if [[ $ftype == 1 ]]
then
mv "$dir/$filename" "$dir/${filename//.jpg/.png}"
fi
done
fi

echo "Removing tmp"
Expand Down
4 changes: 2 additions & 2 deletions user.sh
Expand Up @@ -5,7 +5,7 @@ url="http://$1.imgur.com/"

for album in $(curl -s $url | grep -i "imgur.com/a/" | sed s/^.*imgur.com/imgur.com/ | sed s/\"\>// | sed s/^/http:\\/\\//)
do
echo "Downloading album: $album"
./imgur.sh $album
echo "Downloading album: $album"
./imgur.sh $album
done

0 comments on commit 23f2552

Please sign in to comment.