From 6fe002736730aaa336f10d44568bd36ef8f7aaf7 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Tue, 17 Sep 2019 18:34:54 -0400 Subject: [PATCH] Add mpd_top script finds top $N played songs in mpd log --- home/bin/mpd_top | 24 ++++++++++++++++++++++++ home/lib/login_variables.sh | 3 +++ 2 files changed, 27 insertions(+) create mode 100755 home/bin/mpd_top diff --git a/home/bin/mpd_top b/home/bin/mpd_top new file mode 100755 index 0000000..b391e31 --- /dev/null +++ b/home/bin/mpd_top @@ -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" diff --git a/home/lib/login_variables.sh b/home/lib/login_variables.sh index 9d07f45..fda5f62 100644 --- a/home/lib/login_variables.sh +++ b/home/lib/login_variables.sh @@ -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 -- 2.20.1