Ubuntu – Get the total listening time from the CLI with banshee

bansheecommand linescripts

Is there a way I can get total listening time from command line? I want to write a script to keep track of how much time I spend listening to music on a daily basis.

Best Answer

First, using the following command:

pgrep banshee

you can check if Banshee is running.

If yes, you can use:

banshee --query-current-state

command in your bash script to get the current Banshee state (if it's playing or not).

Here is some rudimentary bash code from which you can start and improve your script:

#!/bin/bash

seconds=0

while : ; do
    if ( pgrep banshee > /dev/null ); then
        if [ "$(banshee --query-current-state | cut -d' ' -f2)" = "playing" ]; then
            (( seconds++ ))
            echo "Total listening time: $seconds seconds"
        fi
    fi
    sleep 1
done