Add mpd_top script
authorSiraaj Khandkar <siraaj@khandkar.net>
Tue, 17 Sep 2019 22:34:54 +0000 (18:34 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Tue, 17 Sep 2019 22:34:54 +0000 (18:34 -0400)
finds top $N played songs in mpd log

home/bin/mpd_top [new file with mode: 0755]
home/lib/login_variables.sh

diff --git a/home/bin/mpd_top b/home/bin/mpd_top
new file mode 100755 (executable)
index 0000000..b391e31
--- /dev/null
@@ -0,0 +1,24 @@
+#! /bin/sh
+
+case "$1" in
+    '') N=10;;
+    *)  N="$1"
+esac
+
+grep -a 'player: *played' "$FILE_LOG_MPD" \
+| awk '
+    BEGIN {
+        s = " *"
+    }
+
+    $5 == "player:" && $6 == "played" {
+        sub("^" s $1 s $2 s $3 s $4 s $5 s $6 s, "")
+        count[$0]++
+    }
+
+    END {
+        for (song in count)
+            printf("%d %s\n", count[song], song)
+    }' \
+| sort -n -k 1 -r \
+| head -"$N"
index 9d07f45..fda5f62 100644 (file)
@@ -3,6 +3,9 @@ export EDITOR=vim
 export VISUAL=$EDITOR
 export DIR_GITHUB="${HOME}/Archives/Software/src/repos/remote/github.com"
 export DIR_NOTES="$HOME/Documents/Notes"
+export DIR_LOG="$HOME/var/log"
+export DIR_LOG_MPD="$DIR_LOG/mpd"
+export FILE_LOG_MPD="$DIR_LOG_MPD/mpd.log"
 
 # .Net Core
 export DOTNET_ROOT=$HOME/.dotnet
This page took 0.031121 seconds and 4 git commands to generate.