diff options
Diffstat (limited to 'clerk2')
-rwxr-xr-x | clerk2 | 71 |
1 files changed, 64 insertions, 7 deletions
@@ -41,16 +41,73 @@ elif [[ $scrobbler == mpdscribble ]]; then export scrobbler_kill="mpdscribble" fi +fix_date_format() { + # reformats the date given in column $1 from format %c of locale LC_TIME=C + # (see man strftime) to the format specified in argument $2 column indices + # start with 1 + column_index="$1" + gawk -F $'\t' ' + # parse a date which was formated using %c to unix time + BEGIN { + # generated by the following bash one-liner: + # for i in {1..12} ; do LC_TIME=C date -d "1972-$i-01" +month2num[\"%b\"]\ =\ %_m ; done + month2num["Jan"] = 1 + month2num["Feb"] = 2 + month2num["Mar"] = 3 + month2num["Apr"] = 4 + month2num["May"] = 5 + month2num["Jun"] = 6 + month2num["Jul"] = 7 + month2num["Aug"] = 8 + month2num["Sep"] = 9 + month2num["Oct"] = 10 + month2num["Nov"] = 11 + month2num["Dec"] = 12 + } + function reformat_c_date(str) { + monthname = gensub(/^([^ ]*)[ ]+([^ ]*)[ ]+([^ ]*)[ ]+([^ ]*)[ ]+([^ ]*)$/, "\\2", "g", str) + monthnum = month2num[monthname] + nicedate = gensub(/^([^ ]*)[ ]+([^ ]*)[ ]+([^ ]*)[ ]+([^ ]*)[ ]+([^ ]*)$/, "\\5 " monthnum " \\3 \\4", "g", str) + nicedate = gensub(/:/, " ", "g", nicedate) + return nicedate + } + { + # modify the $column_index-th field + $'"$1"' = strftime("'"$2"'", mktime(reformat_c_date($'"$1"'))) + print $0 + } + ' +} + + updateCache () { cd $HOME/.config/clerk2 rm -f *.cache - ./clerk_helper2 createcache - cat tracks.cache | sed 's,^\([^\t]*\t[^\t]\{40\}\)[^\t]*,\1,' | column -o ' ' -s $'\t' -t > tracks.cache.new - mv tracks.cache.new tracks.cache - cat latest.cache | column -o $'\t' -s $'\t' -t > latest.cache.new - mv latest.cache.new latest.cache - cat albums.cache | column -o $'\t' -s $'\t' -t > albums.cache.new - mv albums.cache.new albums.cache + mpc --format '[%mtime%\t%albumartist%|%artist%] - (%date%) - %album%' \ + search filename '' \ + | grep -v '^ — ' \ + | grep -v ' — $' \ + | uniq \ + | fix_date_format 1 '%Y-%m-%d' \ + | sort -u \ + | sort -nr \ + | awk '{for (i=2; i<NF; i++) printf $i " "; print $NF}' \ + | awk -F ' - ' '{ print $1 "\t" $2 " - " $3 }' \ + | sed 's,^\([^\t]*\t[^\t]\{40\}\)[^\t]*,\1,' | column -o ' ' -s $'\t' -t > $HOME/.config/clerk2/latest.cache + mpc --format '[%albumartist%|%artist%]\t(%date%) - %album%' \ + search filename '' \ + | grep -v '^ - ' \ + | grep -v ' - $' \ + | sort \ + | uniq \ + | column -o $'\t' -s $'\t' -t > $HOME/.config/clerk2/albums.cache + mpc --format '[[%title%\t[(by %artist%[ on %album%])]]|[%file%]]\t%file%' \ + search filename '' \ + | grep -v '^ - ' \ + | grep -v ' - $' \ + | uniq \ + | sed 's,^\([^\t]\{40\}\)[^\t]*,\1…,' | column -o $'\t' -s $'\t' -t \ + > $HOME/.config/clerk2/tracks.cache } # check if ./clerk_helper2 process is running. if it isn't update cache files, if |