Some Twitter love. Resolves Issue #47.

This commit is contained in:
Tim 2015-09-19 00:57:24 +02:00
parent 483f5825db
commit 6eec4d1ca6
3 changed files with 95 additions and 22 deletions

View file

@ -9,9 +9,9 @@
<div class="container-fluid">
<div class="row">
<form action="set_notification_config" method="post" class="form" id="set_notification_config" data-parsley-validate>
<div class="col-md-6">
<div class="col-md-8">
% for item in data:
% if item['input_type'] != 'checkbox':
% if item['input_type'] == 'text' or item['input_type'] == 'number' or item['input_type'] == 'password':
<div class="form-group">
<label for="${item['name']}">${item['label']}</label>
<input type="${item['input_type']}" class="form-control" id="${item['name']}" name="${item['name']}" value="${item['value']}" size="30">
@ -20,6 +20,11 @@
% endif
<p class="help-block">${item['description']}</p>
</div>
% elif item['input_type'] == 'button':
<div class="form-group">
<input type="${item['input_type']}" class="btn btn-bright" id="${item['name']}" name="${item['name']}" value="${item['value']}">
</div>
<p class="help-block">${item['description']}</p>
% elif item['input_type'] == 'checkbox':
<div class="checkbox">
<label>
@ -35,7 +40,14 @@
</div>
</div>
<div class="modal-footer">
<%
nosave = any(d['input_type'] == 'nosave' for d in data)
%>
% if not nosave:
<input type="button" id="save-notification-item" class="btn btn-bright" value="Save">
% else:
<input type="button" class="btn btn-bright" data-dismiss="modal" value="Close">
% endif
</div>
</div>
</div>
@ -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("<div class='msg'><span class='ui-icon ui-icon-check'></span>Confirm Authorization. Check pop-up blocker if no response.</div>"); });
$('#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("<div class='msg'><span class='ui-icon ui-icon-check'></span>"+data+"</div>"); });
$('#ajaxMsg').addClass('success').fadeIn().delay(3000).fadeOut();
});
$('#testTwitter').click(function () {
$.get("/testTwitter",
function (data) { $('#ajaxMsg').html("<div class='msg'><span class='ui-icon ui-icon-check'></span>"+data+"</div>"); });
$('#ajaxMsg').addClass('success').fadeIn().delay(3000).fadeOut();
});
</script>

View file

@ -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),

View file

@ -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):