mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-07 13:41:15 -07:00
Move get poster to notification handler
This commit is contained in:
parent
b1ecff3d10
commit
0e53252a27
3 changed files with 63 additions and 51 deletions
|
@ -1479,6 +1479,13 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
|
|||
<td><strong>{duration}</strong></td>
|
||||
<td>The duration (in minutes) for the item.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>{poster_url}</strong></td>
|
||||
<td>
|
||||
A URL for the movie or TV show poster.<br />
|
||||
<p class="small-muted">(PMS agent must be Freebase or TheTVDB)</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>{imdb_id}</strong></td>
|
||||
<td>The IMDB ID for the movie. <span class="small-muted">(e.g. tt2488496)</span>
|
||||
|
|
|
@ -14,9 +14,13 @@
|
|||
# along with PlexPy. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
import arrow
|
||||
import json
|
||||
from httplib import HTTPConnection
|
||||
import openanything
|
||||
import re
|
||||
import time
|
||||
import arrow
|
||||
import urllib2
|
||||
|
||||
from plexpy import logger, config, notifiers, database, helpers, plextv, pmsconnect
|
||||
import plexpy
|
||||
|
@ -495,6 +499,47 @@ def build_notify_text(session=None, timeline=None, state=None):
|
|||
metadata['lastfm_id'] = metadata['guid'].split('lastfm://')[1].rsplit('/', 1)[0]
|
||||
metadata['lastfm_url'] = 'https://www.last.fm/music/' + metadata['lastfm_id']
|
||||
|
||||
# Get posters (only IMDB and TheTVDB supported)
|
||||
if metadata['media_type'] == 'movie' and metadata.get('imdb_id', ''):
|
||||
uri = '/?i=' + metadata['imdb_id']
|
||||
|
||||
# Get poster using OMDb API
|
||||
http_handler = HTTPConnection("www.omdbapi.com")
|
||||
http_handler.request('GET', uri)
|
||||
response = http_handler.getresponse()
|
||||
request_status = response.status
|
||||
|
||||
if request_status == 200:
|
||||
data = json.loads(response.read())
|
||||
poster_url = data.get('Poster', '')
|
||||
metadata['poster_url'] = poster_url if poster_url != 'N/A' else ''
|
||||
elif request_status >= 400 and request_status < 500:
|
||||
logger.warn(u"PlexPy Notifiers :: Unable to retrieve IMDB poster: %s" % response.reason)
|
||||
else:
|
||||
logger.warn(u"PlexPy Notifiers :: Unable to retrieve IMDB poster.")
|
||||
|
||||
elif (metadata['media_type'] == 'show' or metadata['media_type'] == 'episode') \
|
||||
and (metadata.get('imdb_id', '') or metadata.get('thetvdb_id', '')):
|
||||
if metadata.get('imdb_id', ''):
|
||||
uri = '/lookup/shows?imdb=' + metadata['imdb_id']
|
||||
elif metadata.get('thetvdb_id', ''):
|
||||
uri = '/lookup/shows?thetvdb=' + metadata['thetvdb_id']
|
||||
|
||||
# Get poster using TVmaze API
|
||||
request = urllib2.Request('http://api.tvmaze.com' + uri)
|
||||
opener = urllib2.build_opener(openanything.SmartRedirectHandler())
|
||||
response = opener.open(request)
|
||||
request_status = response.status
|
||||
|
||||
if request_status == 301:
|
||||
data = json.loads(response.read())
|
||||
image = data.get('image', '')
|
||||
metadata['poster_url'] = image.get('original', image.get('medium',''))
|
||||
elif request_status >= 400 and request_status < 500:
|
||||
logger.warn(u"PlexPy Notifiers :: Unable to retrieve TVmaze poster: %s" % response.reason)
|
||||
else:
|
||||
logger.warn(u"PlexPy Notifiers :: Unable to retrieve TVmaze poster.")
|
||||
|
||||
# Fix metadata params for notify recently added grandparent
|
||||
if state == 'created' and plexpy.CONFIG.NOTIFY_RECENTLY_ADDED_GRANDPARENT:
|
||||
show_name = metadata['title']
|
||||
|
@ -576,6 +621,7 @@ def build_notify_text(session=None, timeline=None, state=None):
|
|||
'tagline': metadata['tagline'],
|
||||
'rating': metadata['rating'],
|
||||
'duration': duration,
|
||||
'poster_url': metadata.get('poster_url',''),
|
||||
'imdb_id': metadata.get('imdb_id',''),
|
||||
'imdb_url': metadata.get('imdb_url',''),
|
||||
'thetvdb_id': metadata.get('thetvdb_id',''),
|
||||
|
|
|
@ -2127,63 +2127,22 @@ class FacebookNotifier(object):
|
|||
attachment = {}
|
||||
|
||||
if self.incl_poster and 'metadata' in kwargs:
|
||||
poster = ''
|
||||
caption = 'View in Plex Web.'
|
||||
metadata = kwargs['metadata']
|
||||
poster_url = metadata.get('poster_url','')
|
||||
caption = 'View in Plex Web.'
|
||||
|
||||
if metadata['media_type'] == 'movie' and metadata.get('imdb_id', ''):
|
||||
if metadata['media_type'] == 'movie' or metadata['media_type'] == 'show':
|
||||
title = metadata['title']
|
||||
subtitle = metadata['year']
|
||||
uri = '/?i=' + metadata['imdb_id']
|
||||
elif metadata['media_type'] == 'episode':
|
||||
title = metadata['grandparent_title'] + ' - ' + metadata['title']
|
||||
subtitle = 'S' + metadata['parent_media_index'] + ' ' + '\xc2\xb7'.decode('utf8') + \
|
||||
' E' + metadata['media_index']
|
||||
|
||||
# Get poster using OMDb API
|
||||
http_handler = HTTPConnection("www.omdbapi.com")
|
||||
http_handler.request('GET', uri)
|
||||
response = http_handler.getresponse()
|
||||
request_status = response.status
|
||||
|
||||
if request_status == 200:
|
||||
data = json.loads(response.read())
|
||||
poster = data.get('Poster', '')
|
||||
elif request_status >= 400 and request_status < 500:
|
||||
logger.warn(u"PlexPy Notifiers :: Unable to retrieve IMDB poster: %s" % response.reason)
|
||||
else:
|
||||
logger.warn(u"PlexPy Notifiers :: Unable to retrieve IMDB poster.")
|
||||
|
||||
elif (metadata['media_type'] == 'show' or metadata['media_type'] == 'episode') \
|
||||
and (metadata.get('imdb_id', '') or metadata.get('thetvdb_id', '')):
|
||||
if metadata['media_type'] == 'show':
|
||||
title = metadata['title']
|
||||
subtitle = metadata['year']
|
||||
elif metadata['media_type'] == 'episode':
|
||||
title = metadata['grandparent_title'] + ' - ' + metadata['title']
|
||||
subtitle = 'S' + metadata['parent_media_index'] + ' ' + '\xc2\xb7'.decode('utf8') + \
|
||||
' E' + metadata['media_index']
|
||||
|
||||
if metadata.get('imdb_id', ''):
|
||||
uri = '/lookup/shows?imdb=' + metadata['imdb_id']
|
||||
elif metadata.get('thetvdb_id', ''):
|
||||
uri = '/lookup/shows?thetvdb=' + metadata['thetvdb_id']
|
||||
|
||||
# Get poster using TVmaze API
|
||||
request = urllib2.Request('http://api.tvmaze.com' + uri)
|
||||
opener = urllib2.build_opener(openanything.SmartRedirectHandler())
|
||||
response = opener.open(request)
|
||||
request_status = response.status
|
||||
|
||||
if request_status == 301:
|
||||
data = json.loads(response.read())
|
||||
image = data.get('image', '')
|
||||
poster = image.get('original', image.get('medium',''))
|
||||
elif request_status >= 400 and request_status < 500:
|
||||
logger.warn(u"PlexPy Notifiers :: Unable to retrieve TVmaze poster: %s" % response.reason)
|
||||
else:
|
||||
logger.warn(u"PlexPy Notifiers :: Unable to retrieve TVmaze poster.")
|
||||
|
||||
if poster and poster != 'N/A':
|
||||
if poster_url:
|
||||
attachment['link'] = 'http://app.plex.tv/web/app#!/server/' + plexpy.CONFIG.PMS_IDENTIFIER + \
|
||||
'/details/%2Flibrary%2Fmetadata%2F' + metadata['rating_key']
|
||||
attachment['picture'] = poster
|
||||
attachment['picture'] = poster_url
|
||||
attachment['name'] = title
|
||||
attachment['description'] = subtitle
|
||||
attachment['caption'] = caption
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue