#!/bin/bash # Paste a file here that contains the HTML code to be placed _before_ the MP3 tag list. DIRLISTHEAD="/etc/mp3dir2html/head.php" # Regular expression that is to be excluded in the final listing should exist as # DIRLISTEX='what.*ever|another.*one' in CONFFILE. Plus, we need the resulting table's # id as M3LTABLEID='mp3list' (or whatever else) CONFFILE='/etc/mp3dir2html/mp3dir2html.conf' # CORE SCRIPT FROM HERE. DON'T FIDDLE IF YOU DON'T KNOW WHAT YOU'RE DOING. M3LTABLEID='mp3list' DIRLISTEX="0x1fedbeef" [ -r "$CONFFILE" ] && . "$CONFFILE" || echo "WARNING: $CONFFILE not readable..." function m3l_help { echo "Usage: $(basename $0) [options]";echo echo "Options:" echo -e " -h\t\tPrint this help text and exit" echo -e " -d DIRECTORY\tSpecify a directory to be scanned" echo -e " \t\tWithout supplying DIRECTORY, the current directory will be used." } while getopts "ht:r:p:v" params; do case $params in "h") m3l_help exit 0 ;; "d") SDIR="$OPTARG" ;; esac done if [ "$SDIR" == "" ]; then SDIR="*" fi function m3l_rm_verb { #As -q nukes away too much, we have to omit that and remove status stuff here: grep -v 'directories scanned' | grep -v 'files read' } function m3l_prep_table { #Let's create a tab separated table with empty values where we have none but need at least an empty one. # (Besides, this kind of rhymes.) # Additionally: ampersand handling sed 's/========.*/====/g' | sed 's/\t$/\t" "/g' | tr '\n' '\t' |\ sed 's/====/\n====/g;s/====\t/====/g' |\ sed 's/Artist\t//;s/Title\t//;s/Album\t//;s/\(.*\)Year\t/\1/;s/\(.*\)Track\t/\1/' |\ uniq | sed 's/====//g;s/&/\&\;/g' | tr -s '\n' |\ sed 's/\t0\t/\t"0"\t/g' } function m3l_fin_table { #Sort stuff, grep away lame artists and finally: put everything in order and remove the quotation marks # from the entries again (leaving a whitespace char on an empty entry actually). sort -t \t -k 1,2 -k 2,3 -k 4,5 -k 3,4 |\ grep -vE "$DIRLISTEX" |\ awk -F '\t' '{print $1"\t"$2"\t"$3}' |\ sed 's/" "/ /g;s/"0"/0/g' } exiftool -ext .mp3 -ext .MP3 -ext .wma -ext .WMA -ext .ogg -ext .OGG -lang en -Artist -Title -Album -Year -Track -t -r $SDIR |\ m3l_rm_verb |\ m3l_prep_table |\ m3l_fin_table > content.csv cat "$DIRLISTHEAD" > content.php echo -n "

">>content.php for i in `cat content.csv|awk '{print substr($0,0,1)}'|sort|tr '[:lower:]' '[:upper:]'|uniq`;do echo -n "$i">>content.php;done echo -e "

\n">>content.php sed 's/^/
/g;s/\t/<\/td>/g;s/$/<\/td><\/tr>/g' content.csv >> content.php rm content.csv echo -e '\n\n
\n\n\n\n' >> content.php for i in `seq 0 9` `echo {A..Z}` `echo {a..z}`;do sed -i -e "0,/^\($i\)/ s/^\($i\)/\\1/" content.php done echo