Created
November 8, 2010 00:57
-
-
Save pablox-cl/667247 to your computer and use it in GitHub Desktop.
Bash script to download sounds from instants.cl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
############################################################################### | |
# # | |
# (c) 2010, Pablo Olmos de Aguilera <pablo[at}glatelier.org>; # | |
# Based on work from Gonzalo Diaz <me{at)gon.cl>; # | |
# http://gon.pastebin.com/zanh8uAq # | |
# # | |
# Based on InstantsFunGet from Felipe Astroza <felipe(at]astroza.cl> # | |
# http://felipe.astroza.cl/news/2010/05/08/audios-de-instantsfun-es-en-mp3/ # | |
# # | |
# This program is free software: you can redistribute it and/or modify # | |
# it under the terms of the GNU General Public License as published by # | |
# the Free Software Foundation, either version 3 of the License, or # | |
# (at your option) any later version. # | |
# # | |
# This program is distributed in the hope that it will be useful, # | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
# GNU General Public License for more details. # | |
# # | |
# You should have received a copy of the GNU General Public License # | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
# # | |
############################################################################### | |
#============================================================================== | |
# | |
# FILE: instants_cl_mp3_downloader.sh | |
# | |
# DESCRIPTION: Download every 'instant' from instants.cl to a folder. | |
# | |
# REVISION: 0.9 | |
#============================================================================== | |
# | |
# Constants | |
# | |
SOURCE_HOST=http://www.instants.cl/search?max-results=1000 | |
# TODO: Use mktemp | |
TEMP_DIR=tmp | |
# TODO: Ask user | |
COLLECTION_DIR=collection | |
# TODO: make optional wget or curl | |
# TODO: ask if the user wants to convert to wav | |
REQUIREMENTS=( lame wget swfextract ) | |
function prepare() { | |
for app in ${REQUIREMENTS[@]}; do | |
if ! type -P ${app} &>/dev/null; then | |
# TODO: Find a way to make bash find that swfextract is part from swftools | |
[[ $app = "swfextract" ]] && app="swftools" | |
not_installed=("${not_installed[@]}" "$app") | |
fi | |
done | |
if [ ${#not_installed[@]} != 0 ]; then | |
echo "Sorry, the following apps have to be installed to run this script:" >&2 | |
for required_app in ${not_installed[@]}; do | |
printf " %s\n" $required_app | |
done | |
exit 1 | |
fi | |
mkdir -p $TEMP_DIR $COLLECTION_DIR | |
} | |
function cleanup() { rm -fr $TEMP_DIR; } | |
function get_swf_list() { | |
echo $(cat $1 | grep swf | awk 'BEGIN {FS="\""}; {print $12}'); | |
} | |
function get_index() { | |
wget -q $1 -O $TEMP_DIR/index | |
echo "$TEMP_DIR/index" | |
} | |
# | |
# Starting Application | |
# | |
prepare | |
echo "InstantsChileGet-Improved - (C) 2010 Pablo Olmos de Aguilera" | |
echo "Based on: InstantsChileGet - (C) 2010 Gonzalo Diaz" | |
echo "based on: InstantsFunGet - (C) 2010 Felipe Astroza" | |
echo -n -e "Reading index\r" | |
swf_list=$(get_swf_list $(get_index $SOURCE_HOST)) | |
# Deleting $TEMP_DIR/to_download if exists | |
[[ -e $TEMP_DIR/to_download ]] && rm $TEMP_DIR/to_download | |
for swf in $swf_list; do | |
echo $swf >> $TEMP_DIR/to_download | |
done | |
# Remove duplicated entries | |
swf_list=$(cat $TEMP_DIR/to_download | uniq ) | |
TOTAL=$(echo $swf_list | wc -w) | |
current=1 | |
for swf in $swf_list; do | |
name=$(echo $swf | awk 'BEGIN {FS="/"}; {print $6}') | |
echo -e -n "\r[$current of $TOTAL]\e[0K $swf => $TEMP_DIR/$name\n" | |
wget -q -nc $swf -P $TEMP_DIR/ | |
let "current++" | |
done | |
echo "Now we are going to extract the sound..." | |
sleep 5 | |
current=1 | |
for swf in $TEMP_DIR/*.swf; do | |
filename=$(basename $swf) | |
name=${filename%.*} | |
echo -e -n "\r[$current of $TOTAL]\e[0K Extracting sound from: \ | |
$swf => $COLLECTION_DIR/$name.mp3\n" | |
sound_id=$(swfextract $swf | grep Sound: | awk '{print $5}') | |
swfextract -s $sound_id $swf -o $COLLECTION_DIR/$name.mp3 | |
lame --decode $COLLECTION_DIR/$name.mp3 $COLLECTION_DIR/$name.wav | |
let "current++" | |
done | |
cleanup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment