From 4100917016973109281621442fa3f50f3cc69372 Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Fri, 26 Feb 2016 21:39:41 -0800 Subject: [PATCH] Add ability to disable Facebook poster link to Plex Web --- data/interfaces/default/settings.html | 2 +- plexpy/config.py | 1 + plexpy/notifiers.py | 67 ++++++++++++++++++++++----- 3 files changed, 57 insertions(+), 13 deletions(-) diff --git a/data/interfaces/default/settings.html b/data/interfaces/default/settings.html index e1651b86..694029bc 100644 --- a/data/interfaces/default/settings.html +++ b/data/interfaces/default/settings.html @@ -1527,7 +1527,7 @@ available_notification_agents = sorted(notifiers.available_notification_agents() {lastfm_url} - The last.fm URL for the album. + The Last.fm URL for the album.

(PMS agent must be Last.fm)

diff --git a/plexpy/config.py b/plexpy/config.py index ae668035..d914ce6b 100644 --- a/plexpy/config.py +++ b/plexpy/config.py @@ -88,6 +88,7 @@ _CONFIG_DEFINITIONS = { 'FACEBOOK_APP_SECRET': (str, 'Facebook', ''), 'FACEBOOK_TOKEN': (str, 'Facebook', ''), 'FACEBOOK_GROUP': (str, 'Facebook', ''), + 'FACEBOOK_INCL_PMSLINK': (int, 'Facebook', 0), 'FACEBOOK_INCL_POSTER': (int, 'Facebook', 1), 'FACEBOOK_INCL_SUBJECT': (int, 'Facebook', 1), 'FACEBOOK_ON_PLAY': (int, 'Facebook', 0), diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py index ccf5bf52..c8bdc78d 100644 --- a/plexpy/notifiers.py +++ b/plexpy/notifiers.py @@ -1301,7 +1301,7 @@ class TwitterNotifier(object): {'label': 'Include Subject Line', 'value': self.incl_subject, 'name': 'twitter_incl_subject', - 'description': 'Include the subject line in the notifications.', + 'description': 'Include the subject line with the notifications.', 'input_type': 'checkbox' } ] @@ -1716,7 +1716,7 @@ class TELEGRAM(object): {'label': 'Include Subject Line', 'value': self.incl_subject, 'name': 'telegram_incl_subject', - 'description': 'Include the subject line in the notifications.', + 'description': 'Include the subject line with the notifications.', 'input_type': 'checkbox' } ] @@ -1814,7 +1814,7 @@ class SLACK(object): {'label': 'Include Subject Line', 'value': self.incl_subject, 'name': 'slack_incl_subject', - 'description': 'Include the subject line in the notifications.', + 'description': 'Include the subject line with the notifications.', 'input_type': 'checkbox' } ] @@ -2087,6 +2087,7 @@ class FacebookNotifier(object): self.app_id = plexpy.CONFIG.FACEBOOK_APP_ID self.app_secret = plexpy.CONFIG.FACEBOOK_APP_SECRET self.group_id = plexpy.CONFIG.FACEBOOK_GROUP + self.incl_pmslink = plexpy.CONFIG.FACEBOOK_INCL_PMSLINK self.incl_poster = plexpy.CONFIG.FACEBOOK_INCL_POSTER self.incl_subject = plexpy.CONFIG.FACEBOOK_INCL_SUBJECT @@ -2144,10 +2145,27 @@ class FacebookNotifier(object): poster_url = metadata.get('poster_url','') if poster_url: - if metadata['media_type'] == 'movie' or metadata['media_type'] == 'show': + if metadata['media_type'] == 'movie': title = metadata['title'] subtitle = metadata['year'] rating_key = metadata['rating_key'] + 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 = metadata['title'] + subtitle = metadata['year'] + rating_key = metadata['rating_key'] + 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' % (metadata['grandparent_title'], metadata['title']) @@ -2155,26 +2173,44 @@ class FacebookNotifier(object): '\xc2\xb7'.decode('utf8'), metadata['media_index']) rating_key = metadata['rating_key'] + 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 = '' rating_key = metadata['rating_key'] + 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'] rating_key = metadata['parent_rating_key'] - - caption = 'View in Plex Web.' + if metadata.get('lastfm_url',''): + poster_link = metadata.get('lastfm_url', '') + caption = 'View on Last.fm.' # Build Facebook post attachment - attachment['link'] = 'http://app.plex.tv/web/app#!/server/' + plexpy.CONFIG.PMS_IDENTIFIER + \ - '/details/%2Flibrary%2Fmetadata%2F' + rating_key + if self.incl_pmslink: + caption = 'View on Plex Web.' + attachment['link'] = 'http://app.plex.tv/web/app#!/server/' + plexpy.CONFIG.PMS_IDENTIFIER + \ + '/details/%2Flibrary%2Fmetadata%2F' + rating_key + attachment['caption'] = caption + elif poster_link: + attachment['link'] = poster_link + attachment['caption'] = caption + else: + attachment['link'] = poster_url + attachment['picture'] = poster_url attachment['name'] = title attachment['description'] = subtitle - attachment['caption'] = caption try: api.put_wall_post(profile_id=self.group_id, message=message, attachment=attachment) @@ -2200,7 +2236,7 @@ class FacebookNotifier(object): Step 4: Go to App Review and toggle public to Yes.
\ Step 5: Fill in the PlexPy URL below with the exact same URL from Step 3.
\ Step 6: Fill in the App ID and App Secret below.
\ - Step 7: Click the Request Authorization button below.
\ + Step 7: Click the Request Authorization button below.
\ Step 8: Fill in the Group ID below.', 'input_type': 'help' }, @@ -2237,13 +2273,20 @@ class FacebookNotifier(object): {'label': 'Include Poster Image', 'value': self.incl_poster, 'name': 'facebook_incl_poster', - 'description': 'Include a poster and link in the notifications.', + 'description': 'Include a poster with the notifications.', + 'input_type': 'checkbox' + }, + {'label': 'Include Link to Plex Web', + 'value': self.incl_pmslink, + 'name': 'facebook_incl_pmslink', + 'description': 'Include a link to the media in Plex Web with the notifications.
' + 'If disabled, the link will go to IMDB, TVDB, TMDb, or Last.fm instead, if available.', 'input_type': 'checkbox' }, {'label': 'Include Subject Line', 'value': self.incl_subject, 'name': 'facebook_incl_subject', - 'description': 'Include the subject line in the notifications.', + 'description': 'Include the subject line with the notifications.', 'input_type': 'checkbox' } ]