mirror of
https://github.com/nikdoof/flexget-plugins.git
synced 2025-12-13 05:12:15 +00:00
Initial untested import of output_xmpp.py
This commit is contained in:
8
README
8
README
@@ -1,8 +0,0 @@
|
||||
Flexget Plugins By Andrew Williams (nikdoof)
|
||||
|
||||
output_twitter - For each entry produce a twitter posting.
|
||||
Requires python-twitter 0.5 or above.
|
||||
|
||||
output_rtorrent - Load accepted entries into rtorrent
|
||||
|
||||
output_log - Write entries to a log file
|
||||
25
README.md
Normal file
25
README.md
Normal file
@@ -0,0 +1,25 @@
|
||||
FlexGet Plugins
|
||||
===============
|
||||
|
||||
A small collection of extra FlexGet plugins by Andrew Williams (nikdoof)
|
||||
|
||||
|
||||
output_twitter
|
||||
--------------
|
||||
|
||||
Sends a twitter message when a new entry has been accepted and downloaded. Requires python-twitter 0.5 or above, currently uses the old authentication method and needs to be updated.
|
||||
|
||||
output_rtorrent
|
||||
---------------
|
||||
|
||||
Basic plugin to output to rTorrent, it is incomplete and non working, and has probably been superceded by FlexGet's own support
|
||||
|
||||
output_log
|
||||
----------
|
||||
|
||||
A in-progress basic plugin to output accepted entries to a log file
|
||||
|
||||
output_xmpp
|
||||
-----------
|
||||
|
||||
Sends a message via XMPP to a target username/chat when a entry is accepted
|
||||
84
output_xmpp.py
Normal file
84
output_xmpp.py
Normal file
@@ -0,0 +1,84 @@
|
||||
import logging
|
||||
from uuid import uuid4
|
||||
from flexget.plugin import *
|
||||
|
||||
__version__ = (0, 1)
|
||||
|
||||
log = logging.getLogger('xmpp')
|
||||
|
||||
class OutputXMPP:
|
||||
|
||||
rooms = []
|
||||
|
||||
def validator(self):
|
||||
from flexget import validator
|
||||
config = validator.factory('dict')
|
||||
config.accept('text', key='jid', required=True)
|
||||
config.accept('text', key='password', required=True)
|
||||
config.accept('text', key='nickname')
|
||||
config.accept('text', key='connection_host')
|
||||
config.accept('integer', key='connection_port')
|
||||
config.accept('text', key='message_format')
|
||||
config.accept('text', key='message_type')
|
||||
return config
|
||||
|
||||
def prepare_config(self, config):
|
||||
if isinstance(config, bool):
|
||||
config = {'enabled': config}
|
||||
config.setdefault('message_format', '{{title}} has started downloading')
|
||||
config.setdefault('message_type', 'headline')
|
||||
config.setdefault('nickname', 'FlexGet')
|
||||
return config
|
||||
|
||||
def on_process_start(self, feed, config):
|
||||
try:
|
||||
from xmpp import Client, Message, JID, Presence
|
||||
except ImportError:
|
||||
raise PluginError("output_xmpp requires xmppy, either `pip install xmpppy` or `apt-get install python-xmpp`")
|
||||
|
||||
debug = []
|
||||
self.jid = JID(config.get('jid'))
|
||||
self.client = Client(self.jid, debug=debug)
|
||||
|
||||
if self.client.connect() is None or self.client.auth(self.jid.getNode(), config['password'], uuid4()):
|
||||
self.error('Unable to connect to XMPP, disabling plugin')
|
||||
config['enabled'] = None
|
||||
return
|
||||
self.client.SendInitPresence()
|
||||
log.debug('Connected to XMPP server on JID %s' % self.jid.getNode())
|
||||
|
||||
def on_process_end(self, feed):
|
||||
if hasattr(self, 'client') and self.client.isConnected():
|
||||
self.client.disconnect()
|
||||
self.client = None
|
||||
|
||||
def on_feed_output(self, feed, config):
|
||||
from xmpp import Client, Message, JID, Presence
|
||||
|
||||
if config['enabled'] is None or feed.manager.options.learn:
|
||||
log.debug('XMPP plugin disabled or in learning mode, skipping.')
|
||||
return
|
||||
|
||||
for entry in feed.accepted:
|
||||
body = entry.render(config.get('message_format'))
|
||||
if feed.manager.options.test:
|
||||
log.info("XMPP message: %s", body)
|
||||
continue
|
||||
msg = Message(body=body)
|
||||
for dest in [x.strip() for x in config['to'].split(',')]:
|
||||
if dest[0] == '@':
|
||||
dest = dest[1:]
|
||||
if not dest in self.rooms:
|
||||
self.client.send(Presence("%s/%s" % (dest, config['nickname'])))
|
||||
msg.setAttr('to', dest)
|
||||
msg.setType('groupchat')
|
||||
else:
|
||||
msg.setAttr('to', dest)
|
||||
msg.setType(config['message_type'])
|
||||
self.client.send(msg)
|
||||
|
||||
|
||||
register_plugin(OutputXMPP, 'xmpp')
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user