SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2012-11-05 23:50:50

mosesgunn
#! CrunchBanger
Registered: 2012-10-20
Posts: 133

MPD Pipe Menu Error

I am starting to enter into the world of pipemenus!  But I have not been able to get one particular pipemenu working, a python mpd script.
I made a ,py file with the code o found on benj1's ultimate pipemenu thread.  I made it executable and made a pipemenu entry using the ob gui editor - and I am getting the following error when I try to access the pipemenu.

Failed to execute command for pipe-menu "home/manning/bin/mpd-menu.py": Failed to execute child process for pipe-menu "home/manning/bin/mpd-menu.py" (Permission Denied)

 

Here is the code I am using:

#!/usr/bin env python
#
# Author: Ben Holroyd <holroyd.ben@gmail.com>
# License: GPL 3.0+
#
# This script requires python-mpd
#
# Usage:
# Put an entry in ~/.config/openbox/menu.xml:
# <menu id="mpd" label="MPD" execute="~/.config/openbox/scripts/ompb.py" />
#
import mpd, os, sys, socket
mpdport = 6600
musicfolder ='/home/manning/music'
filelist = True  #potentially slow and unwieldy with a large collection of music
playlist = True #same for this
program = sys.argv[0]

client = mpd.MPDClient()  
try:
    client.connect("localhost", mpdport)    
except socket.error:
    print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
    print "<openbox_pipe_menu>"
    print "  <item label=\"MPD not running, click to start\">"
    print "    <action name=\"Execute\"><execute>mpd</execute></action>"
    print "  </item>"
    print "</openbox_pipe_menu>"
    sys.exit(0)    

song = client.currentsong()                      
stats = client.stats()
status = client.status() 

def play():
    if status['state'] == "stop" or status['state'] == "pause":
        client.play()
    elif status['state'] == "play":
        client.pause()
    
def volume(vol):
    if vol == "up":
        client.setvol(int(status['volume'])+10)
    elif vol == "down":
        client.setvol(int(status['volume'])-10)
           
try:
    if (sys.argv[1] == "play"):       play()
    elif (sys.argv[1] == "stop"):     client.stop()
    elif (sys.argv[1] == "prev"):     client.previous()
    elif (sys.argv[1] == "next"):     client.next()
    elif (sys.argv[1] == "add"):      client.add(sys.argv[2]); client.play()
    elif (sys.argv[1] == "clear"):    client.clear()
    elif (sys.argv[1] == "volume"):   volume(sys.argv[2])
    elif (sys.argv[1] == "playlist"): 
        client.delete(client.playlist().index(sys.argv[2]))
    elif sys.argv[1] == "random":
        client.random(int(not int(client.status()['random'])and True or False))
    elif sys.argv[1] == "repeat":
        client.repeat(int(not int(client.status()['repeat'])and True or False))
except IndexError:
    pass

def item_entry(indent, label, option = '', song = ''):
    """label = label on menu, option = play/pause/stop etc, song = path to song  """
    print "%s<item label=\"%s\">"%(indent, label)
    print "%s  <action name=\"Execute\"><execute>%s %s '%s'</execute></action>" % (indent, program, option, song)
    print "%s</item>" % (indent)
    
def file_walk(dir,indent):
    """ walks through music directory building a menu to view albums"""
    files = os.listdir(dir)
    files.sort()
    for file in files:
        path = os.path.join(dir,file)
        if os.path.isdir(path):
            print "%s<menu id=\"%s\" label=\"%s\">"%(indent, file, file)
            item_entry(indent+'  ','Add all to playlist','add' ,path.replace(musicfolder,''))
            print "%s  <separator />" % indent
            file_walk(path,indent+'  ')
            print "%s</menu>" % indent
        else:
            item_entry(indent,file,'add',path.replace(musicfolder,''))          
    indent = indent[2:]

def track_info(label):
    print "  <menu id=\"%s\" label=\"%s\">"%(label,label)
    print "    <item label=\"Artist: %s\"/>" % song['artist']
    print "    <item label=\"Album: %s\"/>" % song['album']
    print "    <item label=\"Tracklength: %.2f\"/>" % ((int(song['time'])/60)+(int(song['time'])%60.0/100))  
    print "    <item label=\"Track: %s\"/>" % song['track']
    print "    <item label=\"filetype: %s\"/>" % song['file'][song['file'].rfind('.')+1:]
    #print "    <item label=\"Genre: %s\"/>" % song['genre']
    print "  </menu>"


print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
print "<openbox_pipe_menu>"
if status['state'] != "stop":
    track_info("Playing: %s - " % song['artist'])
    track_info(song['title'])
    print "  <separator />"
print "  <item label=\"Status: %s\"/>" % {'play':'Playing','pause':'Paused','stop':'Stopped'}[status['state']]    
print "  <separator />"
item_entry('  ', 'Play/Pause', 'play')    
item_entry('  ', 'Stop', 'stop')
item_entry('  ', 'Prev', 'prev')
item_entry('  ', 'Next', 'next')
print "  <separator />"
if filelist == True:
    print "  <menu id=\"Albums\" label=\"Albums\">"
    file_walk(musicfolder,'  ')
    print "  </menu>"
    print "  <separator />"
if playlist == True:
    print "  <menu id=\"Playlist\" label=\"Playlist\">"
    print "    <item label=\"Click to remove from playlist\"/>"
    print "    <separator />"
    for entries in client.playlist():
        item_entry('    ', entries, 'playlist', entries)
    print "  </menu>"
    print "  <separator />"
item_entry('  ', 'Clear Playlist', 'clear')
item_entry('  ', 'Random %s' % (int(status['random']) and '[On]' or '[Off]'), 'random')    
item_entry('  ', 'Repeat %s' % (int(status['repeat']) and '[On]' or '[Off]'), 'repeat')    
print "  <menu id=\"volume\" label=\"Volume [%s]\">" % (int(status['volume']) > 0 and status['volume']+'%' or 'mute') 
item_entry('    ', 'Volume + 10\% ', 'volume up')
item_entry('    ', 'Volume - 10\%', 'volume down')
print "  </menu>"
print "  <separator />"
print "  <menu id=\"stats\" label=\"Database Stats\">"
print "    <item label=\"Artists in database: %s\"/>" % stats['artists']
print "    <item label=\"Albums in database: %s\"/>" % stats['albums']
print "    <item label=\"Songs in database: %s\"/>" % stats['songs']
print "  </menu>"
print "</openbox_pipe_menu>"
exit 0

Thanks for any input!!  I am diggin this crunchbang community!!!

Offline

Be excellent to each other!

#2 2012-11-05 23:58:15

dura
Bloated Gimp
From: interzone
Registered: 2012-09-15
Posts: 2,108

Re: MPD Pipe Menu Error

Just a wild guess:

Do you need to change user permissions on that file?

ugo+x ?

edit: you probably know a lot more than me about this, and might as well ignore me  cry

Last edited by dura (2012-11-06 00:01:31)

Offline

#3 2012-11-06 13:33:54

mosesgunn
#! CrunchBanger
Registered: 2012-10-20
Posts: 133

Re: MPD Pipe Menu Error

Yeah, the file is executable and has permission.
I've given it all the same permissions as other pipe-menus that I have run in the past.

Offline

#4 2012-11-10 16:17:54

VastOne
#! Ranger
From: V-Ger
Registered: 2011-04-26
Posts: 10,165
Website

Re: MPD Pipe Menu Error

Test response, please disregard


VSIDO | Words That Build Or Destroy

We do not run from challenges, they become new innovations within VSIDO!

Offline

#5 2012-11-18 11:50:57

helcioajr
New Member
Registered: 2012-11-16
Posts: 2

Re: MPD Pipe Menu Error

Hi, try on the Terminal:

sudo chmod u+x home/manning/bin/mpd-menu.py

and pass "/home/manning/bin/mpd-menu.py" to menu.xml.
I had the exact same problem and this solved for me.

Last edited by helcioajr (2012-11-18 12:26:04)


"in code we trust"

Offline

#6 2012-11-18 23:39:58

mosesgunn
#! CrunchBanger
Registered: 2012-10-20
Posts: 133

Re: MPD Pipe Menu Error

Hmm thanks helcloajr.  I'm still getting the same error.  I'll reboot later and see if that helps.

Offline

#7 2012-11-19 09:04:22

xaos52
The Good Doctor
From: Planet of the @s
Registered: 2011-06-24
Posts: 4,602

Re: MPD Pipe Menu Error

First line of your script should be

#!/usr/bin/env python

The last line

sys.exit(0)

Offline

#8 2012-11-19 12:44:37

mosesgunn
#! CrunchBanger
Registered: 2012-10-20
Posts: 133

Re: MPD Pipe Menu Error

Hmm thanks xaos52!  Now i am getting this error

Invalid output from pipe-menu "/home/manning/bin/mpd-menu.py"

I feel like i'm so close!

Offline

#9 2012-11-19 14:24:21

xaos52
The Good Doctor
From: Planet of the @s
Registered: 2011-06-24
Posts: 4,602

Re: MPD Pipe Menu Error

Run the script in a terminal window and check the output.
Also, check in rc.xml if you defined the entry as a menu or as a menu item.

Offline

#10 2012-11-19 15:06:55

mosesgunn
#! CrunchBanger
Registered: 2012-10-20
Posts: 133

Re: MPD Pipe Menu Error

Hmm.  It didn't give me any errors running it in the terminal.  I searched for the .py file in rc.xml.  what should i be looking for?

Thanks xaos52!

Offline

#11 2012-11-19 15:16:00

mosesgunn
#! CrunchBanger
Registered: 2012-10-20
Posts: 133

Re: MPD Pipe Menu Error

Oh, i couldnt find a mpd-menu.py entrance.

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo