All pastes #21732 Raw Edit

sh

public shellscript v1 · immutable
#21732 ·published 2005-08-31 14:10 UTC
rendered paste body
#!/bin/sh#ConfigOUTPUT_DIR="/home/kikidonk/win/gp4"START_ID="24404"END_ID="60000"#Init, create output dir, set total size[[ ! -d $OUTPUT_DIR ]] && mkdir $OUTPUT_DIRTOTAL_SIZE="0"#For every song IDfor i in $(seq $START_ID $END_ID)do    #Format the id to 5-digit	i=$(echo $i | awk '{ printf("%05d\n", $0) }')	echo "$i" >> $OUTPUT_DIR/progress        #Compute the url for the file	URL="http://www.mysongbook.com/tab-tab_download-id_tablature=$i.htm"    FILE_URL="$(curl -s $URL|egrep -o '<a href="files.*/.*" '|sed 's/<a href="\(.*\)".*/\1/')"    echo "Downloading $URL"		if [ "$FILE_URL" == "" ]    then        echo "Skipping..."        echo "ERROR: $i" >> $OUTPUT_DIR/progress        echo "---"        continue    fi       if echo $FILE_URL|grep '/.zip' > /dev/null    then        echo "Skipping..."        echo "ERROR: $i" >> $OUTPUT_DIR/progress        echo "---"        continue    fi    GP4_URL="http://www.mysongbook.com/$FILE_URL"    NAME="$(echo $GP4_URL|sed 's/.*files.*\/.\/.*\/\(.*\)/\1/'|sed 's/%[0-9][0-9]//g'|tr [A-Z] [a-z])"    curl -s -D "$OUTPUT_DIR/header" "$GP4_URL" > "$OUTPUT_DIR/$NAME"    SIZE="$(cat $OUTPUT_DIR/header|grep Content-Length|sed 's/.*Length..\([0-9]\+\).*/\1/')"    TOTAL_SIZE="$(echo \($TOTAL_SIZE*1024+$SIZE\)/1024|bc)"    echo "Downloaded $NAME, Total Size:$TOTAL_SIZE KBytes"    if echo "$NAME"|grep zip    then        echo "Downloaded a zip file, extracting..."        unzip -qq -o -j -L "$OUTPUT_DIR/$NAME" -d "$OUTPUT_DIR" > /dev/null 2>&1        rm "$OUTPUT_DIR/$NAME"    fi    echo "---"done