PDA

View Full Version : a NowPlaying screenlet player for mpd/lastfmproxy


atie
May 2nd, 2007, 04:19 AM
I told that I needed that player(actually utility to get album cover) for [url=http://forum.beryl-project.org/viewtopic.php?f=38&t=4973:a704a]NowPlaying[/url:a704a] screenlet. So I made this [url=http://kldp.org/files/LFProxy.py_.txt:a704a]one[/url:a704a].

screenshot: http://kldp.org/files/2007-5May2.png

If someone has same need like me and wants to use LFProxy.py with NowPlaying screenlet, hope these steps help.
- put Sonata's [url=http://svn.berlios.de/wsvn/sonata/trunk/mpdclient3.py?op=file&rev=0&sc=0:a704a]mpdclient3.py[/url:a704a] into same directory as NowPlayingScreenlet.py
- Modify 48~49 lines of NowPlayingScreenlet.py as below
[code:a704a] 'Exaile':'ExaileAPI',
'LFProxy':'LFProxyAPI'}[/code:a704a]
- Put LFProxy.py under NowPlaying's Player directory.
- That's all. Restart the screenlet and enjoy your musics with mpd/lastfmproxy and album covers.

In case you switch to a GUI player after using LFProxy.py, you need to stop mpd otherwise covers don't show up for the GUI player.

[url=http://www.deviantart.com/deviation/40223310/?qo=5&q=by%3Acrni-ob&qh=sort%3Atime+-in%3Ascraps:a704a]Background[/url:a704a]
The NowPlaying theme on my screenshot above uses pngs from [url=http://www.kde-look.org/content/show.php/45+Amarok?content=56959:a704a]45-Amarok[/url:a704a], FYI ;)

muadib
June 22nd, 2007, 04:37 PM
:mrgreen: thank you, works fine!

mots
June 30th, 2007, 12:57 PM
Very nice :>. I wonder if someone could modify it to work with MPD/Sonata?
EDIT: tried it myself from scratch, didn't seem to work... here's what I have so far:
[code:8c667]#!/usr/bin/env python

# MPD API

import os
import dbus
import string
import gobject
import mpdclient
from GenericPlayer import GenericAPI

class MPDAPI(GenericAPI):
__name__ = 'MPD API'
__version__ = '0.1'
__author__ = 'mots'
__desc__ = 'API to the Music Player Daemon'

host='localhost'
port=6600

playerAPI = None

__timeout = None
__interval = 2

callbackFn = None
__curplaying = None

# Extended Functions from the GenericAPI

def __init__(self, session_bus):
GenericAPI.__init__(self, session_bus)

def is_active(self, dbus_iface):
try:
self.mpd = mpdclient.MpdController(host,port)
return True
except:
return False


def connect(self):
self.playerAPI = self.mpd

def get_title(self):
return self.playerAPI.getCurrentSong().title

def get_album(self):
return self.playerAPI.getCurrentSong().album

def get_artist(self):
return self.playerAPI.getCurrentSong().artist

def get_cover_path(self):
#return self.playerAPI.GetPlayingCoverUri()

def is_playing(self):
if self.playerAPI.status().stateStr() == 'play': return True
else: return False

def play_pause(self):
if self.playerAPI.status().stateStr() == 'play':
self.playerAPI.pause()
else:
self.playerAPI.play()

def next(self):
self.playerAPI.next()

def previous(self):
self.playerAPI.prev()

def register_change_callback(self, fn):
self.callback_fn = fn
# Could not find a callback signal for MPD, so just calling after some time interval
if self.__timeout:
gobject.source_remove(self.__timeout)
self.__timeout = gobject.timeout_add(self.__interval * 1000, self.info_changed)

def info_changed(self, signal=None):
# Only call the callback function if Data has changed
if self.__timeout:
gobject.source_remove(self.__timeout)
try:
if self.__curplaying != None and not self.is_playing():
self.__curplaying = None
self.callback_fn()

playinguri = self.playerAPI.GetPlayingUri()
if self.is_playing() and self.__curplaying != playinguri:
self.__curplaying = playinguri
self.callback_fn()
self.__timeout = gobject.timeout_add(self.__interval * 1000, self.info_changed)
except:
# The player exited ? call callback function
self.callback_fn()[/code:8c667]

hells_dark
October 11th, 2007, 02:55 PM
Can we use nowPlayingScreenlet with mpd ???

I did not understand..

chh.gx7
January 8th, 2008, 10:43 PM
I'm still uncomfortable to publish this code, but someone at dA asked me sort of howto after seeing my screenshot (http://forum.compiz-fusion.org/showthread.php?t=4743&page=12) so here we go.

First, get lastfmproxy 1.3 from here (http://vidar.gimp.org/?page_id=50). Then, modify config.py with your lastfm userid and password. This point, you're able to listen last.fm with your web browser by opening http://localhost:1881. For further detail, look at README.txt.

Second, install mpd, mpc, curl (and ncmpc as option) and use this helper script which I got from the net.
lf-mpd.sh

#!/bin/sh
LASTFMPROXY_DIR=/your/path/to/lastfmproxy
LASTFMPROXY_PIDFILE=/your/path/to/lastfmproxy/lastfmproxy.pid
LASTFMPROXY_SERVER=http://localhost:1881

case $1 in
start)
$0 stop
cd $LASTFMPROXY_DIR
./main.py 2>&1 > /dev/null &
echo $! > $LASTFMPROXY_PIDFILE
sleep 3
mpc add $LASTFMPROXY_SERVER/lastfm.mp3
mpc play
;;
stop)
if [ -f $LASTFMPROXY_PIDFILE ]; then
kill $(cat $LASTFMPROXY_PIDFILE)
rm -f $LASTFMPROXY_PIDFILE
fi
mpc clear
;;
station)
$LASTFMPROXY_DIR/changestation.py $2
;;
skip)
curl $LASTFMPROXY_SERVER/skip
;;
ban)
curl $LASTFMPROXY_SERVER/ban
;;
love)
curl $LASTFMPROXY_SERVER/love
;;
*)
echo $0: invalid argument
;;
esac

Don't forget to change "/your/path/to/ (I use my homedir /bin). Now, from the command line, you can simply do
lf-mpd.sh start
lf-mpd.sh stop
lf-mpd.sh station lastfm://artist/dido (so far so good? If not, read the README.txt)

Now, third, get the attachement and extract
- NowPlayingScreenlet.py and mpdclient3.py to your NowPlaying folder. ( I guess it's usually ~/.screenlets/NowPlaying )
- LFProxy.py to NowPlaying/Players folder.

I put all necessary changes mentioned on the first post so don't worry about.

Note:
- This vesion of LFProxy player stores album art to ~/.covers folder so if it's complained create the folder. And, clean up some garbages in the folder once in a while, you'll see what I mean garbage.
- Lastfmproxy dumps song's info to http://localhost:1881/np since the 1.3 version so for hack look at that info.
- Depending on your net (I guess) there is lag between mpd's song (slow) and cover art (fast), in this case simply do lf-mpd.sh stop and lf-mpd.sh start :D
- Also, either NowPlaying or LFProxy takes bigger memory after listening for long while, just turn off/on NowPlaying :D

I think I put all so enjoy, and please don't ask further since I don't know further either. ;)

hells_dark
April 28th, 2008, 09:42 PM
It still doesnt work. I thought it was ok :(
http://forum.compiz-fusion.org/showthread.php?t=8003