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',