Skip to content

Commit

Permalink
Fix Encoding issues in notifiers.py due to Py3 migration.
Browse files Browse the repository at this point in the history
  • Loading branch information
zSeriesGuy committed Mar 25, 2020
1 parent 013ec78 commit d51a67e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 43 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v4.0.12 (2020-03-25)
* (FIXED) Fix encoding issues in notifiers.py related to the Py3 migration.

## v4.0.11 (2020-03-03)
* (FIXED) Issue with encoding in notifiers.py when using Python < 3.8.

Expand Down
81 changes: 39 additions & 42 deletions plexpy/notifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,14 +761,14 @@ def get_title(self, divider='-'):
title = '%s - %s' % (self.parameters['artist_name'], self.parameters['album_name'])
elif self.media_type == 'track':
title = '%s - %s' % (self.parameters['track_name'], self.parameters['track_artist'])
return title.encode("utf-8")
return title

def get_description(self):
if self.media_type == 'track':
description = self.parameters['album_name']
else:
description = self.parameters['summary']
return description.encode("utf-8")
return description

def get_plex_url(self):
return self.parameters['plex_url']
Expand Down Expand Up @@ -878,9 +878,9 @@ def agent_notify(self, subject='', body='', action='', notification_id=None, **k
pretty_metadata = PrettyMetadata(kwargs.get('parameters'))

plaintext_data = {'notification_id': notification_id,
'subject': subject.encode('UTF-8'),
'body': body.encode('UTF-8'),
'action': action.encode('UTF-8'),
'subject': subject,
'body': body,
'action': action,
'priority': self.config['priority'],
'session_key': pretty_metadata.parameters.get('session_key',''),
'session_id': pretty_metadata.parameters.get('session_id',''),
Expand Down Expand Up @@ -1032,8 +1032,8 @@ class BOXCAR(Notifier):

def agent_notify(self, subject='', body='', action='', **kwargs):
data = {'user_credentials': self.config['token'],
'notification[title]': subject.encode('utf-8'),
'notification[long_message]': body.encode('utf-8'),
'notification[title]': subject,
'notification[long_message]': body,
'notification[sound]': self.config['sound']
}

Expand Down Expand Up @@ -1145,9 +1145,9 @@ class DISCORD(Notifier):

def agent_notify(self, subject='', body='', action='', **kwargs):
if self.config['incl_subject']:
text = subject.encode('utf-8') + b'\r\n' + body.encode("utf-8")
text = subject + '\r\n' + body
else:
text = body.encode("utf-8")
text = body

data = {'content': text}
if self.config['username']:
Expand Down Expand Up @@ -1201,11 +1201,11 @@ def agent_notify(self, subject='', body='', action='', **kwargs):
if provider_link:
attachment['url'] = provider_link
fields.append({'name': 'View Details',
'value': '[%s](%s)' % (provider_name, provider_link.encode('utf-8')),
'value': '[%s](%s)' % (provider_name, provider_link),
'inline': True})
if self.config['incl_pmslink']:
fields.append({'name': 'View Details',
'value': '[Plex Web](%s)' % plex_url.encode('utf-8'),
'value': '[Plex Web](%s)' % plex_url,
'inline': True})
if fields:
attachment['fields'] = fields
Expand Down Expand Up @@ -1560,9 +1560,9 @@ def _post_facebook(self, **data):

def agent_notify(self, subject='', body='', action='', **kwargs):
if self.config['incl_subject']:
text = subject.encode('utf-8') + b'\r\n' + body.encode("utf-8")
text = subject + '\r\n' + body
else:
text = body.encode("utf-8")
text = body

data = {'message': text}

Expand Down Expand Up @@ -1680,9 +1680,9 @@ def agent_notify(self, subject='', body='', action='', **kwargs):
data = {'bot_id': self.config['bot_id']}

if self.config['incl_subject']:
data['text'] = subject.encode('utf-8') + b'\r\n' + body.encode('utf-8')
data['text'] = subject + '\r\n' + body
else:
data['text'] = body.encode('utf-8')
data['text'] = body

if self.config['incl_poster'] and kwargs.get('parameters'):
pretty_metadata = PrettyMetadata(kwargs.get('parameters'))
Expand Down Expand Up @@ -1787,9 +1787,6 @@ def agent_notify(self, subject='', body='', action='', **kwargs):
logger.error(u"Tautulli Notifiers :: {name} notification failed: authentication error".format(name=self.NAME))
return False

# Fix message
body = body.encode(plexpy.SYS_ENCODING, "replace")

# Send it, including an image
image_file = os.path.join(str(plexpy.PROG_DIR),
"data/interfaces/default/images/logo-circle.png")
Expand Down Expand Up @@ -1848,10 +1845,10 @@ class HIPCHAT(Notifier):
def agent_notify(self, subject='', body='', action='', **kwargs):
data = {'notify': 'false'}

text = body.encode('utf-8')
text = body

if self.config['incl_subject']:
data['from'] = subject.encode('utf-8')
data['from'] = subject

if self.config['color']:
data['color'] = self.config['color']
Expand Down Expand Up @@ -2014,8 +2011,8 @@ class IFTTT(Notifier):
def agent_notify(self, subject='', body='', action='', **kwargs):
event = str(self.config['event']).format(action=action)

data = {'value1': subject.encode("utf-8"),
'value2': body.encode("utf-8")}
data = {'value1': subject,
'value2': body}

if self.config['value3']:
pretty_metadata = PrettyMetadata(kwargs['parameters'])
Expand Down Expand Up @@ -2075,10 +2072,10 @@ class JOIN(Notifier):
def agent_notify(self, subject='', body='', action='', **kwargs):
data = {'apikey': self.config['api_key'],
'deviceNames': ','.join(self.config['device_names']),
'text': body.encode("utf-8")}
'text': body}

if self.config['incl_subject']:
data['title'] = subject.encode("utf-8")
data['title'] = subject

if kwargs.get('parameters', {}).get('media_type'):
# Grab formatted metadata
Expand Down Expand Up @@ -2231,9 +2228,9 @@ def agent_notify(self, subject='', body='', action='', **kwargs):
logger.error(u"Tautulli Notifiers :: MQTT topic not specified.")
return

data = {'subject': subject.encode("utf-8"),
'body': body.encode("utf-8"),
'topic': self.config['topic'].encode("utf-8")}
data = {'subject': subject,
'body': body,
'topic': self.config['topic']}

auth = {}
if self.config['username']:
Expand Down Expand Up @@ -2592,8 +2589,8 @@ class PROWL(Notifier):
def agent_notify(self, subject='', body='', action='', **kwargs):
data = {'apikey': self.config['key'],
'application': 'Tautulli',
'event': subject.encode("utf-8"),
'description': body.encode("utf-8"),
'event': subject,
'description': body,
'priority': self.config['priority']}

headers = {'Content-type': 'application/x-www-form-urlencoded'}
Expand Down Expand Up @@ -2629,8 +2626,8 @@ class PUSHALOT(Notifier):

def agent_notify(self, subject='', body='', action='', **kwargs):
data = {'AuthorizationToken': self.config['api_key'],
'Title': subject.encode('utf-8'),
'Body': body.encode("utf-8")}
'Title': subject,
'Body': body}

headers = {'Content-type': 'application/x-www-form-urlencoded'}

Expand Down Expand Up @@ -2662,14 +2659,14 @@ class PUSHBULLET(Notifier):

def agent_notify(self, subject='', body='', action='', **kwargs):
data = {'type': 'note',
'body': body.encode("utf-8")}
'body': body}

headers = {'Content-type': 'application/json',
'Access-Token': self.config['api_key']
}

if self.config['incl_subject']:
data['title'] = subject.encode("utf-8")
data['title'] = subject

# Can only send to a device or channel, not both.
if self.config['device_id']:
Expand Down Expand Up @@ -2798,14 +2795,14 @@ class PUSHOVER(Notifier):
def agent_notify(self, subject='', body='', action='', **kwargs):
data = {'token': self.config['api_token'],
'user': self.config['key'],
'message': body.encode("utf-8"),
'message': body,
'sound': self.config['sound'],
'html': self.config['html_support'],
'priority': self.config['priority'],
'timestamp': int(time.time())}

if self.config['incl_subject']:
data['title'] = subject.encode("utf-8")
data['title'] = subject

if self.config['priority'] == 2:
data['retry'] = max(30, self.config['retry'])
Expand Down Expand Up @@ -3210,9 +3207,9 @@ class SLACK(Notifier):

def agent_notify(self, subject='', body='', action='', **kwargs):
if self.config['incl_subject']:
text = subject.encode('utf-8') + b'\r\n' + body.encode("utf-8")
text = subject + '\r\n' + body
else:
text = body.encode("utf-8")
text = body

data = {'text': text}
if self.config['channel'] and self.config['channel'].startswith('#'):
Expand Down Expand Up @@ -3389,9 +3386,9 @@ def agent_notify(self, subject='', body='', action='', **kwargs):
data = {'chat_id': self.config['chat_id']}

if self.config['incl_subject']:
text = subject.encode('utf-8') + b'\r\n' + body.encode('utf-8')
text = subject + '\r\n' + body
else:
text = body.encode('utf-8')
text = body

if self.config['html_support']:
data['parse_mode'] = 'HTML'
Expand Down Expand Up @@ -3756,9 +3753,9 @@ def _test_hook(self):
return self.agent_notify(_test_data=_test_data)

def agent_notify(self, subject='', body='', action='', **kwargs):
data = {'subject': subject.encode("utf-8"),
'body': body.encode("utf-8"),
'action': action.encode("utf-8")}
data = {'subject': subject,
'body': body,
'action': action}

if kwargs.get('parameters', {}).get('media_type'):
# Grab formatted metadata
Expand Down
2 changes: 1 addition & 1 deletion plexpy/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PLEXPY_BRANCH = "master"
PLEXPY_RELEASE_VERSION = "v4.0.11"
PLEXPY_RELEASE_VERSION = "v4.0.12"

0 comments on commit d51a67e

Please sign in to comment.