pintcat

AMPGet v1.1 - Script to download entire music archives from http://amp.dascene.net/ at once.

Jan 10th, 2022 (edited)
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.39 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # AMPGet v1.1 - Makes downloading entire music archives from http://amp.dascene.net/ more comfortable.
  4.  
  5. OIFS=$IFS
  6. OTEXT=
  7. URL=http://amp.dascene.net/
  8. HTML=/media/ramdisk/detail.html
  9. DEF_OUTPATH=/media/ramdisk/
  10. OUTPATH=$DEF_OUTPATH
  11.  
  12. function ERROR() # display error message, infotext and exit with return code 1
  13. {
  14.     echo -e "\n\033[0;31m$1\nUsage: amp-get.bash -c [composer ID] -o [output path]\n\
  15. If no output path is given the default path $DEF_OUTPATH will be used.\033[0m\n"
  16.     exit 1
  17. }
  18.  
  19. function STRIP() # remove html crap from plain text
  20. {
  21.     TEXT=$1
  22.     while [ ! "$OTEXT" = "$TEXT" ]; do
  23.         OTEXT=$TEXT
  24.         TEXT=${TEXT#*<*>}
  25.         TEXT=${TEXT%</*>*}
  26.     done
  27. }
  28.  
  29. function GET_NAME() # obtain handle and real name
  30. {
  31.     STRING=$(grep -nm 1 $1 $HTML)
  32.     typeset -i LINE=${STRING%':    '*}+1
  33.     GET_META $LINE
  34. }
  35.  
  36. function GET_META() # obtain additional info which regards to a certain entry, but is placed on a different line
  37. {
  38.     RAW_NAME=$(sed -n $1"p" $HTML)
  39.     STRIP $RAW_NAME
  40. }
  41.  
  42. while getopts :c:C:o:O: OPT; do
  43.     case $OPT in
  44.         c|C)
  45.             if [[ ! $OPTARG =~ ^[0-9]+$ ]]; then ERROR "Composer ID must be a number!"; fi
  46.             ID=$OPTARG
  47.             ;;
  48.         o|O)
  49.             if [ ! -d $OPTARG ]; then ERROR "Output path doesn't exist."; fi
  50.             OUTPATH=$OPTARG
  51.             ;;
  52.         \?)
  53.             ERROR "Unknown option: "$OPTARG
  54.             ;;
  55.     esac
  56. done
  57. if [ -z $ID ]; then ERROR "Composer ID must be given!"; fi
  58.    
  59. if wget -q $URL'detail.php?detail=modules&view='$ID -O $HTML; then
  60.     IFS=$'\n'
  61.     typeset -i COUNT=0
  62.     typeset -i OK=0
  63.     typeset -i FAIL=0
  64.     cd $OUTPATH
  65.     echo -e "\nOutput path is: "$OUTPATH"\nComposer ID is: "$ID
  66.     GET_NAME 'class="descript">Handle:'
  67.     HANDLE=$TEXT
  68.     echo "Handle is:      "$HANDLE
  69.     GET_NAME '<td class="descript">Real&nbsp;Name: </td>'
  70.     REAL_NAME=$TEXT
  71.     echo -e "Real name is:   "$REAL_NAME"\n"
  72.     for MOD_ENTRY in $(grep -n '" target="_new">' $HTML); do
  73.         COUNT=$COUNT+1
  74.         typeset -i POS=0
  75.         typeset -i LINE=${MOD_ENTRY%':    '*}+4
  76.         STRIP $MOD_ENTRY
  77.         RAW=$TEXT
  78.         TYPE=
  79.         GET_META $LINE
  80.         if [ ! $TEXT = MOD ]; then TYPE="."$TEXT; fi
  81.         while [ ${#RAW} -gt $POS ]; do
  82.             if [ "${RAW:$POS:3}" = '&nb' ]; then
  83.                 POS=$POS+5
  84. # 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 "_"
  85.             elif [ "${RAW:$POS:1}" = \* ] || [ "${RAW:$POS:1}" = \? ] || [ "${RAW:$POS:1}" = \| ] || [ "${RAW:$POS:1}" = \@ ] || [ "${RAW:$POS:1}" = \" ]
  86.             then
  87.                 NAME=$NAME"_"
  88.             elif [ "${RAW:$POS:4}" = '&lt;' ] || [ "${RAW:$POS:4}" = '&gt;' ]; then
  89.                 NAME=$NAME"_"
  90.                 POS=$POS+3
  91.             else
  92.                 NAME=$NAME${RAW:$POS:1}
  93.             fi
  94.             POS=$POS+1
  95.         done
  96.         while [ -f $NAME$TYPE".mod.gz" ]; do NAME=$NAME"_"; done
  97.         NAME=$NAME$TYPE".mod.gz"
  98.         echo -n "Downloading "$NAME"...        "
  99.         MOD_ID=${MOD_ENTRY#*'<td><a href="'}
  100.         MOD_ID=${MOD_ID%'" target="_new">'*}
  101.         FILE=$URL$MOD_ID
  102.         if wget -q $FILE -O $NAME; then
  103.             echo -e "\033[0;32mOK\033[0m"
  104.             OK=$OK+1
  105.         else
  106.             echo -e "\033[0;31mFAILED!\033[0m"
  107.             FAIL=$FAIL+1
  108.         fi
  109.         NAME=""
  110.     done
  111.     IFS=$OIFS
  112.     if [ $COUNT -gt 0 ]; then
  113.         echo -e "\nNumber of files: "$COUNT"    Downloaded: "$OK"    Failed: "$FAIL"\n"
  114.         echo -e "Composer ID was: "$ID"\nHandle was:      "$HANDLE"\nReal name was:   "$REAL_NAME"\n"
  115.     else
  116.         echo -e "Nothing to download.\n"
  117.     fi
  118.     rm -f $HTML
  119. else
  120.     ERROR "Unable to retrieve composer information. Possibly due to difficulties with internet connection or page is offline."
  121. fi
  122.  
Add Comment
Please, Sign In to add comment