You are not logged in.
Pages: 1
Hello all.
How to get current playing artist\ song from mpd.
In Python\Perl or ruby?)
Offline
Hello all.
How to get current playing artist\ song from mpd.
In Python\Perl or ruby?)
There is no need for python/perl/ruby to do this, the easiest way to do this is via mpc (which is small! and shouldn't be a problem), just running "mpc" gives something like:
Infected Mushroom - Disco Mushroom
[playing] #12/12 4:13/8:47 (48%)
volume: 90% repeat: off random: off
And you can use head to get the first line (Infected Mushroom - Disco Mushroom in this case):
mpc | head -1
Will gives you the first line. I do not know about Perl or Ruby but Python has built in so you can run programs from the shell within a python program.
Last edited by patogen (2008-08-08 12:11:34)
We met up with the aliens and guess what? They have no word for fluffy!
Offline
Hm...Thank.
Me need clean programm\script with don't installed other programms
Offline
telnet, the commands are on the mpd website
-$: file /dev/zero
/dev/zero: symbolic link to '/dev/brain'
Offline
There is ruby-mpd in community, although I think it's outdated. It still seems to work for me:
[nogoma@alfheim:~/src/3rdparty/wmii]% irb
ruby>> require 'mpd'
# => true
ruby>> m = MPD.new('localhost')
# => #<MPD:0xb78f82a4 @debug_socket=false, @mpd_version=nil, @allow_toggle_states=true, @socket=nil, @mpd_port=6600, @overwrite_playlist=true, @mpd_host="localhost", @password=nil, @error=nil>
ruby>> p "#{m.currentsong.artist} - #{m.currentsong.title}"
"The Kooks - Hateful Of Love"
-nogoma
---
Code Happy, Code Ruby!
http://www.last.fm/user/nogoma/
Offline
you can do it easily with python and python-mpd
import mpd
## Connect to mpd client ###
client = mpd.MPDClient()
client.connect("localhost", 6600)
## Get current song info ###
curSongInfo = client.currentsong()
print "\n\n", curSongInfo['artist'] + " - " + curSongInfo['title'] + "\n"
Offline
Me showed this error
AttributeError: 'module' object has no attribute 'MPDClient' :'(
how to fix?
Last edited by Dimon-z (2008-08-08 20:24:42)
Offline
have you got python-mpd installed?
Offline
yes
Offline
This is how I do it:
file getsong:
#!/bin/bash
echo -e "status\\nclose" | nc $MPD_HOST 6600 | is_mpd_playing.pl && echo -e "currentsong\\nclose" | nc $MPD_HOST 6600 | parse_song_info.pl
file is_mpd_playing.pl:
#!/usr/bin/env perl
use strict;
my $exit = -1;
while(<>) {
chomp;
if(/state: (.*)/) {
my $state = $1;
if($state =~ /stop/ or $state =~ /pause/) {
$exit = 1;
} elsif($state =~ /play/) {
$exit = 0;
}
last;
}
}
exit $exit;
file parse_song_info.pl:
#!/usr/bin/perl
use strict;
my($artist, $title);
while(<>) {
chomp;
/Artist: (.*)/ and $artist = $1;
/Title: (.*)/ and $title = $1;
}
$artist and $title and print "$artist :: $title\n";
Offline
thx, i reinstall python-mpd and all worked
How to make: if current song changed, print new song\artist name?)
Thanks
Offline
Just do a loop:
import time
lastSong = None
while True:
currentSong = client.currentsong()
if currentSong != lastSong:
print "\n\n", currentSong['artist'] + " - " + currentSong['title'] + "\n"
lastSong = currentSong
time.sleep(2) #change this to however often you wanna poll.
blog - github - facebook - google profile
Offline
Hm...
If i using u code my irc client is freezing(((
Client xChat
Last edited by Dimon-z (2008-08-13 13:02:11)
Offline
Hmm works fine here... No idea what it has to do with irc client.
blog - github - facebook - google profile
Offline
Pages: 1