当前位置: 首页>>代码示例>>Python>>正文


Python MPDClient.password方法代码示例

本文整理汇总了Python中mpd.MPDClient.password方法的典型用法代码示例。如果您正苦于以下问题:Python MPDClient.password方法的具体用法?Python MPDClient.password怎么用?Python MPDClient.password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mpd.MPDClient的用法示例。


在下文中一共展示了MPDClient.password方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: wrapper

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import password [as 别名]
    def wrapper(request):
        client = MPDClient()
        try:
            client.connect(settings.MPD_HOST, settings.MPD_PORT)
            if settings.MPD_PASSWORD:
                client.password(settings.MPD_PASSWORD)
            result = func(client) or {"success": True}
        except (MPDError, IOError) as e:
            result = {
                "success": False,
                "error": _("Error while executing %(command)s: %(error_message)s")
                % {"command": func.__name__, "error_message": e},
            }
        finally:
            try:
                client.close()
                client.disconnect()
            except ConnectionError:
                pass

        # add a success key in the result dict if not already present.
        result.setdefault("success", True)

        data = json.dumps(result)
        return HttpResponse(data, content_type="application/json")
开发者ID:rafikdraoui,项目名称:vortex,代码行数:27,代码来源:views.py

示例2: wrapper

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import password [as 别名]
    def wrapper(request):
        client = MPDClient()
        try:
            client.connect(settings.MPD_HOST, settings.MPD_PORT)
            if settings.MPD_PASSWORD:
                client.password(settings.MPD_PASSWORD)
            result = func(client) or {'success': True}
        except (MPDError, IOError) as e:
            result = {
                'success': False,
                'error': _(
                    'Error while executing %(command)s: %(error_message)s'
                ) % {'command': func.__name__, 'error_message': e}
            }
        finally:
            try:
                client.close()
                client.disconnect()
            except ConnectionError:
                pass

        # add a success key in the result dict if not already present.
        result.setdefault('success', True)

        json = simplejson.dumps(result)
        return HttpResponse(json, mimetype='application/json')
开发者ID:tutuca,项目名称:vortex,代码行数:28,代码来源:views.py

示例3: __init__

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import password [as 别名]
class MPDConnection:
   """ Connects and disconnects to a MPD server """

   def __init__(self, host, port, password=None):
      self.host = host
      self.port = port
      self.password = password

      # Always use Unicode in the MPDClient.
      self.client = MPDClient(use_unicode=True)

   def connect(self):
      """ Connect to the MPD server """

      try:
         log.info('Connecting to the MPD server.')

         self.client.connect(self.host, self.port)
      except IOError as err:
         errno, errstr = err
         raise MPDConnectionError("Could not connect to '%s': %s" % (self.host, errstr))
      except MPDError as e:
         raise MPDConnectionError("Could not connect to '%s': %s" % (self.host, e))

      if self.password:
         log.info('Attempting password command.')

         try:
            self.client.password(self.password)
         except CommandError as e:
            raise MPDConnectionError("Could not connect to '%s': "
                              "password command failed: %s" % (self.host, e))
         except (MPDError, IOError) as e:
            raise MPDConnectionError("Could not connect to '%s': "
                              "password command failed: %s" % (self.host, e))
      
   def disconnect(self):
      """ Disconnect from the MPD server """

      log.info('Disconnecting from the MPD server.')

      try:
         self.client.close()
      except (MPDError, IOError):
         log.debug('Could not close client, disconnecting...')
         # Don't worry, just ignore it, disconnect
         pass
      try:
         self.client.disconnect()
      except (MPDError, IOError):
         log.debug('Could not disconnect, resetting client object.')

         # The client object should not be trusted to be re-used.
         self.client = MPDClient(use_unicode=True)

   def reconnect(self):
      """ Reconnects to the MPD server """

      self.disconnect()
      self.connect()
开发者ID:bozbalci,项目名称:oiseau,代码行数:62,代码来源:mpdclient.py

示例4: IndiMPDClient

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import password [as 别名]
class IndiMPDClient(object):
	def __init__(self):
		self.config = IndiMPCConfiguration()
	
		self.setup_dbus()
		self.setup_client()
		self.oldstatus = ""
		self.oldsongdata = ""

		pynotify.init("indimpc")
		self.notification = pynotify.Notification("indiMPC started")
		self.notification.set_hint("action-icons", True)
		gobject.timeout_add(500, self.status_loop)

		if self.config.general_grab_keys:
			self.grab_mmkeys()

	def setup_dbus(self):
		dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
		self.bus = dbus.Bus(dbus.Bus.TYPE_SESSION)
	
	def setup_client(self):
		global MPD
		try:
			self.mpdclient = MPDClient()
			self.mpdclient.connect(self.config.mpd_host, self.config.mpd_port)
			if self.config.mpd_password not in ("", None):
				self.mpdclient.password(self.config.mpd_password)
			self.oldstatus = self.mpdclient.status()["state"]
		except socket.error, e:
			sys.stderr.write("[FATAL] indimpc: can't connect to mpd. please check if it's running corectly")
			sys.exit()
开发者ID:ThomasAdam,项目名称:indimpc,代码行数:34,代码来源:indimpc.py

示例5: currentTrack

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import password [as 别名]
    def currentTrack(self, i3status_output_json, i3status_config):
        try:
            c = MPDClient()
            c.connect(host=HOST, port=PORT)
            if PASSWORD:
                c.password(PASSWORD)

            status = c.status()
            song = int(status.get("song", 0))
            next_song = int(status.get("nextsong", 0))

            if (status["state"] == "pause" and HIDE_WHEN_PAUSED) or (status["state"] == "stop" and HIDE_WHEN_STOPPED):
                text = ""
            else:
                try:
                    song = c.playlistinfo()[song]
                    song["time"] = "{0:.2f}".format(int(song.get("time", 1)) / 60)
                except IndexError:
                    song = {}

                try:
                    next_song = c.playlistinfo()[next_song]
                except IndexError:
                    next_song = {}

                format_args = song
                format_args["state"] = STATE_CHARACTERS.get(status.get("state", None))
                for k, v in next_song.items():
                    format_args["next_{}".format(k)] = v

                text = STRFORMAT
                for k, v in format_args.items():
                    text = text.replace("{" + k + "}", v)

                for sub in re.findall(r"{\S+?}", text):
                    text = text.replace(sub, "")
        except SocketError:
            text = "Failed to connect to mpd!"
        except CommandError:
            text = "Failed to authenticate to mpd!"
            c.disconnect()

        if len(text) > MAX_WIDTH:
            text = text[-MAX_WIDTH-3:] + "..."

        if self.text != text:
            transformed = True
            self.text = text
        else:
            transformed = False

        response = {
            'cached_until': time() + CACHE_TIMEOUT,
            'full_text': self.text,
            'name': 'scratchpad-count',
            'transformed': transformed
        }

        return (POSITION, response)
开发者ID:AdamBSteele,项目名称:py3status,代码行数:61,代码来源:mpd_status.py

示例6: MPDPoller

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import password [as 别名]
class MPDPoller(object):
    def __init__(self, host='localhost', port='6600', password=None):
        self._host = host
        self._port = port
        self._password = password
        self._client = MPDClient()
        
    def connect(self):
        try:
            self._client.connect(self._host, self._port)
        except IOError as strerror:
            raise PollerError("Could not connect to '%s': %s" %
                              (self._host, strerror))
        except mpd.MPDError as e:
            raise PollerError("Could not connect to '%s': %s" %
                              (self._host, e))

        if self._password:
            try:
                self._client.password(self._password)

            # Catch errors with the password command (e.g., wrong password)
            except mpd.CommandError as e:
                raise PollerError("Could not connect to '%s': "
                                  "password commmand failed: %s" %
                                  (self._host, e))

            # Catch all other possible errors
            except (mpd.MPDError, IOError) as e:
                raise PollerError("Could not connect to '%s': "
                                  "error with password command: %s" %
                                  (self._host, e))
    def disconnect(self):
        try:
            self._client.close()
        except (mpd.MPDError, IOError):
            pass
        
        try:
            self._client.disconnect()
        except (mpd.MPDError, IOError):
            self._client = mpd.MPDClient()
            
    def poll(self):
        try:
            song = self._client.currentsong()
        except (mpd.MPDError, IOError):
            self.disconnect()
            try:
                self.connect()
            except PollerError as e:
                raise PollerError("Reconnecting failed: %s" % e)
            
            try:
                song = self._client.currentsong()
            except (mpd.MPDError, IOError) as e:
                raise PollerError("Couldn't retrieve current song: %s" % e)
            
        print(song)
开发者ID:silkecho,项目名称:glowing-silk,代码行数:61,代码来源:silkmpd.py

示例7: Observer

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import password [as 别名]
class Observer(QThread):
    """MPD Observer thread."""
    def __init__(self):
        self._config = ServiceLocator.getGlobalServiceInstance(ServiceNames.Configuration)
        self.client = MPDClient()

        return QThread.__init__(self)

    def __del__(self):
        self.wait()

    def mpdConnect(self):
        self.client.timeout = 10
        self.client.idletimeout = None
        self.client.connect(self._config.mpdserver, self._config.mpdport)
        if len(self._config.mpdpassword) > 0:
            self.client.password(self._config.mpdpassword)
        self.client.update()

    def run(self):
        try:
            self.mpdConnect()
    
            while True:
                info = self.client.idle()
                print("info:{0}".format(info))
                if 'update' in info:
                    # Update all
                    self.updatePlaylist()
                    self.updatePlayer()
                    self.updateMixer()

                if 'playlist' in info:
                    self.updatePlaylist()
                if 'player' in info:
                    self.updatePlayer()
                    self.updateMixer()
                if 'mixer' in info:
                    self.updateMixer()
                self.sleep(2)
        except:
             self.emit(SIGNAL(ObserverSignals.ConnectionError))
            

        pass

    def updatePlaylist(self):
        playlist = self.client.playlistinfo()
        self.emit(SIGNAL(ObserverSignals.PlaylistChanged), playlist)
        pass
    def updateMixer(self):
        status = self.client.status()
        self.emit(SIGNAL(ObserverSignals.MixerChanged), status)
        pass

    def updatePlayer(self):
        currentSong = self.client.currentsong()
        self.emit(SIGNAL(ObserverSignals.PlayerChanged), currentSong)
        pass
开发者ID:huvermann,项目名称:CuteMpd,代码行数:61,代码来源:Observer.py

示例8: mpd

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import password [as 别名]
def mpd(bot, trigger):
  """Used to control the mpd music player at the space"""
  rulenum = trigger.group(2)

  ## MPD object instance
  client = MPDClient()

  try:
    client.connect(host=HOST, port=PORT)
  except SocketError:
    bot.say('socketerror')
    exit(1)


  # Auth if password is set non False
  if PASSWORD:
    try:
      client.password(PASSWORD)
    except CommandError:
      client.disconnect()
      sys.exit(2)

  mpdcommand = str(rulenum)

  if ((mpdcommand == 'playing') or (mpdcommand == 'state')) :
    currentsong = client.currentsong()
    currentstatus = client.status()
    
    if currentstatus['state'] == 'play':
      saySong(bot,currentsong)
    elif currentstatus['state'] == 'pause':
      bot.say('Music is currently paused (' + songNow(currentsong) + ')')
    elif currentstatus['state'] == 'stop':
      bot.say('No music is playing')

  elif mpdcommand == 'play':
    bot.say('Pressing play on mpd...')
    client.play()
    currentsong = client.currentsong()
    saySong(bot,currentsong)

  elif mpdcommand == 'pause':
    bot.say('Pausing mpd...')
    client.pause()

  elif mpdcommand == 'stop':
    bot.say('Stopping mpd...')
    client.stop()

  elif mpdcommand == 'next':
    bot.say('Moving to next song on mpd...')
    client.next()
    currentsong = client.currentsong()
    saySong(bot,currentsong)

  else:
    bot.say('invalid mpd command')
开发者ID:annejan,项目名称:spacebot_modules,代码行数:59,代码来源:spacempd.py

示例9: mpdInit

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import password [as 别名]
def mpdInit():
    global client
    client = MPDClient()                        
    client.timeout = 10                          
    client.idletimeout = None                   
    client.connect("localhost", 6600)   
    client.password("1234")
    client.setvol(20)
    return client
开发者ID:DipoChiang,项目名称:Personal-Assistant,代码行数:11,代码来源:spotifyPi.py

示例10: connect_mpd

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import password [as 别名]
def connect_mpd():
	'''
			Connects to MPD Server
	'''
	client = MPDClient()
	IP = ip_addresses()
	IP = IP['IP']
	client.connect(IP, 6600)
	client.password('blox')
	return client
开发者ID:merlinsbeard,项目名称:blox-user-homepage,代码行数:12,代码来源:blox.py

示例11: get_paths

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import password [as 别名]
def get_paths(root):
    client = MPDClient()
    client.connect(host=HOST, port=PORT)

    if PASSWORD:
        client.password(PASSWORD)

    playlist = client.playlist()
    client.disconnect()

    return [entry.replace("file: ", root) for entry in playlist if entry.startswith("file: ")]
开发者ID:lidel,项目名称:dotfiles,代码行数:13,代码来源:mpd-playlist-export.py

示例12: get_connected

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import password [as 别名]
def get_connected(addr = '0.0.0.0', port = 6600, password = None):
    client=MPDClient()
    mopidyAddress = addr
    mopidyPort = port

    client.timeout = 10
    client.idletimeout = None
    client.connect(mopidyAddress,mopidyPort)
    if password:
        client.password('IlPits2013')
    return client
开发者ID:NilsNoreyson,项目名称:phoneBookServer,代码行数:13,代码来源:mpd_comm.py

示例13: connect

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import password [as 别名]
def connect():
    client = MPDClient()
    try:
        client.connect(HOST, PORT)
        if PASSWORD:
            client.password(PASSWORD)
    except (SocketError, ConnectionError):
        return False
    except CommandError:
        client.disconnect()
        return False
    return client
开发者ID:tokyo-jesus,项目名称:hidden-radio,代码行数:14,代码来源:mpc.py

示例14: connectClient

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import password [as 别名]
def connectClient(config):
    client = MPDClient()
        
    client.timeout = 10
    client.idletimeout = None
    try:
        client.connect(config.mpdserver, config.mpdport)
        if len(config.mpdpassword) > 0:
            client.password(config.mpdpassword)
    except Exception as e:
        print(e)

    return client
开发者ID:huvermann,项目名称:CuteMpd,代码行数:15,代码来源:Client.py

示例15: mpdInfo

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import password [as 别名]
def mpdInfo(host="localhost", keys=("albumartist", "album", "artist")):
    result = dict()

    client = MPDClient()

    host = host.split(":")
    try:
        port = host[1]

    except:
        port = "6600"

    host = host[0].split("@")

    try:
        password = host[0]
        host = host[1]

    except:
        password = ""
        host = host[0]

    conId = {"host": host, "port": port}

    try:
        client.connect(**conId)

    except SocketError:
        result["error"] = "Connection to mpd failed."
        return False, result

    if password:
        try:
            client.password(password)

        except CommandError:
            result["error"] = "Authentification failed."
            return False, result

    for key in client.currentsong():
        value = client.currentsong()[key]
        if type(value).__name__ == "list":
            value = ", ".join(value)

        key = "%s" % key
        if key in keys:
            result[key] = value

    client.disconnect()

    return True, result
开发者ID:serantes,项目名称:getlyrics,代码行数:53,代码来源:getlyrics2.py


注:本文中的mpd.MPDClient.password方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。