You are not logged in.

#1 2010-11-04 17:05:44

BaconPie
Member
Registered: 2010-08-11
Posts: 209

[SOLVED] MPD Notify

I just moved to MPD from Rhythmbox because I am building a PC remote using a web interface for my phone. MPD is great and I love the whole Client/Server thing but a few things are bugging me and I was just wondering if anyone could shed any light.

First of all (and mainly) Rhythmbox notifies me when it changes track and the program isn't on the screen (minimised or I'm on another workspace). Is it possible for MPD to do this and/or how would I go about writing my own? I am familiar with notify-send and if I'm not mistaken that's what Rhythmbox calls whenever it changes track. How would I get MPD to do this (MPD, not a client because when the client goes away I want it to keep on telling me the song).

Also, I like having all my music just dumped onto the screen so that I can keep it on shuffle and/or live search through it so that it only plays (randomly) what I searched for. Does mpd support this or is it strictly playlist based? Speaking of which, could someone explain to me the general work flow of an mpd client? Is it double click to add to play queue or a playlist? My method of building a playlist of all my songs and putting it on shuffle just seems backwards.

Thanks

Solution: Not quite ideal but Ario uses notification system so I just keep it in my system tray. Just as good as Rhythmbox was.

Last edited by BaconPie (2010-11-05 11:43:49)

Offline

#2 2010-11-04 17:21:35

hokasch
Member
Registered: 2007-09-23
Posts: 1,461

Re: [SOLVED] MPD Notify

A quick search in AUR turned up mpd-libnotify. I believe mpd only works via playlists, but I could be wrong... As for clients, check out mpd wiki, personally I like Sonata but their are even clients for cellphones and web-interfaces.

edit: just skimmed the mpd wiki link - tons of stuff. another notify plugin: http://chadok.info/mpn/
"Workflow" differs from client to client I guess, in Sonata double-click/enter adds the selected songs/folders to the playlist (there are shortcuts, e.g. adding ctrl+d, replacing ctrl+r, for start playing if stopped add shift) .

Last edited by hokasch (2010-11-04 17:28:44)

Offline

#3 2010-11-04 17:28:05

BaconPie
Member
Registered: 2010-08-11
Posts: 209

Re: [SOLVED] MPD Notify

I didn't think to check the AUR after both the links in that thread where dead.

I installed in anyway, how is it used? No notifications so far (after restating mpd).

Offline

#4 2010-11-04 17:32:24

hokasch
Member
Registered: 2007-09-23
Posts: 1,461

Offline

#5 2010-11-04 17:37:42

BaconPie
Member
Registered: 2010-08-11
Posts: 209

Re: [SOLVED] MPD Notify

*facepalm* Ha, thanks.

Offline

#6 2010-11-04 18:05:39

BaconPie
Member
Registered: 2010-08-11
Posts: 209

Re: [SOLVED] MPD Notify

Right, I've installed it from the aur here. And when I run it for the first time it creates this config file:

#!/bin/bash
#
# mpdnotify config - any valid bash is allowed, you
# only need to define handle_event() for the deamon
# to run properly
#
# $mydir exists, and it's value is /home/tom/.config/mpdnotify
#
###

###
#
# the actual handle_event() definition
#
# this is the only requirement for a valid config
#
###

fetch_cover () {
  album=Beautiful Freak
  # do we have a valid album name
  file="/"
  # Does the covers directory exist? Make it if it does not.
  if [ ! -d "" ]; then mkdir -p ""; fi
  # have we not fetched this already
  if [ ! -f "" ] ; then
    echo -n " is not in covers... "
    echo ""
    url="http://www.albumart.org/index.php?srchkey=&itempage=1&newsearch=1&searchindex=Music"
    cover_url=
    # is it available
    if [ -n "" ]; then
      echo retrieved
      wget -q -O "" ""
    else
      echo NOT available 
    fi
  fi
}

handle_event() {
  coverDir="/home/tom/.covers/"
  tmpCover="/tmp/cover"
  baseCover="/usr/share/mpd-libnotify/base.png"
  topCover="/usr/share/mpd-libnotify/top.png"
  noCover="/usr/share/mpd-libnotify/NOCOVER.png"
  mpdPID=17253
  mpcArtist="Could not find Artist's name"
  mpcTitle="Could not find Song's title"
  mpcAlbum="Could not find Album's name"
  mpcLength="Could not find Song's length"

  if [[ -z  ]]; then
    echo "MPD is not currently running!"
    exit
  else
    mpcAlbum=Beautiful Freak
    mpcArtist=Eels
    mpcTitle=Not Ready Yet
    mpcLength=4:47
    if [ -f "" ]; then rm ""; fi
    if [ -f "/" ]; then
      cp "/" ""
      mogrify -resize 65x65! 
      convert  "" -geometry +4+3 -composite  -geometry +0+0 -composite ""
      [[ "0" -gt "25" ]] && mpcArtist=...
      [[ "0" -gt "25" ]] && mpcTitle=...
      [[ "0" -gt "25" ]] && mpcAlbum=...
      notify-send --expire-time=1300 -i "" "MPD Notification" "<u></u>
By: <i></i>
From: <i></i>
Length: <i></i>"
    else
      fetch_cover
      if [ -f "/" ]; then
        cp "/" ""
        mogrify -resize 65x65! 
        convert  "" -geometry +4+3 -composite  -geometry +0+0 -composite ""
        [[ "0" -gt "25" ]] && mpcArtist=...
        [[ "0" -gt "25" ]] && mpcTitle=...
        [[ "0" -gt "25" ]] && mpcAlbum=...
        notify-send --expire-time=1300 -i "" "MPD Notification" "<u></u>
By: <i></i>
From: <i></i>
Length: <i></i>"
      else
        cp "" ""
        mogrify -resize 65x65! 
        convert  "" -geometry +4+3 -composite  -geometry +0+0 -composite ""
        [[ "0" -gt "25" ]] && mpcArtist=...
        [[ "0" -gt "25" ]] && mpcTitle=...
        [[ "0" -gt "25" ]] && mpcAlbum=...
        notify-send --expire-time=1300 -i "" "MPD Notification" "<u></u>
By: <i></i>
From: <i></i>
Length: <i></i>"
      fi
    fi
  fi
}

The next time I run it it gives me this error:

$ mpdnotify
/home/tom/.config/mpdnotify/config: line 53: unexpected argument `]]' to conditional unary operator
/home/tom/.config/mpdnotify/config: line 53: syntax error near `;'
/home/tom/.config/mpdnotify/config: line 53: `  if [[ -z  ]]; then'
[ 04 Nov 2010 18:02 ] :: error: handle_event() not defined, check your config
[tom@kiwi mpdnotify-git]$ mpdnotify start
/home/tom/.config/mpdnotify/config: line 53: unexpected argument `]]' to conditional unary operator
/home/tom/.config/mpdnotify/config: line 53: syntax error near `;'
/home/tom/.config/mpdnotify/config: line 53: `  if [[ -z  ]]; then'
[ 04 Nov 2010 18:04 ] :: error: handle_event() not defined, check your config

Am I supposed to change the variable -z is looking for? Is it PID?

Offline

#7 2010-11-04 19:12:18

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,799
Website

Re: [SOLVED] MPD Notify

hmm something's odd there (i actually wrote the script that that's based on).

obviously this line is pretty fail:

if [[ -z  ]]; then

[[ -z "$somevar" ]] checks if a variable has a value.  also, in the else he then hardcodes some artist/title info?  i think he was testing something at the time you git pulled...

/edit:

and wth is this?

if [ -f "" ]; then rm ""; fi
    if [ -f "/" ]; then
        cp "/" ""

...

Last edited by brisbin33 (2010-11-04 19:16:48)

Offline

#8 2010-11-04 19:14:13

skunktrader
Member
From: Brisbane, Australia
Registered: 2010-02-14
Posts: 1,679

Re: [SOLVED] MPD Notify

and the hardcoding of mpdPID=17253 seems somewhat suspect

Offline

#9 2010-11-04 19:37:36

BaconPie
Member
Registered: 2010-08-11
Posts: 209

Re: [SOLVED] MPD Notify

Soooo, is there another way to get notifications when mpd does something? I'll write it myself but I don't know how to write daemons/check mpd.

Last edited by BaconPie (2010-11-04 19:38:01)

Offline

#10 2010-11-04 19:51:33

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,799
Website

Re: [SOLVED] MPD Notify

you can start with my version, that one works.  just uses dzen instead of libnotify or whatever.

Offline

#11 2010-11-04 20:02:46

BaconPie
Member
Registered: 2010-08-11
Posts: 209

Re: [SOLVED] MPD Notify

brisbin33 wrote:

that one works.

I get an error:

$ sh bashnotify start
bashnotify: line 103: syntax error near unexpected token `<'
bashnotify: line 103: `    done < <(mpc idleloop player) ) &'

Copy/paste from here.

I'm not too sure on the bash to fix it...

Lines 91 -> 110 (It doesn't like the one below handle_event()):

  type -p handle_event || errorout 'handle_event() not defined, check your config'
}

# }}}

### start/stop deamon {{{
start_daemon() {
  [[ -f "$pid" ]] && errorout "file found at $pid, daemon already running?"

  # start listening in background
  ( while read -r; do
      handle_event
    done < <(mpc idleloop player) ) &

  echo $! > "$pid"
}

stop_daemon() {
  if [[ -f "$pid" ]]; then
    kill $(cat "$pid") || errorout 'error stopping daemon'

Last edited by BaconPie (2010-11-04 20:04:28)

Offline

#12 2010-11-04 21:17:10

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,799
Website

Re: [SOLVED] MPD Notify

$ sh bashnotify start

why would you do that? using sh is causing the error (< <( ) is a bashism).

//blue/0/~/ ./bashnotify start
[ 04 Nov 2010 17:15 ] :: NOTE: writing example config to /home/patrick/.bashnotify/config...
[ 04 Nov 2010 17:15 ] :: you should edit this file before starting the deamon

Offline

#13 2010-11-04 21:46:32

BaconPie
Member
Registered: 2010-08-11
Posts: 209

Re: [SOLVED] MPD Notify

Today is not my day...

Thanks.

Offline

#14 2010-11-04 22:22:59

BaconPie
Member
Registered: 2010-08-11
Posts: 209

Re: [SOLVED] MPD Notify

Just for some closure I edited the handle_event() function to be:

handle_event() {
  local songInfo="/home/tom/.bashnotify/songInfo"
  mpc | head -1 > $songInfo
  notify-send "`cat $songInfo`"
  rm -f $songInfo
}

It works but it does that annoying this where the notifications get queued up. I guess this is more of a notify-osd thing. How do I fix it so that when I skip songs fast, the notifications come in real time?

Thanks again.

Last edited by BaconPie (2010-11-04 22:23:41)

Offline

#15 2010-11-04 22:33:07

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [SOLVED] MPD Notify


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#16 2010-11-04 22:41:04

kittykatt
Member
From: Missouri, USA
Registered: 2009-11-04
Posts: 260
Website

Re: [SOLVED] MPD Notify

It seems I never really tested the configuration generated with mpdnotify. How very stupid of me.

Let me fix it and upload a new package.

Last edited by kittykatt (2010-11-04 23:03:13)


- [ My Blog ] | [ AUR Packages ] | [ My deviantART ] | [ screenFetch ] | [ SilverIRC ] -

Offline

#17 2010-11-04 22:43:57

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,799
Website

Re: [SOLVED] MPD Notify

BaconPie wrote:

Just for some closure I edited the handle_event() function to be:

handle_event() {
  local songInfo="/home/tom/.bashnotify/songInfo"
  mpc | head -1 > $songInfo
  notify-send "`cat $songInfo`"
  rm -f $songInfo
}

It works but it does that annoying this where the notifications get queued up. I guess this is more of a notify-osd thing. How do I fix it so that when I skip songs fast, the notifications come in real time?

Thanks again.

FYI: i think you can just do...

handle_event() {  notify-send "$(mpc current)"; }

as for your other issues, i dunno.

Offline

#18 2010-11-04 23:03:38

kittykatt
Member
From: Missouri, USA
Registered: 2009-11-04
Posts: 260
Website

Re: [SOLVED] MPD Notify

My package mpdnotify-git should be fixed now if you would like to try it out again. ^^:


- [ My Blog ] | [ AUR Packages ] | [ My deviantART ] | [ screenFetch ] | [ SilverIRC ] -

Offline

#19 2010-11-04 23:53:34

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,362

Re: [SOLVED] MPD Notify

Why not just use (for example) something like sonata and let it show notifications? Since you're comparing it to Rhythmbox, after all....


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#20 2010-11-05 11:30:30

BaconPie
Member
Registered: 2010-08-11
Posts: 209

Re: [SOLVED] MPD Notify

Sonata doesn't support the newer notification system however airo does. I'll be just using that from now on. Thanks to everyone for all the help!

Last edited by BaconPie (2010-11-05 11:42:31)

Offline

#21 2010-11-05 12:10:57

dmz
Member
From: Sweden
Registered: 2008-08-27
Posts: 881
Website

Re: [SOLVED] MPD Notify

pimpd features three monitor modes; you can run it in
daemonized mode, and it'll execute arbitary commands whenever a song change
occurs. Use with dzen2, xosd or your window manager's native hooks for
notifying. It can also output on STDOUT, either with a full backlog or in
'realtime' mode, keeping a single line always updated with the relevant info.

And for the database thingy... you dont need to update all of it, you can cheat

Offline

Board footer

Powered by FluxBB