Remove string encoding from notifiers

This commit is contained in:
JonnyWong16 2020-01-19 17:09:50 -08:00
parent 6b7cd38d71
commit 4c211342a2

View file

@ -759,14 +759,14 @@ class PrettyMetadata(object):
title = '%s - %s' % (self.parameters['artist_name'], self.parameters['album_name']) title = '%s - %s' % (self.parameters['artist_name'], self.parameters['album_name'])
elif self.media_type == 'track': elif self.media_type == 'track':
title = '%s - %s' % (self.parameters['track_name'], self.parameters['track_artist']) title = '%s - %s' % (self.parameters['track_name'], self.parameters['track_artist'])
return title.encode('utf-8') return title
def get_description(self): def get_description(self):
if self.media_type == 'track': if self.media_type == 'track':
description = self.parameters['album_name'] description = self.parameters['album_name']
else: else:
description = self.parameters['summary'] description = self.parameters['summary']
return description.encode('utf-8') return description
def get_plex_url(self): def get_plex_url(self):
return self.parameters['plex_url'] return self.parameters['plex_url']
@ -885,9 +885,9 @@ class ANDROIDAPP(Notifier):
pretty_metadata = PrettyMetadata(kwargs.get('parameters')) pretty_metadata = PrettyMetadata(kwargs.get('parameters'))
plaintext_data = {'notification_id': notification_id, plaintext_data = {'notification_id': notification_id,
'subject': subject.encode('utf-8'), 'subject': subject,
'body': body.encode('utf-8'), 'body': body,
'action': action.encode('utf-8'), 'action': action,
'priority': self.config['priority'], 'priority': self.config['priority'],
'session_key': pretty_metadata.parameters.get('session_key',''), 'session_key': pretty_metadata.parameters.get('session_key',''),
'session_id': pretty_metadata.parameters.get('session_id',''), 'session_id': pretty_metadata.parameters.get('session_id',''),
@ -1039,8 +1039,8 @@ class BOXCAR(Notifier):
def agent_notify(self, subject='', body='', action='', **kwargs): def agent_notify(self, subject='', body='', action='', **kwargs):
data = {'user_credentials': self.config['token'], data = {'user_credentials': self.config['token'],
'notification[title]': subject.encode('utf-8'), 'notification[title]': subject,
'notification[long_message]': body.encode('utf-8'), 'notification[long_message]': body,
'notification[sound]': self.config['sound'] 'notification[sound]': self.config['sound']
} }
@ -1152,9 +1152,9 @@ class DISCORD(Notifier):
def agent_notify(self, subject='', body='', action='', **kwargs): def agent_notify(self, subject='', body='', action='', **kwargs):
if self.config['incl_subject']: if self.config['incl_subject']:
text = subject.encode('utf-8') + '\r\n' + body.encode('utf-8') text = subject + '\r\n' + body
else: else:
text = body.encode('utf-8') text = body
data = {'content': text} data = {'content': text}
if self.config['username']: if self.config['username']:
@ -1208,11 +1208,11 @@ class DISCORD(Notifier):
if provider_link: if provider_link:
attachment['url'] = provider_link attachment['url'] = provider_link
fields.append({'name': 'View Details', fields.append({'name': 'View Details',
'value': '[%s](%s)' % (provider_name, provider_link.encode('utf-8')), 'value': '[%s](%s)' % (provider_name, provider_link),
'inline': True}) 'inline': True})
if self.config['incl_pmslink']: if self.config['incl_pmslink']:
fields.append({'name': 'View Details', fields.append({'name': 'View Details',
'value': '[Plex Web](%s)' % plex_url.encode('utf-8'), 'value': '[Plex Web](%s)' % plex_url,
'inline': True}) 'inline': True})
if fields: if fields:
attachment['fields'] = fields attachment['fields'] = fields
@ -1568,9 +1568,9 @@ class FACEBOOK(Notifier):
def agent_notify(self, subject='', body='', action='', **kwargs): def agent_notify(self, subject='', body='', action='', **kwargs):
if self.config['incl_subject']: if self.config['incl_subject']:
text = subject.encode('utf-8') + '\r\n' + body.encode('utf-8') text = subject + '\r\n' + body
else: else:
text = body.encode('utf-8') text = body
data = {'message': text} data = {'message': text}
@ -1688,9 +1688,9 @@ class GROUPME(Notifier):
data = {'bot_id': self.config['bot_id']} data = {'bot_id': self.config['bot_id']}
if self.config['incl_subject']: if self.config['incl_subject']:
data['text'] = subject.encode('utf-8') + '\r\n' + body.encode('utf-8') data['text'] = subject + '\r\n' + body
else: else:
data['text'] = body.encode('utf-8') data['text'] = body
if self.config['incl_poster'] and kwargs.get('parameters'): if self.config['incl_poster'] and kwargs.get('parameters'):
pretty_metadata = PrettyMetadata(kwargs.get('parameters')) pretty_metadata = PrettyMetadata(kwargs.get('parameters'))
@ -1856,10 +1856,10 @@ class HIPCHAT(Notifier):
def agent_notify(self, subject='', body='', action='', **kwargs): def agent_notify(self, subject='', body='', action='', **kwargs):
data = {'notify': 'false'} data = {'notify': 'false'}
text = body.encode('utf-8') text = body
if self.config['incl_subject']: if self.config['incl_subject']:
data['from'] = subject.encode('utf-8') data['from'] = subject
if self.config['color']: if self.config['color']:
data['color'] = self.config['color'] data['color'] = self.config['color']
@ -2022,8 +2022,8 @@ class IFTTT(Notifier):
def agent_notify(self, subject='', body='', action='', **kwargs): def agent_notify(self, subject='', body='', action='', **kwargs):
event = str(self.config['event']).format(action=action) event = str(self.config['event']).format(action=action)
data = {'value1': subject.encode('utf-8'), data = {'value1': subject,
'value2': body.encode('utf-8')} 'value2': body}
if self.config['value3']: if self.config['value3']:
pretty_metadata = PrettyMetadata(kwargs['parameters']) pretty_metadata = PrettyMetadata(kwargs['parameters'])
@ -2083,10 +2083,10 @@ class JOIN(Notifier):
def agent_notify(self, subject='', body='', action='', **kwargs): def agent_notify(self, subject='', body='', action='', **kwargs):
data = {'apikey': self.config['api_key'], data = {'apikey': self.config['api_key'],
'deviceNames': ','.join(self.config['device_names']), 'deviceNames': ','.join(self.config['device_names']),
'text': body.encode('utf-8')} 'text': body}
if self.config['incl_subject']: if self.config['incl_subject']:
data['title'] = subject.encode('utf-8') data['title'] = subject
if kwargs.get('parameters', {}).get('media_type'): if kwargs.get('parameters', {}).get('media_type'):
# Grab formatted metadata # Grab formatted metadata
@ -2239,9 +2239,9 @@ class MQTT(Notifier):
logger.error("Tautulli Notifiers :: MQTT topic not specified.") logger.error("Tautulli Notifiers :: MQTT topic not specified.")
return return
data = {'subject': subject.encode('utf-8'), data = {'subject': subject,
'body': body.encode('utf-8'), 'body': body,
'topic': self.config['topic'].encode('utf-8')} 'topic': self.config['topic']}
auth = {} auth = {}
if self.config['username']: if self.config['username']:
@ -2552,8 +2552,8 @@ class PROWL(Notifier):
def agent_notify(self, subject='', body='', action='', **kwargs): def agent_notify(self, subject='', body='', action='', **kwargs):
data = {'apikey': self.config['key'], data = {'apikey': self.config['key'],
'application': 'Tautulli', 'application': 'Tautulli',
'event': subject.encode('utf-8'), 'event': subject,
'description': body.encode('utf-8'), 'description': body,
'priority': self.config['priority']} 'priority': self.config['priority']}
headers = {'Content-type': 'application/x-www-form-urlencoded'} headers = {'Content-type': 'application/x-www-form-urlencoded'}
@ -2593,14 +2593,14 @@ class PUSHBULLET(Notifier):
def agent_notify(self, subject='', body='', action='', **kwargs): def agent_notify(self, subject='', body='', action='', **kwargs):
data = {'type': 'note', data = {'type': 'note',
'body': body.encode('utf-8')} 'body': body}
headers = {'Content-type': 'application/json', headers = {'Content-type': 'application/json',
'Access-Token': self.config['api_key'] 'Access-Token': self.config['api_key']
} }
if self.config['incl_subject']: if self.config['incl_subject']:
data['title'] = subject.encode('utf-8') data['title'] = subject
# Can only send to a device or channel, not both. # Can only send to a device or channel, not both.
if self.config['device_id']: if self.config['device_id']:
@ -2729,14 +2729,14 @@ class PUSHOVER(Notifier):
def agent_notify(self, subject='', body='', action='', **kwargs): def agent_notify(self, subject='', body='', action='', **kwargs):
data = {'token': self.config['api_token'], data = {'token': self.config['api_token'],
'user': self.config['key'], 'user': self.config['key'],
'message': body.encode('utf-8'), 'message': body,
'sound': self.config['sound'], 'sound': self.config['sound'],
'html': self.config['html_support'], 'html': self.config['html_support'],
'priority': self.config['priority'], 'priority': self.config['priority'],
'timestamp': int(time.time())} 'timestamp': int(time.time())}
if self.config['incl_subject']: if self.config['incl_subject']:
data['title'] = subject.encode('utf-8') data['title'] = subject
if self.config['priority'] == 2: if self.config['priority'] == 2:
data['retry'] = max(30, self.config['retry']) data['retry'] = max(30, self.config['retry'])
@ -3161,9 +3161,9 @@ class SLACK(Notifier):
def agent_notify(self, subject='', body='', action='', **kwargs): def agent_notify(self, subject='', body='', action='', **kwargs):
if self.config['incl_subject']: if self.config['incl_subject']:
text = subject.encode('utf-8') + '\r\n' + body.encode('utf-8') text = subject + '\r\n' + body
else: else:
text = body.encode('utf-8') text = body
data = {'text': text} data = {'text': text}
if self.config['channel'] and self.config['channel'].startswith('#'): if self.config['channel'] and self.config['channel'].startswith('#'):
@ -3340,9 +3340,9 @@ class TELEGRAM(Notifier):
data = {'chat_id': self.config['chat_id']} data = {'chat_id': self.config['chat_id']}
if self.config['incl_subject']: if self.config['incl_subject']:
text = subject.encode('utf-8') + '\r\n' + body.encode('utf-8') text = subject + '\r\n' + body
else: else:
text = body.encode('utf-8') text = body
if self.config['html_support']: if self.config['html_support']:
data['parse_mode'] = 'HTML' data['parse_mode'] = 'HTML'
@ -3723,9 +3723,9 @@ class ZAPIER(Notifier):
return self.agent_notify(_test_data=_test_data) return self.agent_notify(_test_data=_test_data)
def agent_notify(self, subject='', body='', action='', **kwargs): def agent_notify(self, subject='', body='', action='', **kwargs):
data = {'subject': subject.encode('utf-8'), data = {'subject': subject,
'body': body.encode('utf-8'), 'body': body,
'action': action.encode('utf-8')} 'action': action}
if kwargs.get('parameters', {}).get('media_type'): if kwargs.get('parameters', {}).get('media_type'):
# Grab formatted metadata # Grab formatted metadata