Skip to content

Instantly share code, notes, and snippets.

@Markus00000
Last active August 29, 2015 14:22
Show Gist options
  • Save Markus00000/f4061589671580523d41 to your computer and use it in GitHub Desktop.
Save Markus00000/f4061589671580523d41 to your computer and use it in GitHub Desktop.
Show song rating from playlist using cmus
#!/bin/bash
# Path to playlists
playlists="$HOME/music"
# Prefix and suffix strings for the playlist file name
pl_prefix=''
pl_suffix='.m3u'
# Get current song from cmus
song=$(cmus-remote -Q | grep file)
# Strip "file " from the output
song=${song/file \///}
for n in {1..5}; do
f="$playlists/${pl_prefix}$n${pl_suffix}"
if [[ -f "$f" ]]; then
grep -Fq "$song" "$f"
if [[ "$?" == 0 ]]; then
rating="Rating: $n/5"
fi
fi
done
playing=$(cmus-remote -Q)
artist=$(echo "$playing" | grep "tag artist " | cut -d " " -f 3-)
title=$(echo "${playing}" | grep "tag title " | cut -d " " -f 3-)
album=$(echo "${playing}" | grep "tag album " | cut -d " " -f 3-)
album_artist=$(echo "${playing}" | grep "tag albumartist " | cut -d " " -f 3-)
if [ "$album_artist" == '' ]; then
echo -e "$artist\n$title\n$album\n$rating"
notify-send -t 3000 "$artist\n$title\n$album\n$rating"
else
echo -e "$artist ($album_artist)\n$title\n$album\n$rating"
notify-send -t 3000 "$artist ($album_artist)\n$title\n$album\n$rating"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment