simple mpd client thing
gets now playing status
This commit is contained in:
parent
474afe2576
commit
217b8a15cd
@ -184,6 +184,12 @@ IRCBOT_XMLRPC_PORT = 13132
|
||||
KARMA_IGNORE_CHATTER_TARGETS = []
|
||||
KARMA_IGNORE_COMMAND_TARGETS = []
|
||||
|
||||
# mpd
|
||||
|
||||
MPD_HOST = ""
|
||||
MPD_PORT = None
|
||||
MPD_PASS = None
|
||||
|
||||
# storycraft
|
||||
|
||||
STORYCRAFT_MASTER_CHANNEL = '#dr.botzo'
|
||||
|
1
mpdbot/__init__.py
Normal file
1
mpdbot/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
"""Interface with an mpd server."""
|
63
mpdbot/ircplugin.py
Normal file
63
mpdbot/ircplugin.py
Normal file
@ -0,0 +1,63 @@
|
||||
"""Access to and interface with mpd through bot commands."""
|
||||
|
||||
import logging
|
||||
|
||||
from django.conf import settings
|
||||
from mpd import MPDClient
|
||||
|
||||
from ircbot.lib import Plugin
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MpdBot(Plugin):
|
||||
"""Access to and interface with mpd through bot commands."""
|
||||
|
||||
playing_regex = (r'(what\s+is|what\'s)\s+playing\?$')
|
||||
|
||||
def start(self):
|
||||
"""Set up handlers."""
|
||||
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], self.playing_regex,
|
||||
self.handle_playing, -20)
|
||||
super(MpdBot, self).start()
|
||||
|
||||
def stop(self):
|
||||
"""Tear down handlers."""
|
||||
self.connection.reactor.remove_global_regex_handler(['pubmsg', 'privmsg'], self.handle_playing)
|
||||
super(MpdBot, self).stop()
|
||||
|
||||
def handle_playing(self, connection, event, match):
|
||||
"""Watch IRC for inquiries about the playing track in mpd."""
|
||||
log.debug("in Mpd.handle_playing")
|
||||
if event.in_privmsg or event.addressed:
|
||||
client = MPDClient(use_unicode=True)
|
||||
client.connect(settings.MPD_HOST, settings.MPD_PORT)
|
||||
|
||||
if settings.MPD_PASS:
|
||||
client.password(settings.MPD_PASS)
|
||||
|
||||
status = client.status()
|
||||
log.debug(status)
|
||||
|
||||
state = status.get('state', None)
|
||||
|
||||
if state == 'play':
|
||||
current = client.currentsong()
|
||||
log.debug(current)
|
||||
|
||||
filename = current.get('file', None)
|
||||
|
||||
if filename:
|
||||
artist = current.get('artist', "Unknown")
|
||||
title = current.get('title', "Unknown")
|
||||
album = current.get('album', "Unknown")
|
||||
|
||||
np = "{0:s} - {1:s} [{2:s}]".format(artist, title, album)
|
||||
return self.bot.reply(event, np, stop=True)
|
||||
else:
|
||||
return self.bot.reply(event, "something's playing, but i don't know what!?", stop=True)
|
||||
else:
|
||||
return self.bot.reply(event, "nothing is playing", stop=True)
|
||||
|
||||
|
||||
plugin = MpdBot
|
@ -49,6 +49,7 @@ pylint==1.6.5 # via prospector, pylint-celery, pylint-common, pylint
|
||||
pyparsing==2.1.10 # via packaging
|
||||
python-dateutil==2.6.0
|
||||
python-gitlab==0.18
|
||||
python-mpd2==0.5.5
|
||||
pytz==2016.10
|
||||
pyyaml==3.12 # via prospector
|
||||
requests-oauthlib==0.7.0 # via twython
|
||||
|
@ -27,6 +27,7 @@ ply==3.10
|
||||
psycopg2==2.6.2
|
||||
python-dateutil==2.6.0
|
||||
python-gitlab==0.18
|
||||
python-mpd2==0.5.5
|
||||
pytz==2016.10
|
||||
requests-oauthlib==0.7.0 # via twython
|
||||
requests==2.13.0 # via python-gitlab, requests-oauthlib, twython
|
||||
|
@ -9,5 +9,6 @@ parsedatetime # relative date stuff in countdown
|
||||
ply # dice lex/yacc compiler
|
||||
python-dateutil # countdown relative math
|
||||
python-gitlab # client for the gitlab bot
|
||||
python-mpd2 # client for mpd
|
||||
pytz # timezone awareness
|
||||
twython # twitter client
|
||||
|
@ -26,6 +26,7 @@ parsedatetime==2.2
|
||||
ply==3.10
|
||||
python-dateutil==2.6.0
|
||||
python-gitlab==0.18
|
||||
python-mpd2==0.5.5
|
||||
pytz==2016.10
|
||||
requests-oauthlib==0.7.0 # via twython
|
||||
requests==2.13.0 # via python-gitlab, requests-oauthlib, twython
|
||||
|
Loading…
Reference in New Issue
Block a user