diff options
-rwxr-xr-x | clerk | 32 | ||||
-rwxr-xr-x | clerk_helper | 2 |
2 files changed, 21 insertions, 13 deletions
@@ -41,12 +41,31 @@ elif [[ $scrobbler == mpdscribble ]]; then export scrobbler_kill="mpdscribble" fi +updateCache () { + cd $HOME/.config/clerk + rm -f *.cache + clerk_helper 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 +} + # check if clerk_helper process is running. if it isn't update cache files, if # needed if [[ $(ps x| grep clerk_helper | head -1 | grep -v 'grep') ]]; then : else - clerk_helper update & + date=$(mpc stats | grep 'DB Updated: ') + file="$HOME/.config/clerk/.lastupdate" + if [ "$(< $file)" = "$date" ] && [ -f "$file" ] ; then + : + else + updateCache + echo "${date}" > "${file}" + fi fi export separator="$separator" @@ -76,17 +95,6 @@ sed=$([[ "$OSTYPE" == "darwin"* ]] && echo 'gsed' || echo 'sed') shuf=$([[ "$OSTYPE" == "darwin"* ]] && echo 'gshuf' || echo 'shuf') tac=$([[ "$OSTYPE" == "darwin"* ]] && echo 'gtac' || echo 'tac') -updateCache() { - cd $HOME/.config/clerk - rm -f *.cache - clerk_helper createcache - cat tracks.cache | sed 's,^\([^\t]\{40\}\)[^\t]*,\1…,' | column -o $'\t' -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 -} # main Menu dplayPrompt () { diff --git a/clerk_helper b/clerk_helper index a465c15..d48d2a8 100755 --- a/clerk_helper +++ b/clerk_helper @@ -120,7 +120,7 @@ def createCache(args): taglist = ['date', 'artist', 'albumartist', 'album', 'track', 'title', 'file'] track.update([(k, reduceToFstElm(v)) for (k, v) in track.items() if k in taglist]) - tracklist.append(track['track']+" "+track['title']+"\tby "+track['artist']+" on "+track['album']+" ("+track['date']+")\t"+track['file']) + tracklist.append(track['track']+"\t"+track['title']+"\tby "+track['artist']+" on "+track['album']+" ("+track['date']+")\t"+track['file']) # with open(os.getenv('HOME')+'/.config/clerk/tracks.cache', "w") as cache_file: for track in tracklist: |