View previous topic :: View next topic |
Author |
Message |
oggy n00b
Joined: 28 Oct 2004 Posts: 40
|
Posted: Sat Dec 04, 2004 5:00 pm Post subject: Client for mpd written in python |
|
|
Hi
I have written a simple mpd client in python. I'm just learning the language so it's nothing fancy but it's the first program I've written that I actually *use*
Download here.
The host and password for the mpd server is read from the environment variable MPD_HOST but defaults to localhost port 6600.
Comments welcome
EDIT: pympc is now hosted on sourceforge
Last edited by oggy on Tue Jan 04, 2005 10:42 am; edited 4 times in total |
|
Back to top |
|
|
bennettp Guru
Joined: 22 Feb 2004 Posts: 335 Location: on my back and tumbling
|
Posted: Sun Dec 05, 2004 10:28 am Post subject: |
|
|
Impressive.
Suggestion: Use the environment variables (such as MPD_HOST) to get values such as port, host, password, etc. These should override the config file.
Question: What does the 2nd button from the left do? The "left arrow" button?
Congratulations.
Here's one you might like. It displays some green text at the bottom of the screen whenever the song status changes. Its slow and buggy, but I use it all the time
Requires osd_cat.
Screenie
PS. Nice choice in music, btw. _________________ Registered Linux User #363420 |
|
Back to top |
|
|
oggy n00b
Joined: 28 Oct 2004 Posts: 40
|
Posted: Sun Dec 05, 2004 12:04 pm Post subject: |
|
|
Thank you for your suggestions!
The 2nd button is pause/play. It was the best of the standard icons I could find without drawing one myself .
The environment variables was a much nicer solution - thank you. py-libmpdclient even have support for them so it's even easier.
Updated version uploaded. It alsa fixes the non-working seeking.
The osd script was nice, I've been looking for something like that. Is there someway to make osd_cat output antialiased text? |
|
Back to top |
|
|
bennettp Guru
Joined: 22 Feb 2004 Posts: 335 Location: on my back and tumbling
|
Posted: Sun Dec 05, 2004 12:13 pm Post subject: |
|
|
oggy wrote: | Thank you for your suggestions!
The 2nd button is pause/play. It was the best of the standard icons I could find without drawing one myself .
The environment variables was a much nicer solution - thank you. py-libmpdclient even have support for them so it's even easier.
Updated version uploaded. It alsa fixes the non-working seeking. |
No problemo. The reason I couldn't figure out the button was because it wasn't doing anything, since my server is password protected. This new version should fix the problem, since my password is stored in the MPD_HOST variable.
oggy wrote: | The osd script was nice, I've been looking for something like that. Is there someway to make osd_cat output antialiased text? |
Hah I wish. I think there's a project called "eosd" that provides this, but I never bothered. _________________ Registered Linux User #363420
Last edited by bennettp on Sun Dec 05, 2004 12:19 pm; edited 1 time in total |
|
Back to top |
|
|
bennettp Guru
Joined: 22 Feb 2004 Posts: 335 Location: on my back and tumbling
|
Posted: Sun Dec 05, 2004 12:18 pm Post subject: |
|
|
In the new version: Code: | bennett@perky pympc $ ./pympc.py
Traceback (most recent call last):
File "./pympc.py", line 356, in ?
app.start()
File "./pympc.py", line 48, in start
self.try_connect()
File "./pympc.py", line 57, in try_connect
self.c = mpdclient.MpdController(port=int(port))
File "/usr/lib/python2.3/site-packages/mpdclient.py", line 781, in __init__
MpdConnection.__init__(self, host, port, *args)
File "/usr/lib/python2.3/site-packages/mpdclient.py", line 342, in __init__
self._connect()
File "/usr/lib/python2.3/site-packages/mpdclient.py", line 755, in _connect
self.sock.connect((self._resolveHost(), self.port))
File "/usr/lib/python2.3/site-packages/mpdclient.py", line 750, in _resolveHost
raise MpdUnknownHostError(self.host)
File "/usr/lib/python2.3/site-packages/mpdclient.py", line 96, in __init__
MpdNetError.__init__(self, "host `%(host)s' not found" % host, 11, host)
TypeError: format requires a mapping
bennett@perky pympc $ |
This happens regardless of whether MPD_PORT is set (I usually leave it unset & use the default). _________________ Registered Linux User #363420 |
|
Back to top |
|
|
bennettp Guru
Joined: 22 Feb 2004 Posts: 335 Location: on my back and tumbling
|
Posted: Sun Dec 05, 2004 12:28 pm Post subject: |
|
|
By the way, I started to write a KDE port to pop up a passive dialog, but it only appears at the top-left corner of the screen, and I'd rather it appeared at the bottom-right. (This is due to the code that handles passive dialog boxes -- according to the kdialog changelog, its "a mess"). I can't remember if I finished it or not... but it seems to work. Maybe I should port it to C++, so it runs at a decent speed, and appears in the correct position...
Here's the link. _________________ Registered Linux User #363420
Last edited by bennettp on Sun Dec 05, 2004 1:12 pm; edited 2 times in total |
|
Back to top |
|
|
oggy n00b
Joined: 28 Oct 2004 Posts: 40
|
Posted: Sun Dec 05, 2004 12:34 pm Post subject: |
|
|
I suppose you are using your password in MPD_HOST? MPD_HOST is ultimately used by py-libmpdclient to resolve the hostname of the server so I guess it can't resolve addresses on the form pass@host.
I'm not sure how to make it work but I'll try to look into it. |
|
Back to top |
|
|
bennettp Guru
Joined: 22 Feb 2004 Posts: 335 Location: on my back and tumbling
|
Posted: Sun Dec 05, 2004 12:40 pm Post subject: |
|
|
Ahh duh, I figured out the problem; its my MPD_HOST variable: it's in the format "password@host". This is the format used by mpc(1). Umm is it possible to use a password with libmpdclient? _________________ Registered Linux User #363420 |
|
Back to top |
|
|
bennettp Guru
Joined: 22 Feb 2004 Posts: 335 Location: on my back and tumbling
|
Posted: Sun Dec 05, 2004 12:50 pm Post subject: |
|
|
oggy wrote: | I suppose you are using your password in MPD_HOST? MPD_HOST is ultimately used by py-libmpdclient to resolve the hostname of the server so I guess it can't resolve addresses on the form pass@host.
I'm not sure how to make it work but I'll try to look into it. |
You beat me to it
Umm I'd probably use regexps to split it up. Here's a perl command that'll do it: Code: | echo $MPD_HOST | perl -e '$host = <STDIN>; if ( $host =~ /@/ ) { $pass = $host; $host =~ s/@.+$//; $pass =~ s/^.+@//; print $host; print $pass } else { print $host }'
|
Not sure how much that helps in python, though...
[Edit: updated command: checks if the @ charater exists in the host before splitting it up] _________________ Registered Linux User #363420 |
|
Back to top |
|
|
oggy n00b
Joined: 28 Oct 2004 Posts: 40
|
Posted: Sun Dec 05, 2004 2:00 pm Post subject: |
|
|
Now I've hacked around a bit in libmpdclient With the newest version the following should work (I hope):
Code: | MPD_HOST=pass@host ./pympc.py |
You must use the updated version of mpdclient.py for it to work. |
|
Back to top |
|
|
bennettp Guru
Joined: 22 Feb 2004 Posts: 335 Location: on my back and tumbling
|
Posted: Sun Dec 05, 2004 11:47 pm Post subject: |
|
|
Success! Nicely done. _________________ Registered Linux User #363420 |
|
Back to top |
|
|
rezza Guru
Joined: 09 Apr 2003 Posts: 434 Location: Edinburgh, UK
|
Posted: Mon Dec 06, 2004 2:06 am Post subject: |
|
|
Nice client... not too many features, and since its python, i can get rid of the couple left that i don't need! One question, though - my buttons are always too wide. Any idea why, or how I can fix this? (Note: this happened before I started chopping the interface down, too.)
Thanks for writing this! _________________ screenshots
blog |
|
Back to top |
|
|
oggy n00b
Joined: 28 Oct 2004 Posts: 40
|
Posted: Mon Dec 06, 2004 10:20 am Post subject: |
|
|
Hi, glad you like it.
Don't really know how to make the buttons smaller by default. I'm not too familiar with the gtk widgets.
I have the following two lines in my .gtkrc to reduce the general size of buttons (why buy a big monitor to display large buttons, right ):
Code: | GtkButtonBox::child-min-height = 0
GtkButtonBox::child-min-width = 0 |
|
|
Back to top |
|
|
Swoosh Apprentice
Joined: 19 Sep 2004 Posts: 203
|
Posted: Tue Dec 07, 2004 5:47 pm Post subject: |
|
|
Damn, that is a great mpd client!
I have an issue when playing a stream. The title doesn't update when playing a stream
Code: |
Traceback (most recent call last):
File "./pympc.py", line 310, in update_status
self.gui.progress.set_value(
ZeroDivisionError: float division
|
and if the stream is playing the client fails to launch with the following output
Code: | Traceback (most recent call last):
File "./pympc.py", line 355, in ?
app.start()
File "./pympc.py", line 48, in start
self.try_connect()
File "./pympc.py", line 62, in try_connect
self.update_status()
File "./pympc.py", line 310, in update_status
self.gui.progress.set_value(
ZeroDivisionError: float division |
rezza, how do i make this client look like you've got on your desktop screenshot?
Also, are there any good resources for learning python? |
|
Back to top |
|
|
oggy n00b
Joined: 28 Oct 2004 Posts: 40
|
Posted: Tue Dec 07, 2004 8:09 pm Post subject: |
|
|
I didn't know it was possible to listen to streams. How do you do that? I guess you must add url:s to the library some way but I can't find anything at www.musicpd.org or the man pages.
Anyway; I suppose streams have zero length and it crashes with a division by zero. Added a simple fix for it. |
|
Back to top |
|
|
Swoosh Apprentice
Joined: 19 Sep 2004 Posts: 203
|
Posted: Tue Dec 07, 2004 9:17 pm Post subject: |
|
|
oggy wrote: | I didn't know it was possible to listen to streams. How do you do that? I guess you must add url:s to the library some way but I can't find anything at www.musicpd.org or the man pages.
Anyway; I suppose streams have zero length and it crashes with a division by zero. Added a simple fix for it. |
Add a playlist file as an .m3u with the URLs of the stream (you can make this using bmp or xmms) to the playlist directory as configured in your mpd config, then create the database.
As for the fix that you applied, I downloaded another copy and am still having the same problem. |
|
Back to top |
|
|
oggy n00b
Joined: 28 Oct 2004 Posts: 40
|
Posted: Tue Dec 07, 2004 11:34 pm Post subject: |
|
|
Swoosh wrote: |
Add a playlist file as an .m3u with the URLs of the stream (you can make this using bmp or xmms) to the playlist directory as configured in your mpd config, then create the database. |
Thanks. It's easier to make something if you can test it.
Swoosh wrote: |
As for the fix that you applied, I downloaded another copy and am still having the same problem. |
Strange. Division by zero should be impossible - I've added checks at all places division takes place. You are positiv you have the latest version? Please try the version I uploaded just now. Playlists could not be used at all before - now all playlists is presented last in the library just as in ncmpc:
Code: | Library:
dir1
dirN
file1
fileN
*playlist1*
*playlistN*
|
Streams also work, at least the first one I found on google, http://oggtrial.nm.cbc.ca:80/cbcr1-toronto.ogg . |
|
Back to top |
|
|
rezza Guru
Joined: 09 Apr 2003 Posts: 434 Location: Edinburgh, UK
|
Posted: Wed Dec 08, 2004 11:11 am Post subject: |
|
|
oggy wrote: | Hi, glad you like it.
Don't really know how to make the buttons smaller by default. I'm not too familiar with the gtk widgets.
I have the following two lines in my .gtkrc to reduce the general size of buttons (why buy a big monitor to display large buttons, right ):
Code: | GtkButtonBox::child-min-height = 0
GtkButtonBox::child-min-width = 0 |
|
I got it fixed... now I got the client looking just right! _________________ screenshots
blog |
|
Back to top |
|
|
Swoosh Apprentice
Joined: 19 Sep 2004 Posts: 203
|
Posted: Wed Dec 08, 2004 5:11 pm Post subject: |
|
|
Works fine now, thanks.
Only one more issue , the client doesn't seem to read the ID3 tags.
Is it supposed to?/Could you add support for this, please? |
|
Back to top |
|
|
landon Apprentice
Joined: 09 Mar 2004 Posts: 159
|
Posted: Thu Dec 09, 2004 7:33 am Post subject: |
|
|
How do I start it?
Is it a simple $ ./pympc.py ?
Also, could you guys post your pympcrc for my perusal? I don't really know the syntax required to set it all up. |
|
Back to top |
|
|
oggy n00b
Joined: 28 Oct 2004 Posts: 40
|
Posted: Thu Dec 09, 2004 7:48 am Post subject: |
|
|
landon wrote: | How do I start it?
Is it a simple $ ./pympc.py ?
Also, could you guys post your pympcrc for my perusal? I don't really know the syntax required to set it all up. |
Yes.
The configurationfile isn't used anymore - it uses the environment variable MPD_HOST to specify host and port of the server.
But the configfile will make a comeback in the next version. |
|
Back to top |
|
|
landon Apprentice
Joined: 09 Mar 2004 Posts: 159
|
Posted: Thu Dec 09, 2004 9:23 am Post subject: |
|
|
Great! I didn't realise that it was so simple.
And yeah, implementations of .pympc would be awesome.
I have a quick question for you regarding the script (since I'm not too familiar with python atm) :
I've noticed that it renders the window width based on the longest file name (I could be wrong.) Is there any code I should augment in order to get it to display @ a fixed width? I'm trying to slim it down as much as possible (it's not your fault; I have a smallish monitor, and I'm trying to conserve as much space as possible.)
edit:// I was totally out of line. The width is determined mostly by the buttons up top ('+ volume + random' area.) I guess it's just a gtkrc modification I should look into. While I'm on the topic, how do I modify the height of the window (unless it too is a gtk thing?) |
|
Back to top |
|
|
oggy n00b
Joined: 28 Oct 2004 Posts: 40
|
Posted: Thu Dec 09, 2004 10:26 am Post subject: |
|
|
New version uploaded. Changes:
* Window size configurable via ~/.pympcrc
* ID3 tags supported. One or more columns with info in the playlist. Configurable - see pympcrc.sample.
* Reordering of playlist by drag and drop. You can only move one file at the time.
* Selection of multiple entries works better.
landon wrote: | The width is determined mostly by the buttons up top ('+ volume + random' area.) |
Yeah, I don't know how to make the buttons smaller by default. It's possible to set a fixed pixelsize for them but I don't think that's a very nice solution. Maybe it breaks if you have different gtk themes. As a workaround see my earlier post as how to make the buttons less bloated. |
|
Back to top |
|
|
rezza Guru
Joined: 09 Apr 2003 Posts: 434 Location: Edinburgh, UK
|
Posted: Thu Dec 09, 2004 2:24 pm Post subject: |
|
|
oggy wrote: | New version uploaded. Changes:
* Window size configurable via ~/.pympcrc
* ID3 tags supported. One or more columns with info in the playlist. Configurable - see pympcrc.sample.
* Reordering of playlist by drag and drop. You can only move one file at the time.
* Selection of multiple entries works better.
landon wrote: | The width is determined mostly by the buttons up top ('+ volume + random' area.) |
Yeah, I don't know how to make the buttons smaller by default. It's possible to set a fixed pixelsize for them but I don't think that's a very nice solution. Maybe it breaks if you have different gtk themes. As a workaround see my earlier post as how to make the buttons less bloated. |
I made the buttons smaller by getting rid of the hbuttonbox entirely, and just packing the buttons individually at the start of the hbox - for some reason the hbuttonbox was making the buttons way too wide, even with the expand=False option.
Oh, and thanks for the update! I'll be merging your changes into mine _________________ screenshots
blog |
|
Back to top |
|
|
landon Apprentice
Joined: 09 Mar 2004 Posts: 159
|
Posted: Thu Dec 09, 2004 7:48 pm Post subject: |
|
|
@ Oggy: Awesome! I can't wait to see it in it's final dev stages. I love clean + minimalistic & yet functional apps, and this fits the pill perfectly.
@ Rezza: Your screenshot is an ideal one. Do you think you could post the modifications you've made to either the .py script, or to the gtkrc? (if it's not too much to ask) |
|
Back to top |
|
|
|