Skip to content

Instantly share code, notes, and snippets.

@XORwell
Created November 12, 2012 06:03
Show Gist options
  • Save XORwell/4057762 to your computer and use it in GitHub Desktop.
Save XORwell/4057762 to your computer and use it in GitHub Desktop.
freesound.org sound-samples downloader
#!/bin/bash
#############
# CONFIG
redisDB=0
redisClient="/usr/local/bin/redis-cli"
redisServer="/usr/local/bin/redis-server"
diff(){
awk 'BEGIN{RS=ORS=" "}
{NR==FNR?a[$0]++:a[$0]--}
END{for(k in a)if(a[k])print k}' <(echo -n "${!1}") <(echo -n "${!2}")
}
# Welcome:
clear
echo "-------------------------------------------------------------------------------------------------"
echo "| Warning: This script WILL NOT check if your disk has enough free space to store the downloads. |"
echo "-------------------------------------------------------------------------------------------------"
#filesize prefetch via curl-header
# Starting redis server
coproc $redisServer
# Ask for download-folder
echo -n -e "download folder (`pwd`/freesound): "
read path
if [ -z "$path" ]
then
path="`pwd`/freesound"
fi
echo $path
# Make sure the download-folder exists; if not, we'll try to create it
if [ -d "$path" ]
then
cd $path
else
mkdir $path
cd $path
fi
# Fetch all collection-ids
ids=(`curl http://www.freesound.org/packsView.php -s | egrep -o 'packsViewSingle.php\?id=[0-9]*' | egrep -o '[0-9]*'`)
# Before we start, tell how many file we'll download
echo "${#ids[*]} sample-collections found on freesound.org"
# Check for filenames, already in redis
rediskeys=(`$redisClient -n $redisDB KEYS \*`)
newIds=($(diff ids[@] rediskeys[@]))
diff=$((${#ids[@]} - ${#newIds[@]}))
echo "$diff already in redis"
echo "${#newIds[@]} filenames remaining"
# Get the filename of each remaining collection
files=( )
echo "Grabbing the archive-filenames of ${#newIds[@]} collections. This could take a while."
i=0
for id in ${ids}
do
((i++))
echo -n "$i of ${#ids}: "
filepath=`curl http://www.freesound.org/packsViewSingle.php?id=$id -s | egrep -o 'http://www.freesound.org\/downloadpack\/.*\.zip'`
filename=`echo $filepath | egrep -o '[0-9]*_.*\.zip'`
$redisClient -n $redisDB SET $id $filename > /dev/null
echo "OK"
echo $filepath
`curl $filepath -H`
if [ $i -eq 2 ]
then
break
fi
done
#$redisClient -n $redisDB KEYS \*
#save and shutdown the server (which we opened via 'coproc')
$redisClient shutdown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment