Advertisement
ZaxonXP45

Modarchive.org top favourite playlist player

Apr 14th, 2023 (edited)
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.80 KB | Music | 0 0
  1. #!/bin/bash
  2. PAGE=$1
  3. POSF=${0/.sh/.last}
  4.  
  5. ###############################################################################
  6. URL="http://modarchive.org/index.php?request=view_top_favourites&page="
  7.  
  8. ###############################################################################
  9. get_pos() {
  10.     local data=$(cat $POSF)
  11.     SONG=${data#*:}
  12.     PAGE=${data%:*}
  13. }
  14.  
  15. ###############################################################################
  16. get_mod_and_play() {
  17.     local urlloc=$1
  18.     local file=${urlloc#*\#}
  19.  
  20.     wget -q -O $dir/$file "$urlloc"
  21.     echo -e "$urlloc\n"
  22.     (sleep 1; echo -n . > openmpt123_fifo)&
  23.     openmpt123 --no-meters --banner 0 --assume-terminal $dir/$file < openmpt123_fifo
  24.     rm $dir/$file
  25. }
  26.  
  27. ###############################################################################
  28. get_mod_list() {
  29.     local page=$1
  30.     LIST=( "" $(lynx -dump -listonly -nonumbers "${URL}${page}" | grep download | uniq) )
  31.     MAX=${#LIST[*]}
  32. }
  33.  
  34. ###############################################################################
  35. cleanup() {
  36.     cd /tmp
  37.     rm -rf $dir
  38.     rm openmpt123_fifo
  39.     rm openmpt123_list
  40.     reset
  41.     exit 0;
  42. }
  43.  
  44. ######################## Main code ############################################
  45.  
  46. [ -z "$PAGE" ] && [ ! -f $POSF ] && echo "Page number not specified" && exit 1
  47. [ -z "$PAGE" ] && [   -f $POSF ] && get_pos
  48.  
  49. cd /tmp/
  50. dir=$(mktemp -d)
  51.  
  52. [ ! -p openmpt123_fifo ] && mkfifo openmpt123_fifo
  53. [ ! -f openmpt123_list ] && echo $POSF > openmpt123_list
  54.  
  55. trap 'cleanup' SIGINT
  56.  
  57. while [ 1 ]; do
  58.     get_mod_list $PAGE
  59.     while [ $SONG -lt $MAX ]; do
  60.         clear
  61.         echo -n "[$PAGE:$SONG] "
  62.         echo "$PAGE:$SONG" > $POSF
  63.         get_mod_and_play ${LIST[$SONG]}
  64.         get_pos
  65.         ((SONG+=1))
  66.     done
  67.     SONG=1
  68.     ((PAGE+=1))
  69. done
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement