From 6d9ef8bbc3a33ad80883b69be4a8870d091e3623 Mon Sep 17 00:00:00 2001 From: "greg.gaskill" Date: Tue, 12 Jul 2016 14:33:04 -0400 Subject: [PATCH 1/6] Combine repeated metadata formatting functions in one place. --- plexpy/notifiers.py | 224 +++++++++++++++++++++----------------------- 1 file changed, 107 insertions(+), 117 deletions(-) diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py index cfe86502..5faf7529 100644 --- a/plexpy/notifiers.py +++ b/plexpy/notifiers.py @@ -615,6 +615,93 @@ def send_notification(agent_id, subject, body, notify_action, **kwargs): else: logger.debug(u"PlexPy Notifiers :: Notification requested but no agent id received.") +class PrettyMetadata(object): + def __init__(self, metadata, divider): + self.poster_url = metadata.get('poster_url','') + self.poster_link = '' + self.caption = '' + self.plex_url = None + self.title = None + self.season_divider = divider + self.subtitle = None + + if not self.poster_url: + if metadata['media_type'] in ['artist', 'track']: + self.poster_url = 'https://raw.githubusercontent.com/drzoidberg33/plexpy/master/data/interfaces/default/images/cover.png' + else: + self.poster_url = 'https://raw.githubusercontent.com/drzoidberg33/plexpy/master/data/interfaces/default/images/poster.png' + + if metadata['media_type'] == 'movie': + self.title = '%s (%s)' % (metadata['title'], metadata['year']) + self.unicode_title = self.title + self.subtitle = metadata['summary'] + if metadata.get('imdb_url',''): + self.poster_link = metadata.get('imdb_url', '') + self.caption = 'View on IMDB' + elif metadata.get('themoviedb_url',''): + self.poster_link = metadata.get('themoviedb_url', '') + self.caption = 'View on The Movie Database' + + elif metadata['media_type'] == 'show': + self.title = '%s (%s)' % (metadata['title'], metadata['year']) + self.unicode_title = self.title + self.subtitle = metadata['summary'] + if metadata.get('thetvdb_url',''): + self.poster_link = metadata.get('thetvdb_url', '') + self.caption = 'View on TheTVDB' + elif metadata.get('themoviedb_url',''): + self.poster_link = metadata.get('themoviedb_url', '') + self.caption = 'View on The Movie Database' + + elif metadata['media_type'] == 'episode': + self.title = '%s - %s (S%s %s E%s)' % (metadata['grandparent_title'], + metadata['title'], + metadata['parent_media_index'], + self.season_divider, + metadata['media_index']) + self.subtitle = metadata['summary'] + if metadata.get('thetvdb_url',''): + self.poster_link = metadata.get('thetvdb_url', '') + self.caption = 'View on TheTVDB' + elif metadata.get('themoviedb_url',''): + self.poster_link = metadata.get('themoviedb_url', '') + self.caption = 'View on The Movie Database' + + elif metadata['media_type'] == 'artist': + self.title = metadata['title'] + self.unicode_title = self.title + self.subtitle = metadata['summary'] + if metadata.get('lastfm_url',''): + self.poster_link = metadata.get('lastfm_url', '') + self.caption = 'View on Last.fm' + + elif metadata['media_type'] == 'track': + self.title = '%s - %s' % (metadata['grandparent_title'], metadata['title']) + self.unicode_title = self.title + self.subtitle = metadata['parent_title'] + if metadata.get('lastfm_url',''): + self.poster_link = metadata.get('lastfm_url', '') + self.caption = 'View on Last.fm' + + self.plex_url = metadata['plex_url'] + + def get_poster_url(self): + return self.poster_url + + def get_plex_url(self): + return self.plex_url + + def get_poster_link(self): + return self.poster_link + + def get_caption(self): + return self.caption + + def get_title(self): + return self.title + + def get_subtitle(self): + return self.subtitle class GROWL(object): """ @@ -1918,66 +2005,20 @@ class SLACK(object): else: data['icon_url'] = self.icon_emoji - if self.incl_poster and 'metadata' in kwargs: + if self.incl_poster and 'metadata' in kwargs: + # Grab formatted metadata + pretty_metadata = PrettyMetadata(kwargs['metadata'], '-') + poster_url = pretty_metadata.get_poster_url() + plex_url = pretty_metadata.get_plex_url() + poster_link = pretty_metadata.get_poster_link() + caption = pretty_metadata.get_caption() + title = pretty_metadata.get_title() + + # Build Slack post attachment attachment = {} - metadata = kwargs['metadata'] - poster_url = metadata.get('poster_url','') - poster_link = '' - caption = '' - - # Use default posters if no poster_url - if not poster_url: - if metadata['media_type'] in ['artist', 'track']: - poster_url = 'https://raw.githubusercontent.com/drzoidberg33/plexpy/master/data/interfaces/default/images/cover.png' - else: - poster_url = 'https://raw.githubusercontent.com/drzoidberg33/plexpy/master/data/interfaces/default/images/poster.png' - - if metadata['media_type'] == 'movie': - title = '%s (%s)' % (metadata['title'], metadata['year']) - if metadata.get('imdb_url',''): - poster_link = metadata.get('imdb_url', '') - caption = 'View on IMDB' - elif metadata.get('themoviedb_url',''): - poster_link = metadata.get('themoviedb_url', '') - caption = 'View on The Movie Database' - - elif metadata['media_type'] == 'show': - title = '%s (%s)' % (metadata['title'], metadata['year']) - if metadata.get('thetvdb_url',''): - poster_link = metadata.get('thetvdb_url', '') - caption = 'View on TheTVDB' - elif metadata.get('themoviedb_url',''): - poster_link = metadata.get('themoviedb_url', '') - caption = 'View on The Movie Database' - - elif metadata['media_type'] == 'episode': - title = '%s - %s (S%s - E%s)' % (metadata['grandparent_title'], - metadata['title'], - metadata['parent_media_index'], - metadata['media_index']) - if metadata.get('thetvdb_url',''): - poster_link = metadata.get('thetvdb_url', '') - caption = 'View on TheTVDB' - elif metadata.get('themoviedb_url',''): - poster_link = metadata.get('themoviedb_url', '') - caption = 'View on The Movie Database' - - elif metadata['media_type'] == 'artist': - title = metadata['title'] - if metadata.get('lastfm_url',''): - poster_link = metadata.get('lastfm_url', '') - caption = 'View on Last.fm' - - elif metadata['media_type'] == 'track': - title = '%s - %s' % (metadata['grandparent_title'], metadata['title']) - if metadata.get('lastfm_url',''): - poster_link = metadata.get('lastfm_url', '') - caption = 'View on Last.fm' - - # Build Facebook post attachment if self.incl_pmslink: caption = 'View on Plex Web' - attachment['title_link'] = metadata['plex_url'] + attachment['title_link'] = plex_url attachment['text'] = caption elif poster_link: attachment['title_link'] = poster_link @@ -2376,70 +2417,19 @@ class FacebookNotifier(object): attachment = {} if self.incl_poster and 'metadata' in kwargs: - metadata = kwargs['metadata'] - poster_url = metadata.get('poster_url','') - poster_link = '' - caption = '' - - # Use default posters if no poster_url - if not poster_url: - if metadata['media_type'] in ['artist', 'track']: - poster_url = 'https://raw.githubusercontent.com/drzoidberg33/plexpy/master/data/interfaces/default/images/cover.png' - else: - poster_url = 'https://raw.githubusercontent.com/drzoidberg33/plexpy/master/data/interfaces/default/images/poster.png' - - if metadata['media_type'] == 'movie': - title = '%s (%s)' % (metadata['title'], metadata['year']) - subtitle = metadata['summary'] - if metadata.get('imdb_url',''): - poster_link = metadata.get('imdb_url', '') - caption = 'View on IMDB' - elif metadata.get('themoviedb_url',''): - poster_link = metadata.get('themoviedb_url', '') - caption = 'View on The Movie Database' - - elif metadata['media_type'] == 'show': - title = '%s (%s)' % (metadata['title'], metadata['year']) - subtitle = metadata['summary'] - if metadata.get('thetvdb_url',''): - poster_link = metadata.get('thetvdb_url', '') - caption = 'View on TheTVDB' - elif metadata.get('themoviedb_url',''): - poster_link = metadata.get('themoviedb_url', '') - caption = 'View on The Movie Database' - - elif metadata['media_type'] == 'episode': - title = '%s - %s (S%s %s E%s)' % (metadata['grandparent_title'], - metadata['title'], - metadata['parent_media_index'], - '\xc2\xb7'.decode('utf8'), - metadata['media_index']) - subtitle = metadata['summary'] - if metadata.get('thetvdb_url',''): - poster_link = metadata.get('thetvdb_url', '') - caption = 'View on TheTVDB' - elif metadata.get('themoviedb_url',''): - poster_link = metadata.get('themoviedb_url', '') - caption = 'View on The Movie Database' - - elif metadata['media_type'] == 'artist': - title = metadata['title'] - subtitle = metadata['summary'] - if metadata.get('lastfm_url',''): - poster_link = metadata.get('lastfm_url', '') - caption = 'View on Last.fm' - - elif metadata['media_type'] == 'track': - title = '%s - %s' % (metadata['grandparent_title'], metadata['title']) - subtitle = metadata['parent_title'] - if metadata.get('lastfm_url',''): - poster_link = metadata.get('lastfm_url', '') - caption = 'View on Last.fm' + # Grab formatted metadata + pretty_metadata = PrettyMetadata(kwargs['metadata'], '\xc2\xb7'.decode('utf8')) + poster_url = pretty_metadata.get_poster_url() + plex_url = pretty_metadata.get_plex_url() + poster_link = pretty_metadata.get_poster_link() + caption = pretty_metadata.get_caption() + title = pretty_metadata.get_unicode_title() + subtitle = pretty_metadata.get_subtitle() # Build Facebook post attachment if self.incl_pmslink: caption = 'View on Plex Web' - attachment['link'] = metadata['plex_url'] + attachment['link'] = plex_url attachment['caption'] = caption elif poster_link: attachment['link'] = poster_link From 809f120db0b72a67111d81f66f37d06160b5871a Mon Sep 17 00:00:00 2001 From: "greg.gaskill" Date: Tue, 12 Jul 2016 17:13:54 -0400 Subject: [PATCH 2/6] Refactored PrettyMetadata class. Trying basic Hipchat poster without links (unfortunately not allowed to use
s). --- plexpy/config.py | 3 + plexpy/notifiers.py | 192 ++++++++++++++++++++++++-------------------- 2 files changed, 107 insertions(+), 88 deletions(-) diff --git a/plexpy/config.py b/plexpy/config.py index 5c5ade78..ceaace8a 100644 --- a/plexpy/config.py +++ b/plexpy/config.py @@ -215,6 +215,9 @@ _CONFIG_DEFINITIONS = { 'HIPCHAT_URL': (str, 'Hipchat', ''), 'HIPCHAT_COLOR': (str, 'Hipchat', ''), 'HIPCHAT_INCL_SUBJECT': (int, 'Hipchat', 1), + 'HIPCHAT_FROM_SUBJECT': (int, 'Hipchat', 0), + 'HIPCHAT_INCL_PMSLINK': (int, 'Hipchat', 0), + 'HIPCHAT_INCL_POSTER': (int, 'Hipchat', 0), 'HIPCHAT_EMOTICON': (str, 'Hipchat', ''), 'HIPCHAT_ENABLED': (int, 'Hipchat', 0), 'HIPCHAT_ON_PLAY': (int, 'Hipchat', 0), diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py index 5faf7529..25d55ade 100644 --- a/plexpy/notifiers.py +++ b/plexpy/notifiers.py @@ -609,100 +609,78 @@ def send_notification(agent_id, subject, body, notify_action, **kwargs): return join.notify(message=body, subject=subject) elif agent_id == 19: hipchat = HIPCHAT() - return hipchat.notify(message=body, subject=subject) + return hipchat.notify(message=body, subject=subject, **kwargs) else: logger.debug(u"PlexPy Notifiers :: Unknown agent id received.") else: logger.debug(u"PlexPy Notifiers :: Notification requested but no agent id received.") class PrettyMetadata(object): - def __init__(self, metadata, divider): - self.poster_url = metadata.get('poster_url','') - self.poster_link = '' - self.caption = '' - self.plex_url = None - self.title = None - self.season_divider = divider - self.subtitle = None + def __init__(self, metadata): + self.metadata = metadata + self.media_type = metadata['media_type'] + def get_poster_url(self): + self.poster_url = self.metadata.get('poster_url','') if not self.poster_url: - if metadata['media_type'] in ['artist', 'track']: + if self.metadata['media_type'] in ['artist', 'track']: self.poster_url = 'https://raw.githubusercontent.com/drzoidberg33/plexpy/master/data/interfaces/default/images/cover.png' else: self.poster_url = 'https://raw.githubusercontent.com/drzoidberg33/plexpy/master/data/interfaces/default/images/poster.png' - - if metadata['media_type'] == 'movie': - self.title = '%s (%s)' % (metadata['title'], metadata['year']) - self.unicode_title = self.title - self.subtitle = metadata['summary'] - if metadata.get('imdb_url',''): - self.poster_link = metadata.get('imdb_url', '') - self.caption = 'View on IMDB' - elif metadata.get('themoviedb_url',''): - self.poster_link = metadata.get('themoviedb_url', '') - self.caption = 'View on The Movie Database' - - elif metadata['media_type'] == 'show': - self.title = '%s (%s)' % (metadata['title'], metadata['year']) - self.unicode_title = self.title - self.subtitle = metadata['summary'] - if metadata.get('thetvdb_url',''): - self.poster_link = metadata.get('thetvdb_url', '') - self.caption = 'View on TheTVDB' - elif metadata.get('themoviedb_url',''): - self.poster_link = metadata.get('themoviedb_url', '') - self.caption = 'View on The Movie Database' - - elif metadata['media_type'] == 'episode': - self.title = '%s - %s (S%s %s E%s)' % (metadata['grandparent_title'], - metadata['title'], - metadata['parent_media_index'], - self.season_divider, - metadata['media_index']) - self.subtitle = metadata['summary'] - if metadata.get('thetvdb_url',''): - self.poster_link = metadata.get('thetvdb_url', '') - self.caption = 'View on TheTVDB' - elif metadata.get('themoviedb_url',''): - self.poster_link = metadata.get('themoviedb_url', '') - self.caption = 'View on The Movie Database' - - elif metadata['media_type'] == 'artist': - self.title = metadata['title'] - self.unicode_title = self.title - self.subtitle = metadata['summary'] - if metadata.get('lastfm_url',''): - self.poster_link = metadata.get('lastfm_url', '') - self.caption = 'View on Last.fm' - - elif metadata['media_type'] == 'track': - self.title = '%s - %s' % (metadata['grandparent_title'], metadata['title']) - self.unicode_title = self.title - self.subtitle = metadata['parent_title'] - if metadata.get('lastfm_url',''): - self.poster_link = metadata.get('lastfm_url', '') - self.caption = 'View on Last.fm' - - self.plex_url = metadata['plex_url'] - - def get_poster_url(self): return self.poster_url - def get_plex_url(self): - return self.plex_url - def get_poster_link(self): + self.poster_link = '' + if self.metadata.get('thetvdb_url',''): + self.poster_link = self.metadata.get('thetvdb_url', '') + elif self.metadata.get('themoviedb_url',''): + self.poster_link = self.metadata.get('themoviedb_url', '') + elif self.metadata.get('imdb_url',''): + self.poster_link = self.metadata.get('imdb_url', '') + elif self.metadata.get('lastfm_url',''): + self.poster_link = self.metadata.get('lastfm_url', '') return self.poster_link def get_caption(self): + self.caption = '' + if self.metadata.get('thetvdb_url',''): + self.caption = 'View on TheTVDB' + elif self.metadata.get('themoviedb_url',''): + self.caption = 'View on The Movie Database' + elif self.metadata.get('imdb_url',''): + self.caption = 'View on IMDB' + elif self.metadata.get('lastfm_url',''): + self.caption = 'View on Last.fm' return self.caption - def get_title(self): + def get_title(self, divider = ''): + if self.metadata['media_type'] == 'movie': + self.title = '%s (%s)' % (self.metadata['title'], self.metadata['year']) + elif self.metadata['media_type'] == 'show': + self.title = '%s (%s)' % (self.metadata['title'], self.metadata['year']) + elif self.metadata['media_type'] == 'artist': + self.title = self.metadata['title'] + elif self.metadata['media_type'] == 'track': + self.title = '%s - %s' % (self.metadata['grandparent_title'], self.metadata['title']) + elif self.metadata['media_type'] == 'episode': + self.title = '%s - %s (S%s %s E%s)' % (self.metadata['grandparent_title'], + self.metadata['title'], + self.metadata['parent_media_index'], + divider, + self.metadata['media_index']) return self.title def get_subtitle(self): + if self.metadata['media_type'] == 'track': + self.subtitle = self.metadata['parent_title'] + else: + self.subtitle = self.metadata['summary'] return self.subtitle + def get_plex_url(self): + self.plex_url = self.metadata['plex_url'] + return self.plex_url + class GROWL(object): """ Growl notifications, for OS X. @@ -2005,14 +1983,14 @@ class SLACK(object): else: data['icon_url'] = self.icon_emoji - if self.incl_poster and 'metadata' in kwargs: + if self.incl_poster and 'metadata' in kwargs: # Grab formatted metadata - pretty_metadata = PrettyMetadata(kwargs['metadata'], '-') + pretty_metadata = PrettyMetadata(kwargs['metadata']) poster_url = pretty_metadata.get_poster_url() plex_url = pretty_metadata.get_plex_url() poster_link = pretty_metadata.get_poster_link() caption = pretty_metadata.get_caption() - title = pretty_metadata.get_title() + title = pretty_metadata.get_title('-') # Build Slack post attachment attachment = {} @@ -2418,12 +2396,12 @@ class FacebookNotifier(object): if self.incl_poster and 'metadata' in kwargs: # Grab formatted metadata - pretty_metadata = PrettyMetadata(kwargs['metadata'], '\xc2\xb7'.decode('utf8')) + pretty_metadata = PrettyMetadata(kwargs['metadata']) poster_url = pretty_metadata.get_poster_url() plex_url = pretty_metadata.get_plex_url() poster_link = pretty_metadata.get_poster_link() caption = pretty_metadata.get_caption() - title = pretty_metadata.get_unicode_title() + title = pretty_metadata.get_title('\xc2\xb7'.decode('utf8')) subtitle = pretty_metadata.get_subtitle() # Build Facebook post attachment @@ -2744,32 +2722,52 @@ class HIPCHAT(object): def __init__(self): self.apiurl = plexpy.CONFIG.HIPCHAT_URL self.color = plexpy.CONFIG.HIPCHAT_COLOR - self.incl_subject = plexpy.CONFIG.HIPCHAT_INCL_SUBJECT self.emoticon = plexpy.CONFIG.HIPCHAT_EMOTICON + self.from_subject = plexpy.CONFIG.HIPCHAT_FROM_SUBJECT + self.incl_pmslink = plexpy.CONFIG.FACEBOOK_INCL_PMSLINK + self.incl_poster = plexpy.CONFIG.FACEBOOK_INCL_POSTER + self.incl_subject = plexpy.CONFIG.HIPCHAT_INCL_SUBJECT - def notify(self, message, subject): + def notify(self, message, subject, **kwargs): if not message or not subject: return - + + data = {'notify': 'false'} + + text = message.encode('utf-8') + if self.incl_subject: - text = subject.encode('utf-8') + ': ' + message.encode('utf-8') - else: - text = message.encode('utf-8') + text = subject.encode('utf-8') + ': ' + text if self.emoticon: text = self.emoticon + ' ' + text - data = {'message': text, - 'notify': 'false', - 'message_format': 'text'} - if self.color: data['color'] = self.color + if self.from_subject: + data['from'] = subject.encode('utf-8') + + if self.incl_poster and 'metadata' in kwargs: + pretty_metadata = PrettyMetadata(kwargs['metadata']) + poster_url = pretty_metadata.get_poster_url() + poster_link = pretty_metadata.get_poster_link() + caption = pretty_metadata.get_caption() + title = pretty_metadata.get_title('-') + subtitle = pretty_metadata.get_subtitle() + message = ( '{0}
' + '' + '' + '
{2}
{3}
').format(text,poster_url,title,subtitle) + + data['message'] = message + data['message_format'] = 'html' + else: + data['message'] = text + data['message_format'] = 'text' + hiphost = urlparse(self.apiurl).hostname - hippath = urlparse(self.apiurl).path - hipquery = urlparse(self.apiurl).query - hipfullq = hippath + '?' + hipquery + hipfullq = urlparse(self.apiurl).path + '?' + urlparse(self.apiurl).query http_handler = HTTPSConnection(hiphost) http_handler.request("POST", @@ -2829,6 +2827,24 @@ class HIPCHAT(object): ' here.', 'input_type': 'text' }, + {'label': 'Include Subject as "From"', + 'value': self.from_subject, + 'name': 'hipchat_from_subject', + 'description': 'Include the subject line in the Hipchat "From" field, which appears on the top line above the message.', + 'input_type': 'checkbox' + }, + {'label': 'Include Poster', + 'value': self.incl_poster, + 'name': 'hipchat_incl_poster', + 'description': 'Include a poster in the notifications.
This will change the notification type to HTML and emoticons will no longer work.', + 'input_type': 'checkbox' + }, + {'label': 'Include Link to Plex Web', + 'value': self.incl_pmslink, + 'name': 'hipchat_incl_pmslink', + 'description': 'Include a link to the media in Plex Web with the notifications.', + 'input_type': 'checkbox' + }, {'label': 'Include Subject Line', 'value': self.incl_subject, 'name': 'hipchat_incl_subject', From 2b680eeb6dc79081dd7e65d35bc6b29ab2ade260 Mon Sep 17 00:00:00 2001 From: "greg.gaskill" Date: Wed, 13 Jul 2016 10:59:32 -0400 Subject: [PATCH 3/6] Finished metadata class. Finished Hipchat graphical poster notifications. --- plexpy/notifiers.py | 53 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py index 25d55ade..865c4a1a 100644 --- a/plexpy/notifiers.py +++ b/plexpy/notifiers.py @@ -1,4 +1,4 @@ -# This file is part of PlexPy. +# This file is part of PlexPy. # # PlexPy is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -654,6 +654,7 @@ class PrettyMetadata(object): return self.caption def get_title(self, divider = ''): + self.title = None if self.metadata['media_type'] == 'movie': self.title = '%s (%s)' % (self.metadata['title'], self.metadata['year']) elif self.metadata['media_type'] == 'show': @@ -668,14 +669,14 @@ class PrettyMetadata(object): self.metadata['parent_media_index'], divider, self.metadata['media_index']) - return self.title + return self.title.encode("utf-8") def get_subtitle(self): if self.metadata['media_type'] == 'track': self.subtitle = self.metadata['parent_title'] else: self.subtitle = self.metadata['summary'] - return self.subtitle + return self.subtitle.encode("utf-8") def get_plex_url(self): self.plex_url = self.metadata['plex_url'] @@ -1990,7 +1991,7 @@ class SLACK(object): plex_url = pretty_metadata.get_plex_url() poster_link = pretty_metadata.get_poster_link() caption = pretty_metadata.get_caption() - title = pretty_metadata.get_title('-') + title = pretty_metadata.get_title() # Build Slack post attachment attachment = {} @@ -2753,15 +2754,45 @@ class HIPCHAT(object): poster_url = pretty_metadata.get_poster_url() poster_link = pretty_metadata.get_poster_link() caption = pretty_metadata.get_caption() - title = pretty_metadata.get_title('-') + title = pretty_metadata.get_title() subtitle = pretty_metadata.get_subtitle() - message = ( '{0}
' - '' - '' - '
{2}
{3}
').format(text,poster_url,title,subtitle) + plex_url = pretty_metadata.get_plex_url() + + card = {'title': title, + 'format': 'medium', + 'style': 'application', + 'id': '41c354f0-69a5-4251-a61c-c6a8daf8e2f6'} + description = {'format': 'text', + 'value': subtitle} + card['description'] = description + thumbnail = {'url': poster_url} + card['thumbnail'] = thumbnail + attributes = [] + + if self.incl_pmslink: + pms_values = {'label': 'View on Plex Web', + 'url': plex_url} + plex_web = {'value': pms_values} + attributes.append(plex_web) + + if poster_link: + card['url'] = poster_link + info_values = {'label': caption, + 'url': poster_link} + content_info_web = {'value': info_values} + attributes.append(content_info_web) + + if len(attributes): + card['attributes'] = attributes + + act_icon = {'url': poster_url} + activity = {'html': text, + 'icon': act_icon} + card['activity'] = activity + + data['message'] = text + data['card'] = card - data['message'] = message - data['message_format'] = 'html' else: data['message'] = text data['message_format'] = 'text' From 2f8833236a7652f3b7c8f31e1bbdcc875bd219a6 Mon Sep 17 00:00:00 2001 From: "greg.gaskill" Date: Wed, 13 Jul 2016 12:14:58 -0400 Subject: [PATCH 4/6] Actually use self.media_type. Set default divider for tv shows to '-'. --- plexpy/notifiers.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py index 865c4a1a..299463c4 100644 --- a/plexpy/notifiers.py +++ b/plexpy/notifiers.py @@ -653,17 +653,17 @@ class PrettyMetadata(object): self.caption = 'View on Last.fm' return self.caption - def get_title(self, divider = ''): + def get_title(self, divider = '-'): self.title = None - if self.metadata['media_type'] == 'movie': + if self.media_type == 'movie': self.title = '%s (%s)' % (self.metadata['title'], self.metadata['year']) - elif self.metadata['media_type'] == 'show': + elif self.media_type == 'show': self.title = '%s (%s)' % (self.metadata['title'], self.metadata['year']) - elif self.metadata['media_type'] == 'artist': + elif self.media_type == 'artist': self.title = self.metadata['title'] - elif self.metadata['media_type'] == 'track': + elif self.media_type == 'track': self.title = '%s - %s' % (self.metadata['grandparent_title'], self.metadata['title']) - elif self.metadata['media_type'] == 'episode': + elif self.media_type == 'episode': self.title = '%s - %s (S%s %s E%s)' % (self.metadata['grandparent_title'], self.metadata['title'], self.metadata['parent_media_index'], @@ -672,7 +672,7 @@ class PrettyMetadata(object): return self.title.encode("utf-8") def get_subtitle(self): - if self.metadata['media_type'] == 'track': + if self.media_type == 'track': self.subtitle = self.metadata['parent_title'] else: self.subtitle = self.metadata['summary'] From 9cdd2eef816282341d920c552fac9a974281a7c4 Mon Sep 17 00:00:00 2001 From: "greg.gaskill" Date: Wed, 13 Jul 2016 12:33:39 -0400 Subject: [PATCH 5/6] Randomize Hipchat card 'id' value. --- plexpy/notifiers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py index 299463c4..cbab840a 100644 --- a/plexpy/notifiers.py +++ b/plexpy/notifiers.py @@ -31,6 +31,7 @@ import urllib from urllib import urlencode import urllib2 from urlparse import urlparse +import uuid import gntp.notifier import facebook @@ -2761,7 +2762,7 @@ class HIPCHAT(object): card = {'title': title, 'format': 'medium', 'style': 'application', - 'id': '41c354f0-69a5-4251-a61c-c6a8daf8e2f6'} + 'id': uuid.uuid4().hex} description = {'format': 'text', 'value': subtitle} card['description'] = description From ea9d0fc449b1a3343374c4dce026f9fd1eec4ee4 Mon Sep 17 00:00:00 2001 From: aboron Date: Wed, 13 Jul 2016 22:54:56 -0400 Subject: [PATCH 6/6] Consolidate redundant subject options. Fix emoticon handling for html cards. Fix cut/paste CONFIG errors. --- plexpy/config.py | 1 - plexpy/notifiers.py | 25 +++++++------------------ 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/plexpy/config.py b/plexpy/config.py index ceaace8a..7734c97a 100644 --- a/plexpy/config.py +++ b/plexpy/config.py @@ -215,7 +215,6 @@ _CONFIG_DEFINITIONS = { 'HIPCHAT_URL': (str, 'Hipchat', ''), 'HIPCHAT_COLOR': (str, 'Hipchat', ''), 'HIPCHAT_INCL_SUBJECT': (int, 'Hipchat', 1), - 'HIPCHAT_FROM_SUBJECT': (int, 'Hipchat', 0), 'HIPCHAT_INCL_PMSLINK': (int, 'Hipchat', 0), 'HIPCHAT_INCL_POSTER': (int, 'Hipchat', 0), 'HIPCHAT_EMOTICON': (str, 'Hipchat', ''), diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py index cbab840a..98d9c67d 100644 --- a/plexpy/notifiers.py +++ b/plexpy/notifiers.py @@ -2725,9 +2725,8 @@ class HIPCHAT(object): self.apiurl = plexpy.CONFIG.HIPCHAT_URL self.color = plexpy.CONFIG.HIPCHAT_COLOR self.emoticon = plexpy.CONFIG.HIPCHAT_EMOTICON - self.from_subject = plexpy.CONFIG.HIPCHAT_FROM_SUBJECT - self.incl_pmslink = plexpy.CONFIG.FACEBOOK_INCL_PMSLINK - self.incl_poster = plexpy.CONFIG.FACEBOOK_INCL_POSTER + self.incl_pmslink = plexpy.CONFIG.HIPCHAT_INCL_PMSLINK + self.incl_poster = plexpy.CONFIG.HIPCHAT_INCL_POSTER self.incl_subject = plexpy.CONFIG.HIPCHAT_INCL_SUBJECT def notify(self, message, subject, **kwargs): @@ -2739,17 +2738,11 @@ class HIPCHAT(object): text = message.encode('utf-8') if self.incl_subject: - text = subject.encode('utf-8') + ': ' + text - - if self.emoticon: - text = self.emoticon + ' ' + text + data['from'] = subject.encode('utf-8') if self.color: data['color'] = self.color - if self.from_subject: - data['from'] = subject.encode('utf-8') - if self.incl_poster and 'metadata' in kwargs: pretty_metadata = PrettyMetadata(kwargs['metadata']) poster_url = pretty_metadata.get_poster_url() @@ -2795,6 +2788,8 @@ class HIPCHAT(object): data['card'] = card else: + if self.emoticon: + text = self.emoticon + ' ' + text data['message'] = text data['message_format'] = 'text' @@ -2854,17 +2849,11 @@ class HIPCHAT(object): {'label': 'Hipchat Emoticon', 'value': self.emoticon, 'name': 'hipchat_emoticon', - 'description': 'Include an emoticon tag at the beginning of all notifications (e.g. (taco)). Leave blank for none.' + 'description': 'Include an emoticon tag at the beginning of text notifications (e.g. (taco)). Leave blank for none.' ' Use a stock emoticon or create a custom emoticon' ' here.', 'input_type': 'text' }, - {'label': 'Include Subject as "From"', - 'value': self.from_subject, - 'name': 'hipchat_from_subject', - 'description': 'Include the subject line in the Hipchat "From" field, which appears on the top line above the message.', - 'input_type': 'checkbox' - }, {'label': 'Include Poster', 'value': self.incl_poster, 'name': 'hipchat_incl_poster', @@ -2880,7 +2869,7 @@ class HIPCHAT(object): {'label': 'Include Subject Line', 'value': self.incl_subject, 'name': 'hipchat_incl_subject', - 'description': 'Include the subject line with the notifications.', + 'description': 'Includes the subject with the notifications.', 'input_type': 'checkbox' } ]