Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # AMPGet v1.1 - Makes downloading entire music archives from http://amp.dascene.net/ more comfortable.
- OIFS=$IFS
- OTEXT=
- URL=http://amp.dascene.net/
- HTML=/media/ramdisk/detail.html
- DEF_OUTPATH=/media/ramdisk/
- OUTPATH=$DEF_OUTPATH
- function ERROR() # display error message, infotext and exit with return code 1
- {
- echo -e "\n\033[0;31m$1\nUsage: amp-get.bash -c [composer ID] -o [output path]\n\
- If no output path is given the default path $DEF_OUTPATH will be used.\033[0m\n"
- exit 1
- }
- function STRIP() # remove html crap from plain text
- {
- TEXT=$1
- while [ ! "$OTEXT" = "$TEXT" ]; do
- OTEXT=$TEXT
- TEXT=${TEXT#*<*>}
- TEXT=${TEXT%</*>*}
- done
- }
- function GET_NAME() # obtain handle and real name
- {
- STRING=$(grep -nm 1 $1 $HTML)
- typeset -i LINE=${STRING%': '*}+1
- GET_META $LINE
- }
- function GET_META() # obtain additional info which regards to a certain entry, but is placed on a different line
- {
- RAW_NAME=$(sed -n $1"p" $HTML)
- STRIP $RAW_NAME
- }
- while getopts :c:C:o:O: OPT; do
- case $OPT in
- c|C)
- if [[ ! $OPTARG =~ ^[0-9]+$ ]]; then ERROR "Composer ID must be a number!"; fi
- ID=$OPTARG
- ;;
- o|O)
- if [ ! -d $OPTARG ]; then ERROR "Output path doesn't exist."; fi
- OUTPATH=$OPTARG
- ;;
- \?)
- ERROR "Unknown option: "$OPTARG
- ;;
- esac
- done
- if [ -z $ID ]; then ERROR "Composer ID must be given!"; fi
- if wget -q $URL'detail.php?detail=modules&view='$ID -O $HTML; then
- IFS=$'\n'
- typeset -i COUNT=0
- typeset -i OK=0
- typeset -i FAIL=0
- cd $OUTPATH
- echo -e "\nOutput path is: "$OUTPATH"\nComposer ID is: "$ID
- GET_NAME 'class="descript">Handle:'
- HANDLE=$TEXT
- echo "Handle is: "$HANDLE
- GET_NAME '<td class="descript">Real Name: </td>'
- REAL_NAME=$TEXT
- echo -e "Real name is: "$REAL_NAME"\n"
- for MOD_ENTRY in $(grep -n '" target="_new">' $HTML); do
- COUNT=$COUNT+1
- typeset -i POS=0
- typeset -i LINE=${MOD_ENTRY%': '*}+4
- STRIP $MOD_ENTRY
- RAW=$TEXT
- TYPE=
- GET_META $LINE
- if [ ! $TEXT = MOD ]; then TYPE="."$TEXT; fi
- while [ ${#RAW} -gt $POS ]; do
- if [ "${RAW:$POS:3}" = '&nb' ]; then
- POS=$POS+5
- # The following chars are not allowed for file names in either the Linux or the AmigaDOS file system and will be replaced by an underscore "_"
- elif [ "${RAW:$POS:1}" = \* ] || [ "${RAW:$POS:1}" = \? ] || [ "${RAW:$POS:1}" = \| ] || [ "${RAW:$POS:1}" = \@ ] || [ "${RAW:$POS:1}" = \" ]
- then
- NAME=$NAME"_"
- elif [ "${RAW:$POS:4}" = '<' ] || [ "${RAW:$POS:4}" = '>' ]; then
- NAME=$NAME"_"
- POS=$POS+3
- else
- NAME=$NAME${RAW:$POS:1}
- fi
- POS=$POS+1
- done
- while [ -f $NAME$TYPE".mod.gz" ]; do NAME=$NAME"_"; done
- NAME=$NAME$TYPE".mod.gz"
- echo -n "Downloading "$NAME"... "
- MOD_ID=${MOD_ENTRY#*'<td><a href="'}
- MOD_ID=${MOD_ID%'" target="_new">'*}
- FILE=$URL$MOD_ID
- if wget -q $FILE -O $NAME; then
- echo -e "\033[0;32mOK\033[0m"
- OK=$OK+1
- else
- echo -e "\033[0;31mFAILED!\033[0m"
- FAIL=$FAIL+1
- fi
- NAME=""
- done
- IFS=$OIFS
- if [ $COUNT -gt 0 ]; then
- echo -e "\nNumber of files: "$COUNT" Downloaded: "$OK" Failed: "$FAIL"\n"
- echo -e "Composer ID was: "$ID"\nHandle was: "$HANDLE"\nReal name was: "$REAL_NAME"\n"
- else
- echo -e "Nothing to download.\n"
- fi
- rm -f $HTML
- else
- ERROR "Unable to retrieve composer information. Possibly due to difficulties with internet connection or page is offline."
- fi
Add Comment
Please, Sign In to add comment