diff --git a/data/interfaces/default/notification_config.html b/data/interfaces/default/notification_config.html index 58f6436e..41e4a341 100644 --- a/data/interfaces/default/notification_config.html +++ b/data/interfaces/default/notification_config.html @@ -9,9 +9,9 @@
-
+
% for item in data: - % if item['input_type'] != 'checkbox': + % if item['input_type'] == 'text' or item['input_type'] == 'number' or item['input_type'] == 'password':
@@ -20,6 +20,11 @@ % endif

${item['description']}

+ % elif item['input_type'] == 'button': +
+ +
+

${item['description']}

% elif item['input_type'] == 'checkbox':
@@ -53,4 +65,20 @@ doAjaxCall('set_notification_config',$(this),'tabs',true); return false; }); + + $('#twitterStep1').click(function () { + $.get("/twitterStep1", function (data) {window.open(data); }) + .done(function () { $('#ajaxMsg').html("
Confirm Authorization. Check pop-up blocker if no response.
"); }); + $('#ajaxMsg').addClass('success').fadeIn().delay(3000).fadeOut(); + }); + $('#twitterStep2').click(function () { + var twitter_key = $("#twitter_key").val(); + $.get("/twitterStep2", {'key': twitter_key}, function (data) { $('#ajaxMsg').html("
"+data+"
"); }); + $('#ajaxMsg').addClass('success').fadeIn().delay(3000).fadeOut(); + }); + $('#testTwitter').click(function () { + $.get("/testTwitter", + function (data) { $('#ajaxMsg').html("
"+data+"
"); }); + $('#ajaxMsg').addClass('success').fadeIn().delay(3000).fadeOut(); + }); diff --git a/plexpy/config.py b/plexpy/config.py index 51145685..9d41b67a 100644 --- a/plexpy/config.py +++ b/plexpy/config.py @@ -194,8 +194,14 @@ _CONFIG_DEFINITIONS = { 'TV_NOTIFY_ON_PAUSE': (int, 'Monitoring', 0), 'TWITTER_ENABLED': (int, 'Twitter', 0), 'TWITTER_PASSWORD': (str, 'Twitter', ''), - 'TWITTER_PREFIX': (str, 'Twitter', 'Headphones'), + 'TWITTER_PREFIX': (str, 'Twitter', 'PlexPy'), 'TWITTER_USERNAME': (str, 'Twitter', ''), + 'TWITTER_ON_PLAY': (int, 'Twitter', 0), + 'TWITTER_ON_STOP': (int, 'Twitter', 0), + 'TWITTER_ON_PAUSE': (int, 'Twitter', 0), + 'TWITTER_ON_RESUME': (int, 'Twitter', 0), + 'TWITTER_ON_BUFFER': (int, 'Twitter', 0), + 'TWITTER_ON_WATCHED': (int, 'Twitter', 0), 'UPDATE_DB_INTERVAL': (int, 'General', 24), 'VERIFY_SSL_CERT': (bool_int, 'Advanced', 1), 'VIDEO_LOGGING_ENABLE': (int, 'Monitoring', 1), diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py index 2c348b5a..6d3abda1 100644 --- a/plexpy/notifiers.py +++ b/plexpy/notifiers.py @@ -49,7 +49,8 @@ AGENT_IDS = {"Growl": 0, "Pushover": 7, "OSX Notify": 8, "Boxcar2": 9, - "Email": 10} + "Email": 10, + "Twitter": 11} def available_notification_agents(): agents = [{'name': 'Growl', @@ -171,6 +172,18 @@ def available_notification_agents(): 'on_resume': plexpy.CONFIG.EMAIL_ON_RESUME, 'on_buffer': plexpy.CONFIG.EMAIL_ON_BUFFER, 'on_watched': plexpy.CONFIG.EMAIL_ON_WATCHED + }, + {'name': 'Twitter', + 'id': AGENT_IDS['Twitter'], + 'config_prefix': 'twitter', + 'has_config': True, + 'state': checked(plexpy.CONFIG.TWITTER_ENABLED), + 'on_play': plexpy.CONFIG.TWITTER_ON_PLAY, + 'on_stop': plexpy.CONFIG.TWITTER_ON_STOP, + 'on_pause': plexpy.CONFIG.TWITTER_ON_PAUSE, + 'on_resume': plexpy.CONFIG.TWITTER_ON_RESUME, + 'on_buffer': plexpy.CONFIG.TWITTER_ON_BUFFER, + 'on_watched': plexpy.CONFIG.TWITTER_ON_WATCHED } ] @@ -229,6 +242,9 @@ def get_notification_agent_config(config_id): elif config_id == 10: email = Email() return email.return_config_options() + elif config_id == 11: + tweet = TwitterNotifier() + return tweet.return_config_options() else: return [] else: @@ -271,6 +287,9 @@ def send_notification(config_id, subject, body): elif config_id == 10: email = Email() email.notify(subject=subject, message=body) + elif config_id == 11: + tweet = TwitterNotifier() + tweet.notify(subject=subject, message=body) else: logger.debug(u"PlexPy Notifier :: Unknown agent id received.") else: @@ -912,19 +931,17 @@ class TwitterNotifier(object): SIGNIN_URL = 'https://api.twitter.com/oauth/authenticate' def __init__(self): - self.consumer_key = "oYKnp2ddX5gbARjqX8ZAAg" - self.consumer_secret = "A4Xkw9i5SjHbTk7XT8zzOPqivhj9MmRDR9Qn95YA9sk" + self.consumer_key = "2LdJKXHDUwJtjYBsdwJisIOsh" + self.consumer_secret = "QWbUcZzAIiL4zbDCIhy2EdUkV8yEEav3qMdo5y3FugxCFelWrA" - def notify_snatch(self, title): - if plexpy.CONFIG.TWITTER_ONSNATCH: - self._notifyTwitter(common.notifyStrings[common.NOTIFY_SNATCH] + ': ' + title + ' at ' + helpers.now()) - - def notify_download(self, title): - if plexpy.CONFIG.TWITTER_ENABLED: - self._notifyTwitter(common.notifyStrings[common.NOTIFY_DOWNLOAD] + ': ' + title + ' at ' + helpers.now()) + def notify(self, subject, message): + if not subject or not message: + return + else: + self._send_tweet(subject + ': ' + message) def test_notify(self): - return self._notifyTwitter("This is a test notification from PlexPy at " + helpers.now(), force=True) + return self._send_tweet("This is a test notification from PlexPy at " + helpers.now()) def _get_authorization(self): @@ -979,7 +996,6 @@ class TwitterNotifier(object): return True def _send_tweet(self, message=None): - username = self.consumer_key password = self.consumer_secret access_token_key = plexpy.CONFIG.TWITTER_USERNAME @@ -997,13 +1013,36 @@ class TwitterNotifier(object): return True - def _notifyTwitter(self, message='', force=False): - prefix = plexpy.CONFIG.TWITTER_PREFIX + def return_config_options(self): + config_option = [{'label': 'Request Authorisation', + 'value': 'Request Authorisation', + 'name': 'twitterStep1', + 'description': 'Step 1: Click Request button above. (Ensure you allow the browser pop-up).', + 'input_type': 'button' + }, + {'label': 'Authorisation Key', + 'value': '', + 'name': 'twitter_key', + 'description': 'Step 2: Input the authorisation key you received from Step 1.', + 'input_type': 'text' + }, + {'label': 'Verify Key', + 'value': 'Verify Key', + 'name': 'twitterStep2', + 'description': 'Step 3: Verify the key.', + 'input_type': 'button' + }, + {'label': 'Test Twitter', + 'value': 'Test Twitter', + 'name': 'testTwitter', + 'description': 'Test if Twitter notifications are working. See logs for troubleshooting.', + 'input_type': 'button' + }, + {'input_type': 'nosave' + } + ] - if not plexpy.CONFIG.TWITTER_ENABLED and not force: - return False - - return self._send_tweet(prefix + ": " + message) + return config_option class OSX_NOTIFY(object):