First commit
This commit is contained in:
commit
37a6571eee
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
*.pyc
|
||||
__pycache__
|
||||
config.py
|
23
README.md
Normal file
23
README.md
Normal file
@ -0,0 +1,23 @@
|
||||
Ampache2IRC
|
||||
===========
|
||||
|
||||
An IRC bot to post currently listened music on an Ampache server.
|
||||
|
||||
## Installation
|
||||
|
||||
* `git clone "https://github.com/Phyks/Ampache2IRC"`
|
||||
|
||||
Then, in the cloned repository,
|
||||
|
||||
* `pip install -r requirements.txt`.
|
||||
* `cp config.py.example config.py` and edit it according to your needs.
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
As simple as `./ampache2irc.py`.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Code released under MIT license.
|
81
ampache2irc.py
Executable file
81
ampache2irc.py
Executable file
@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
IRC bot to track currently played songs on Ampache.
|
||||
|
||||
Code under MIT license.
|
||||
"""
|
||||
import ssl
|
||||
|
||||
import feedparser
|
||||
import irc.bot
|
||||
import irc.connection
|
||||
|
||||
import config
|
||||
|
||||
|
||||
class Ampache2IRC(irc.bot.SingleServerIRCBot):
|
||||
"""
|
||||
Main bot class
|
||||
"""
|
||||
def __init__(self):
|
||||
self.last_seen = None
|
||||
if not config.use_ssl:
|
||||
irc.bot.SingleServerIRCBot.__init__(self, [(config.server,
|
||||
config.port)],
|
||||
config.nick,
|
||||
config.desc)
|
||||
else:
|
||||
self.ssl_factory = irc.connection.Factory(wrapper=ssl.wrap_socket)
|
||||
irc.bot.SingleServerIRCBot.__init__(
|
||||
self, [(config.server, config.port)],
|
||||
config.nick,
|
||||
config.desc,
|
||||
connect_factory=self.ssl_factory)
|
||||
|
||||
def refresh_feed(self, serv):
|
||||
"""Refresh Ampache played RSS feed"""
|
||||
d = feedparser.parse("%s/rss.php?type=recently_played" %
|
||||
(config.ampache_URL,))
|
||||
for entry in d.entries:
|
||||
if(self.last_seen is None or
|
||||
entry.published_parsed > self.last_seen):
|
||||
serv.privmsg(config.channel,
|
||||
"%s (%s)" % (entry.title,
|
||||
(entry.comments
|
||||
.replace(config.ampache_URL, "")
|
||||
.strip("/"))))
|
||||
self.last_seen = entry.published_parsed
|
||||
|
||||
def on_welcome(self, serv, ev):
|
||||
"""Upon server connection, handles nickserv"""
|
||||
if config.password != "":
|
||||
serv.privmsg("nickserv", "identify %s" % (config.password,))
|
||||
serv.join(config.channel)
|
||||
# Refresh feed every 10 seconds
|
||||
self.connection.execute_every(10, self.refresh_feed, (serv,))
|
||||
|
||||
def on_privmsg(self, serv, ev):
|
||||
"""Handles queries"""
|
||||
pass
|
||||
|
||||
def on_pubmsg(self, serv, ev):
|
||||
"""Handles the messages on the chan"""
|
||||
pass
|
||||
|
||||
def close(self):
|
||||
"""Exits nicely"""
|
||||
pass
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, type, value, traceback):
|
||||
self.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
with Ampache2IRC() as bot:
|
||||
bot.start()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
11
config.py.example
Normal file
11
config.py.example
Normal file
@ -0,0 +1,11 @@
|
||||
server = "" # IRC server to connect to
|
||||
port = 6667 # Port to use
|
||||
use_ssl = False # Use SSL for IRC connection?
|
||||
channel = "" # Channel to join
|
||||
|
||||
password = "" # Used for NickServ
|
||||
|
||||
nick = "ampache_playing" # IRC Nickname
|
||||
desc = "" # IRC Realname
|
||||
|
||||
ampache_URL = "" # Base URL of Ampache without trailing slash
|
Loading…
Reference in New Issue
Block a user