本文整理汇总了Python中mpd.MPDClient方法的典型用法代码示例。如果您正苦于以下问题:Python mpd.MPDClient方法的具体用法?Python mpd.MPDClient怎么用?Python mpd.MPDClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpd
的用法示例。
在下文中一共展示了mpd.MPDClient方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_song_info
# 需要导入模块: import mpd [as 别名]
# 或者: from mpd import MPDClient [as 别名]
def get_song_info(player):
if player == "mpd":
from mpd import MPDClient
client = MPDClient()
client.connect("localhost", 6600)
song_info = client.currentsong()
return song_info["artist"], song_info["title"]
else:
bus = dbus.SessionBus()
try:
proxy = bus.get_object("org.mpris.MediaPlayer2.%s" % player,
"/org/mpris/MediaPlayer2")
except dbus.exceptions.DBusException:
print("[ERROR] Player \"%s\" doesn't exist or isn't playing" \
% player)
return
interface = dbus.Interface(
proxy, dbus_interface="org.freedesktop.DBus.Properties"
)
properties = interface.GetAll("org.mpris.MediaPlayer2.Player")
metadata = properties["Metadata"]
artist = str(metadata["xesam:artist"][0])
title = str(metadata["xesam:title"])
return artist, title
示例2: update_mpd_info
# 需要导入模块: import mpd [as 别名]
# 或者: from mpd import MPDClient [as 别名]
def update_mpd_info(channel, mpd, influx_client):
try:
mpd["client"].ping()
except Exception:
try:
mpd["client"] = MPDClient()
mpd["client"].connect(mpd["mpd_host"], mpd["mpd_port"])
mpd["client"].ping()
except Exception as e:
print(e)
mpd["cache"] = ("Could not connect to MPD.", 500)
# okay, client (re-)connected
report = get_playlist_info(mpd["client"])
report["stream_data"] = {"live": False}
report["listeners"] = get_channel_listeners(channel, influx_client)
mpd["cache"] = (report, 200)
###############################################################################
# Icecast
示例3: connect
# 需要导入模块: import mpd [as 别名]
# 或者: from mpd import MPDClient [as 别名]
def connect(self,port):
global client
connection = False
retry = 2
while retry > 0:
client = MPDClient() # Create the MPD client
try:
client.timeout = 10
client.idletimeout = None
client.connect("localhost", port)
log.message("Connected to MPD port " + str(port), log.INFO)
connection = True
retry = 0
except:
log.message("Failed to connect to MPD on port " + str(port), log.ERROR)
time.sleep(2.5) # Wait for interrupt in the case of a shutdown
time.sleep(0.2) # Give MPD time
retry -= 1
return connection
# Handle IR remote key
示例4: _connect
# 需要导入模块: import mpd [as 别名]
# 或者: from mpd import MPDClient [as 别名]
def _connect(self, n_tries=2):
import mpd
with self._client_lock:
if self.client:
return
error = None
while n_tries > 0:
try:
n_tries -= 1
self.client = mpd.MPDClient(use_unicode=True)
self.client.connect(self.host, self.port)
return self.client
except Exception as e:
error = e
self.logger.warning('Connection exception: {}{}'.
format(str(e), (': Retrying' if n_tries > 0 else '')))
time.sleep(0.5)
self.client = None
raise error
示例5: test_correct_mpd_interaction
# 需要导入模块: import mpd [as 别名]
# 或者: from mpd import MPDClient [as 别名]
def test_correct_mpd_interaction(self, mocker) -> None:
import mpd
mock_instance = mocker.MagicMock(spec=mpd.MPDClient)
mock_instance.status.return_value = {"state": "play"}
timeout_property = mocker.PropertyMock()
type(mock_instance).timeout = timeout_property
mock = mocker.patch("mpd.MPDClient")
mock.return_value = mock_instance
host = "foo"
port = 42
timeout = 17
assert Mpd("name", host, port, timeout).check() is not None
timeout_property.assert_called_once_with(timeout)
mock_instance.connect.assert_called_once_with(host, port)
mock_instance.status.assert_called_once_with()
mock_instance.close.assert_called_once_with()
mock_instance.disconnect.assert_called_once_with()
示例6: disconnect
# 需要导入模块: import mpd [as 别名]
# 或者: from mpd import MPDClient [as 别名]
def disconnect(self):
# Try to tell MPD to close the connection first
try:
self._client.close()
# If that fails, ignore it and disconnect
except (MPDError, IOError):
pass
try:
self._client.disconnect()
# Disconnecting failed, setup a new client object instead
# This should never happen. If it does, something is seriously broken,
# and the client object shouldn't be trusted to be re-used.
except (MPDError, IOError):
self._client = MPDClient(use_unicode=True)
self._client.timeout = 60*60*1000
示例7: connect
# 需要导入模块: import mpd [as 别名]
# 或者: from mpd import MPDClient [as 别名]
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")
示例8: _get_state
# 需要导入模块: import mpd [as 别名]
# 或者: from mpd import MPDClient [as 别名]
def _get_state(self) -> Dict:
from mpd import MPDClient
client = MPDClient()
client.timeout = self._timeout
client.connect(self._host, self._port)
state = client.status()
client.close()
client.disconnect()
return state
示例9: __init__
# 需要导入模块: import mpd [as 别名]
# 或者: from mpd import MPDClient [as 别名]
def __init__(self, host, port="6600"):
self._host = host
self._port = port
self._client = MPDClient(use_unicode=True)
self._client.timeout = 60*60*1000