mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-12 00:06:07 -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
|
@ -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',''),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue