Advertisement
ZaxonXP45

get_modarchive_mods.sh

Oct 13th, 2022 (edited)
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.21 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ######################################################################################
  4. get_modules() {
  5.     local nr=$1
  6.     local dir="../Downloaded"
  7.  
  8.     [ ! -d $dir ] && mkdir $dir
  9.  
  10.     local    URL="http://modarchive.org/index.php?"
  11.     local   site="${URL}request=view_top_favourites&page=${nr}#mods"
  12.     local SEARCH="${URL}request=search&submit=Find&search_type=filename_or_songtitle&query="
  13.     local  GENRE="${URL}request=view_by_moduleid&query="
  14.  
  15.     echo "Page: $nr"
  16.  
  17.     [ ! -f downloaded ] && touch downloaded
  18.     [ ! -f deleted ] && touch deleted
  19.  
  20.     for i in `lynx -dump -listonly "$site" | grep api | grep downloads | rev | cut -d" " -f1 | rev | sort | uniq` ; do
  21.  
  22.         name=$(echo $i | cut -d# -f2)
  23.         have=$(cat downloaded deleted | grep -ci "$name")
  24.        
  25.         if [[ $have -eq 0 ]]; then
  26.             echo Getting: \"$name\"
  27.             wget --quiet -O "$dir/$name" "$i"
  28.  
  29.             if [ -s "$dir/$name" ]; then
  30.                
  31.                 # get the module id by searching it by file name
  32.                 if [[ $( lynx -dump -listonly ${SEARCH}$name | grep api | wc -l) -gt 1 ]]; then
  33.                     id=UNKN
  34.                     genre=n/a
  35.                 else
  36.                     id=$(lynx -dump -listonly "${SEARCH}$name" | grep api)
  37.                     id=${id#*=}
  38.                     id=${id%\#*}
  39.  
  40.                     # get the genre of the module searching by ID
  41.                     genre=$(lynx -dump -nolist "${GENRE}$id" | grep "Genre:" | head -1)
  42.                     genre=${genre#*: }
  43.                 fi
  44.  
  45.                 echo "$id;$name;$genre" >> downloaded
  46.             fi
  47.         fi
  48.     done
  49.  
  50.     7zpack_sep.sh $dir
  51. }
  52.  
  53. ######################################################################################
  54. if [ -n "$1" ]; then
  55.  
  56.     [ -n "$1" ] && start=1    end=$1 && shift
  57.     [ -n "$1" ] && start=$end end=$1
  58.  
  59.     for (( j = $start; j <= $end ; j++ )); do
  60.         get_modules $j
  61.     done
  62.  
  63. else
  64.  
  65.     if [ -s last_page ]; then
  66.         next=$(( $( cat last_page ) + 1 ))
  67.     else
  68.         echo 1 > last_page
  69.         next=1
  70.     fi
  71.  
  72.     if [ -v next ]; then
  73.         get_modules $next
  74.         echo $next > last_page
  75.     fi
  76. fi
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement