#!/bin/sh # _ _ # | | | | # _____ _____ _| |_ ____ ____ _____ ___| | # / _ \/ ____|_ _| _ V _ | _ | _ | # | |_| | ___ | | | | | | | | |_| | |_| | # \___ |\_____| |_| |_| |_| |_|_____|_____| # __| | _________________________________ # |___/ --------------------------------- # _ _ _ _ # | |_| | | | | | _ # | |-| |___ ____ ____ _____ ___| |_____ ___________| |___|-| _ _ _____ # | | | _ | _ V _ | _ | _ | _ | ___| ___| _ | |\ \/ / ____| # | | | |_| | | | | | | |_| | |_| | |_| | | | |___| | | | | \ / ___ # |_|_|_____|_| |_| |_|_____|_____|____/\_| |_____|_| |_|_| \/ \_____| # a simple program (and somewhat of a library) to download modules from the # mod archive. provide a filename as the first argument, and a search method # (if you want) as the second (see getmodid() for details). by mothcompute. # public domain as always. part of https://github.com/mothcompute/stuff # on bsds you may need to make this `gsed` SED=sed # `penc` takes a single string on argv[1] and outputs # its percent-encoded version, followed by a newline, # unless argv[1] is '-p', in which case ' ' is encoded # as '+'. here is my implementation: # int main(int a,char**v){if(a<2)exit(1);int i=0,c;if((a>2)&&!(i=(*((short*)v[1])==28717)))exit(1);while(c=*(v[1+i]++)){if(i&&c==32){c=43;goto p;}if((!((c^32)>>4)&&c!=34&&c!=45&&c!=46)||(c==58||c==59||c==61||c==63||c==64||c==91||c==93))printf("%%%02X",c);else p:putchar(c);}putchar(10);} PENC=penc PLAYER() { which xmp > /dev/null || exit xmp -l $@ } which $SED > /dev/null || exit which $PENC > /dev/null || exit # lma_getid(): returns module id # $1 : song or filename # $2 OPTIONAL : search type # possible values for $2: true DEFAULT: 'filename_or_songtitle' \ 'filename' \ 'module_instruments' \ 'filename_and_songtitle' \ 'songtitle' \ 'module_comments' lma_getid() { SEARCHTYPE='filename_or_songtitle' [ ! -z "$2" ] && SEARCHTYPE=$2 curl -s "https://modarchive.org/index.php?request=search&submit=Find&search_type=$SEARCHTYPE&query=$($PENC -p "$1")" | $SED 's/?/ /g;s/ /\n/g' | grep moduleid= | $SED 's/#.*//;s/moduleid=//g' | xargs | awk '{print $1}' } # lma_getname(): returns filename of module # $1 : module id lma_getname() { curl -s "https://modarchive.org/index.php?request=view_by_moduleid&query=$1" | $SED 's/span/\n/g' | grep module-sub-header | $SED 's/).*//;s/.*(//' } lma_int_gmi() { curl -s "https://modarchive.org/index.php?request=view_by_moduleid&query=$1" | grep -A 8 Info | grep li | grep -v 'ul class=' | $SED "s/