Generates and manages static html of mpd currently playing music.

git clone git://watertao.xyz/programs/mpdhh.git

a_filter_track_data.awk (826B)


      1 #!/bin/awk
      2 
      3 # Sanitize Field
      4 function sf(s) {
      5 
      6 	p="";r=""
      7 
      8 	# analyze chars, create whitepace
      9 	# as needed to break long words
     10 	# apart
     11 	while (s){
     12 		c=substr(s,1,1)
     13 
     14 		# Space after case change
     15 		if (p ~ /[a-z]/){
     16 			if (c ~ /[A-Z]/){
     17 				r = r " "
     18 			}
     19 
     20 		# Space after colons
     21 		}else if (p == ":") {
     22 			if (c ~ /[a-zA-Z0-9]/){
     23 				r = r " "
     24 			}
     25 		}
     26 		r = r c
     27 		s=substr(s,2)
     28 		p=c
     29 	}
     30 	gsub( /[_.#]+/, " ",r) # rm underscores
     31 	gsub(/[-/////\\]+/," & ",r) # pad [-/] with space
     32 	gsub(/[ ]{2,}/," ",r) # squeeze spaces
     33 	gsub(/^ - $/,"-",r) # remove spaces from empty fields
     34 	return r
     35 }
     36 {
     37 	# If metadata is emtpy, set track field to filename
     38 	if ($0 == "\t\t") {
     39 		$1 = filename
     40 	}
     41 
     42 	# If value is empty, replace with dash
     43 	for (i=1; i<=NF; i++){
     44 		gsub(/^$/, d, $i)
     45 	}
     46 
     47 	OFS="\t"
     48 	print played_date, sf($1), sf($2), sf($3)
     49 }