You are not logged in.
I'm using fluxbox. I created a ~/.bin, placed the script in it, and added the variables in .bashrc (PATH="${PATH}:/home/user/.bin")
Now, from the terminal, I can execute "mpdratings.sh 0/1/.../5".
However, when I assigned the keyboard shortcuts in "keys" file of fluxbox, I had to add the entire path (Control Shift 0 :exec ~/.bin/mpdratings.sh 0) and it would not simply take "mpdratings.sh 0".
This is not an issue, but just trying to learn if there is something wrong that I did.
Offline
Environment variables can be tricky and I'm not knowledgeable enough to explain what exactly is happening. I think it depends on how you start your X server and your window manager and where you set a variable. As you set it in .bashrc, I assume that your window manager executes your script from a shell that didn't source .bashrc and therefore doesn't know about your changed PATH. If you are interested in the correct explanation, I'd suggest you make a new post or ask in #archlinux.
Offline
Somewhat off-topic, but from this example I had an idea to enable adding the currently playing song to an arbitrary (existing) playlist.
The rationale is that if I hear a good song on my desktop I want to have it on my ipod as well. This script will easily add the currently playing song to a specified playlist and I use
mpdipod to synch that playlist to the ipod.
Additionally, creating a keybinding in the window manager (stumpwm in my case) and using udev-rules to automatically synch the ipod once connected, the whole process is a breeze. The only thing to remember is to umount the ipod before disconnecting.
#!/bin/bash
## Usage: mpd_add_current_to_playlist [playlist]
#
# Adds currently playing song specified playlist. If no playlist is
# given, a list of all playlists is returned.
#
# Can be used to add the currently playing song to a known playlist
# which is synched to a mobile device when connected (usage example:
# mpdipod)
#
# Based on idea from: https://bbs.archlinux.org/viewtopic.php?id=116113
## USER CONFIGURATION-----------------------------------------------------
## Path to playlists
playlists="$HOME/.mpd/playlists"
## Prefix and suffix strings for the playlist file name
pl_prefix=''
pl_suffix='.m3u'
## END USER CONFIGURATION--------------------------------------------------
if [ $# -eq 0 ]; then
list=$(ls $playlists)
if [ -n "$pl_prefix" ]; then list=$(echo -e "$list"|sed -ne "s/^$pl_prefix//p"); fi
if [ -n "$pl_suffix" ]; then list=$(echo -e "$list"|sed -ne "s/$pl_suffix$//p"); fi
echo -e "$list"
exit 0
elif [ $# -ne 1 ]; then
echo "`basename $0` takes 0 or 1 input argument"
exit 1
fi
## Get current song from ncmpcpp or cmus or throw an error
song=`ncmpcpp --now-playing '%D/%f' 2>/dev/null` || \
song=`cmus-remote -Q 2>/dev/null | grep file` || \
{ echo "Error: you need either ncmpcpp or cmus installed to run this script. Aborting." >&2; exit 1; }
## Error cases
if [[ -z "$song" ]]; then
echo 'No song is playing.'
exit 1
fi
## Path to lock file
lock="/tmp/mpd-add-current-to-playlist.lock"
## Lock the file
exec 9>"$lock"
if ! flock -n 9; then
notify-send "Operation failed: Another instance is running."
exit 1
fi
## Strip "file " from the output
song=${song/file \///}
## Temporary file for grepping and sorting
tmp="$playlists/tmp.m3u"
## Append the song to the given playlist
if ls $playlists|grep -Fxq "${pl_prefix}$1${pl_suffix}"; then # Does the playlist exist?
if ! grep -Fxq "$song" "$playlists/${pl_prefix}$1${pl_suffix}"; then # The song doesn't already exist in the playlist
f="$playlists/${pl_prefix}$1${pl_suffix}"
mkdir -p "$playlists" # Create the playlists dir if it's not existing; if existing, does nothing
echo "$song" >> "$f"
sort -u "$f" -o "$tmp"
mv -f $tmp $f
echo "\"$song\" added to playlist \"$1\""
else
echo "\"$song was\" already in playlist \"$1\""
fi
else
echo "Playlist \"$1\" doesn't exist. Exiting."
fi
## The lock file will be unlocked when the script ends
To add currently playing song to "ipodplaylist":
mpd_add_current_to_playlist ipodplaylist
Any improvements or suggestions welcome...
Offline
There is also another way to rate songs: mpdcron. Song rating, playcount and many more are stored in sqlite db. For me it is a great solution.
Offline
this is my solution:
http://files.53280.de/vid/MGM5.mp4
i store album ratings in the album folder in a file called rating.txt
track ratings are stored in the tags inside of the comments field.
the rsync command is only, because my mpd is on a remote machine.
code: http://git.53280.de/carnager/scripts/tree/mpdMenu
I hope for this bug to become reality, then one could use ANY tag to e.g. store album ratings.
http://bugs.musicpd.org/view.php?id=3971
Last edited by Rasi (2014-03-12 23:10:21)
He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.
Douglas Adams
Offline
As of ncmpcpp > 0.6 this no longer works as it seems all console commands have been deprecated.
To use MPC instead, simply replace "ncmpcpp --now-playing '%D/%f'" with "mpc -f %file% current" and you should be good to go.
Offline