Example #1
0
    def connect(self):

        # Try up to 10 times to connect to MPD
        self.connection_failed = 0
        self.dataclient = None

        logging.debug(u"Connecting to MPD service on {0}:{1}".format(
            self.server, self.port))

        while True:
            if self.connection_failed >= 10:
                logging.debug(u"Could not connect to MPD")
                break
            try:
                # Connection to MPD
                client = mpd.MPDClient(use_unicode=True)
                client.connect(self.server, self.port)

                self.dataclient = client
                break
            except:
                self.dataclient = None
                self.connection_failed += 1
                time.sleep(1)
        if self.dataclient is None:
            raise mpd.ConnectionError(u"Could not connect to MPD")
        else:
            logging.debug(u"Connected to MPD")
def previousMPD(c):
    print("Previous Song")
    try:
        c.previous()
    except mpd.ConnectionError():
        print("MPD error setting previous song.")
        return False
    return True
def nextMPD(c):
    print("Next Song")
    try:
        c.next()
    except mpd.ConnectionError():
        print("MPD error setting next song.")
        return False
    return True
def StopMPD(c):
    WriteLog("Stopping MPD")
    try:
        c.clear()
        return True
    except mpd.ConnectionError():
        print("StopMPD: MPD error.")
        return False
Example #5
0
 def wrap(*args, **kwargs):
     try:
         return func(*args, **kwargs)
     except (socket.error, mpd.ConnectionError) as e:
         try:
             self._connect()
             return func(*args, **kwargs)
         except (socket.error, mpd.ConnectionError) as e:
             raise mpd.ConnectionError('Cannot establish connection')
def ConnectMPD(c):
    try:
        c.connect(mpdhost, 6600)
        print("Connected to MDP version " + str(c.mpd_version) + ".")
    except mpd.ConnectionError():
        return False
    except socket.error:
        return False

    return True
def SetVolumeMPD(c, vol):
    global nowVolume
    print("Set volume to " + str(vol) + ".")
    nowVolume = vol
    try:
        c.setvol(vol)
    except mpd.ConnectionError():
        print("MPD error setting volume.")
        return False
    return True
Example #8
0
 def fileno(self):
     if not self.connected:
         raise mpd.ConnectionError("Not connected")
     return self.client._sock.fileno()
def DisconnectMPD(c):
    try:
        c.close()
        print("Disconnected from MDP version " + str(c.mpd_version) + ".")
    except mpd.ConnectionError():
        pass