コード例 #1
0
ファイル: hdbus.py プロジェクト: jldupont/rb-mpdbus
    def hEntryPlaying(self, _, entry, ed):
        """
        Message Bus handler
        """
        self.TrackChange(ed)

    def sRateCurrentPlaying(self, rating):
        """
        DBus signal handler - /Player/RateCurrentPlaying
        """
        Bus.publish(self, "rate-current", rating)
    

player=hPlayer()
Bus.subscribe("entry-playing", player.hEntryPlaying)
dbus.Bus().add_signal_receiver(player.sRateCurrentPlaying, 
                               signal_name="RateCurrentPlaying", 
                               dbus_interface="org.freedesktop.MediaPlayer", 
                               bus_name=None, 
                               path="/Player")


class hTrack(dbus.service.Object):
    """
    DBus signals for the /Track path
    """
    PATH="/Track"
    
    def __init__(self):
        dbus.service.Object.__init__(self, dbus.SessionBus(), self.PATH)
コード例 #2
0
ファイル: user.py プロジェクト: jldupont/dbus_lastfm
        """
        Performs 'dependency checks' of the received
        parameters against the 'root parameters'
        """
        for key in iparams:
            if key in self.rootParams:
                self._updateParams({"auth_token":"", "token":""})
                self.q_user_params()
                break
            
        
    
## ========================================================== Bus Interfacing
    
user=User()
Bus.subscribe("user_params?", user.q_user_params)
Bus.subscribe("user_params",  user.h_user_params)
Bus.subscribe("method_call",  user.h_method_call)

## ========================================================== TESTS

if __name__ == '__main__':
    class Logger(object):
        def __call__(self, msgType, e):
            print "Logger: Error: msgType(%s) Exception(%s)" % (msgType, str(e))
    
    class Test(object):
        def handler(self, msgType, params):
            print params

    Bus.logger=Logger()
コード例 #3
0
ファイル: track.py プロジェクト: jldupont/rb-mpdbus
            print "setRating: exception(%s)" % str(e)

    def setRatings(self, entries, rating):
        """
        Set the rating of a batch of entries
        """

        def _rate(model, _path, iter):
            entry = model.get(iter, 0)[0]
            self.db.set(entry, rhythmdb.PROP_RATING, rating)

        entries.foreach(_rate)


th = TrackHelper()
Bus.subscribe("db", th.hDb)


class TrackHandler(object):
    def __init__(self, trackHelper):
        self.th = trackHelper
        self.currentEntry = None

    def hEntryPlaying(self, _, entry, _entryDic):
        """
        Intercepts the current playing entry
        """
        self.currentEntry = entry

    def hRateCurrent(self, _, rating):
        """
コード例 #4
0
ファイル: logger.py プロジェクト: jldupont/dbus_lastfm
"""
    @author: jldupont

    Created on 2010-02-01
"""
from twisted.python import log
from mbus import Bus

class Logger(object):
    """
    Simple Logger
    """
    def _log(self, _, _msg):
        log.msg(_msg)

logger=Logger()
Bus.subscribe("log", logger._log)
コード例 #5
0
ファイル: ws_method.py プロジェクト: jldupont/dbus_lastfm
        
        if ws_method.is_error():
            cdic["e"](["error", ws_method.get_error()])
            return       
        
        ctx=(ws_method.method, cdic, udic)        
        make_ws_request(ctx, ws_method.url, http_method=ws_method.http_method, postdata=ws_method.body)        
        
    def _session_required_flow(self, mdic, cdic, udic):
        """
        A session must be authenticated before calling the method
        
        We need to have a "token" as starting point 
        """
        #Bus.publish(self, "log", "_session_required_flow: mdic(%s)" % mdic)
        
        auth_token=udic.get("auth_token", "")
        if not auth_token: 
            cdic["e"](["error", "session_required"])
            return
        
        cdic.update({"original_mdic":mdic})
        Bus.publish(self, "method_call", {"method":"auth.getSession"}, cdic)


wsh=WsMethodHandler()
Bus.subscribe("umethod_call", wsh.h_umethod_call)

## Test string for 'track.getTags'
#"depeche mode", "little 15"
コード例 #6
0
ファイル: player.py プロジェクト: jldupont/rb-mpdbus
            self.db.set(entry, rhythmdb.PROP_RATING, fvalue)
        except:
            print "setRating: expecting a float for 'rating', got: %s" % rating
        
    def setRatings(self, entries, rating):
        """
        """
        def _rate(model, _path, iter):
            entry=model.get(iter, 0)[0]
            self.db.set(entry, rhythmdb.PROP_RATING, rating)
            
        entries.foreach(_rate)

    
th=TrackHelper()
Bus.subscribe("db",     th.hDb)
    
    

class TrackHandler(object):
    def __init__(self, trackHelper):
        self.th=trackHelper
        self.currentEntry=None
    
    def hEntryPlaying(self, _, entry):
        """
        Intercepts the current playing entry
        """
        self.currentEntry=entry

    
コード例 #7
0
ファイル: ws_response.py プロジェクト: jldupont/dbus_lastfm
        Bus.publish(self, "log", "h_auth_gettoken, status: %s" % status)
        
        if status!="200":
            cdic["e"](["error", "method_failed", "Cannot retrieve 'auth token' from Last.fm"])
            return
            
        if not response:
            cdic["e"](["error", "invalid_response", "Invalid response received from Last.fm"])
            return
            
        match=re.search("\<token\>(.*)\<\/token\>", response)
        if match is None:
            cdic["e"](["error", "token_missing", "Missing 'auth token' from Last.fm response"])
            return
        
        auth_token=match.group(1)
        Bus.publish(self, "user_params", {"auth_token":auth_token, "token":""})        
        
        api_key=udic.get("api_key", "")
        
        ## Return URL that must be used by the user for authentication
        ## ===========================================================
        url=self.auth_url % (api_key, auth_token)
        cdic["c"](["ok", url])

   
   
wsrh=WsResponseHandler()
Bus.subscribe("ws_response", wsrh.h_ws_response)