Update pms_image_proxy to work with web URLs

This commit is contained in:
JonnyWong16 2020-02-15 20:14:50 -08:00
parent 26f10b2c3d
commit 13a45facf9
4 changed files with 30 additions and 44 deletions

View file

@ -62,7 +62,6 @@ DOCUMENTATION :: END
% if session is not None: % if session is not None:
<% <%
from collections import defaultdict from collections import defaultdict
from urllib import quote
from plexpy import helpers from plexpy import helpers
from plexpy.common import VIDEO_RESOLUTION_OVERRIDES, AUDIO_CODEC_OVERRIDES, EXTRA_TYPES from plexpy.common import VIDEO_RESOLUTION_OVERRIDES, AUDIO_CODEC_OVERRIDES, EXTRA_TYPES
import plexpy import plexpy
@ -81,14 +80,11 @@ DOCUMENTATION :: END
<div class="dashboard-activity-container"> <div class="dashboard-activity-container">
<% <%
if data['live'] == 1: if data['live'] == 1:
background_url = 'images/art-live.png' background_url = 'pms_image_proxy?img=' + data['art'] + '&width=500&height=280&opacity=40&background=282828&blur=3&fallback=art-live&refresh=true'
elif data['channel_stream'] == 0: elif data['channel_stream'] == 0:
background_url = 'pms_image_proxy?img=' + data['art'] + '&width=500&height=280&opacity=40&background=282828&blur=3&fallback=art&refresh=true' background_url = 'pms_image_proxy?img=' + data['art'] + '&width=500&height=280&opacity=40&background=282828&blur=3&fallback=art&refresh=true'
else: else:
if (data['art'] and data['art'].startswith('http')) or (data['thumb'] and data['thumb'].startswith('http')): background_url = 'pms_image_proxy?img=' + (data['art'] or data['thumb']) + '&width=500&height=280&fallback=art&refresh=true&clip=true'
background_url = data['art']
else:
background_url = 'pms_image_proxy?img=' + quote(data['art'] or data['thumb']) + '&width=500&height=280&fallback=art&refresh=true&clip=true'
%> %>
<div id="background-${sk}" class="dashboard-activity-background" style="background-image: url(${background_url});"> <div id="background-${sk}" class="dashboard-activity-background" style="background-image: url(${background_url});">
<div class="dashboard-activity-poster-container hidden-xs"> <div class="dashboard-activity-poster-container hidden-xs">
@ -96,16 +92,7 @@ DOCUMENTATION :: END
<div id="poster-${sk}-bg" class="dashboard-activity-poster" style="background-image: url(pms_image_proxy?img=${data['parent_thumb']}&width=300&height=300&opacity=60&background=282828&blur=3&fallback=cover&refresh=true);"></div> <div id="poster-${sk}-bg" class="dashboard-activity-poster" style="background-image: url(pms_image_proxy?img=${data['parent_thumb']}&width=300&height=300&opacity=60&background=282828&blur=3&fallback=cover&refresh=true);"></div>
% endif % endif
% if data['live'] == 1: % if data['live'] == 1:
<% <div id="poster-${sk}" class="dashboard-activity-poster" style="background-image: url(pms_image_proxy?img=${data['grandparent_thumb'] or data['thumb']}&width=300&height=450&fallback=poster-live&refresh=true);"></div>
live_thumb = data['grandparent_thumb'] or data['thumb']
%>
% if live_thumb.startswith('http'):
<div id="poster-${sk}" class="dashboard-activity-poster" style="background-image: url(${live_thumb});"></div>
% elif live_thumb:
<div id="poster-${sk}" class="dashboard-activity-poster" style="background-image: url(pms_image_proxy?img=${live_thumb}&width=300&height=450&fallback=poster&refresh=true);"></div>
% else:
<div id="poster-${sk}" class="dashboard-activity-poster" style="background-image: url(images/poster-live.png);"></div>
% endif
% elif data['channel_stream'] == 0: % elif data['channel_stream'] == 0:
% if data['media_type'] == 'movie': % if data['media_type'] == 'movie':
<a id="poster-url-${sk}" href="${href}" title="${data['title']}"> <a id="poster-url-${sk}" href="${href}" title="${data['title']}">
@ -129,13 +116,8 @@ DOCUMENTATION :: END
<div id="poster-${sk}" class="dashboard-activity-poster" style="background-image: url(images/poster.png);"></div> <div id="poster-${sk}" class="dashboard-activity-poster" style="background-image: url(images/poster.png);"></div>
% endif % endif
% else: % else:
% if data['channel_icon'].startswith('http'):
<div id="poster-${sk}" class="dashboard-activity-poster-blur" style="background-image: url(${data['channel_icon']});"></div>
<div id="poster-${sk}" class="dashboard-activity-cover" style="background-image: url(${data['channel_icon']});"></div>
% else:
<div id="poster-${sk}" class="dashboard-activity-poster" style="background-image: url(pms_image_proxy?img=${data['channel_icon']}&width=300&height=300&opacity=60&background=282828&blur=3&fallback=cover&refresh=true);"></div> <div id="poster-${sk}" class="dashboard-activity-poster" style="background-image: url(pms_image_proxy?img=${data['channel_icon']}&width=300&height=300&opacity=60&background=282828&blur=3&fallback=cover&refresh=true);"></div>
<div id="poster-${sk}" class="dashboard-activity-cover" style="background-image: url(pms_image_proxy?img=${data['channel_icon']}&width=300&height=300&fallback=cover&refresh=true);"></div> <div id="poster-${sk}" class="dashboard-activity-cover" style="background-image: url(pms_image_proxy?img=${data['channel_icon']}&width=300&height=300&fallback=cover&refresh=true);"></div>
% endif
% endif % endif
</div> </div>
<div class="dashboard-activity-info-icon"> <div class="dashboard-activity-info-icon">

View file

@ -34,11 +34,21 @@ DEFAULT_USER_THUMB = "interfaces/default/images/gravatar-default-80x80.png"
DEFAULT_POSTER_THUMB = "interfaces/default/images/poster.png" DEFAULT_POSTER_THUMB = "interfaces/default/images/poster.png"
DEFAULT_COVER_THUMB = "interfaces/default/images/cover.png" DEFAULT_COVER_THUMB = "interfaces/default/images/cover.png"
DEFAULT_ART = "interfaces/default/images/art.png" DEFAULT_ART = "interfaces/default/images/art.png"
DEFAULT_LIVE_TV_POSTER_THUMB = "interfaces/default/images/poster-live.png"
DEFAULT_LIVE_TV_ART = "interfaces/default/images/art-live.png"
ONLINE_POSTER_THUMB = "https://tautulli.com/images/poster.png" ONLINE_POSTER_THUMB = "https://tautulli.com/images/poster.png"
ONLINE_COVER_THUMB = "https://tautulli.com/images/cover.png" ONLINE_COVER_THUMB = "https://tautulli.com/images/cover.png"
ONLINE_ART = "https://tautulli.com/images/art.png" ONLINE_ART = "https://tautulli.com/images/art.png"
DEFAULT_IMAGES = {
'poster': DEFAULT_POSTER_THUMB,
'cover': DEFAULT_COVER_THUMB,
'art': DEFAULT_ART,
'poster-live': DEFAULT_LIVE_TV_POSTER_THUMB,
'poster-art': DEFAULT_LIVE_TV_ART
}
MEDIA_TYPE_HEADERS = { MEDIA_TYPE_HEADERS = {
'movie': 'Movies', 'movie': 'Movies',
'show': 'TV Shows', 'show': 'TV Shows',

View file

@ -2694,10 +2694,14 @@ class PmsConnect(object):
height = height or 1500 height = height or 1500
if img: if img:
if refresh: web_img = img.startswith('http')
if refresh and not web_img:
img = '{}/{}'.format(img.rstrip('/'), int(time.time())) img = '{}/{}'.format(img.rstrip('/'), int(time.time()))
if clip: if web_img:
params = {'url': '%s' % img}
elif clip:
params = {'url': '%s&%s' % (img, urllib.urlencode({'X-Plex-Token': self.token}))} params = {'url': '%s&%s' % (img, urllib.urlencode({'X-Plex-Token': self.token}))}
else: else:
params = {'url': 'http://127.0.0.1:32400%s?%s' % (img, urllib.urlencode({'X-Plex-Token': self.token}))} params = {'url': 'http://127.0.0.1:32400%s?%s' % (img, urllib.urlencode({'X-Plex-Token': self.token}))}

View file

@ -4038,7 +4038,7 @@ class WebInterface(object):
background (str): 282828 background (str): 282828
blur (str): 3 blur (str): 3
img_format (str): png img_format (str): png
fallback (str): "poster", "cover", "art" fallback (str): "poster", "cover", "art", "poster-live", "poster-art"
refresh (bool): True or False whether to refresh the image cache refresh (bool): True or False whether to refresh the image cache
return_hash (bool): True or False to return the self-hosted image hash instead of the image return_hash (bool): True or False to return the self-hosted image hash instead of the image
@ -4058,9 +4058,12 @@ class WebInterface(object):
else: else:
img = '/library/metadata/{}/thumb'.format(rating_key) img = '/library/metadata/{}/thumb'.format(rating_key)
img_split = img.split('/') web_img = img.startswith('http')
img = '/'.join(img_split[:5])
rating_key = rating_key or img_split[3] if not web_img:
img_split = img.split('/')
img = '/'.join(img_split[:5])
rating_key = rating_key or img_split[3]
img_hash = notification_handler.set_hash_image_info( img_hash = notification_handler.set_hash_image_info(
img=img, rating_key=rating_key, width=width, height=height, img=img, rating_key=rating_key, width=width, height=height,
@ -4111,15 +4114,8 @@ class WebInterface(object):
except Exception as e: except Exception as e:
logger.warn(u'Failed to get image %s, falling back to %s.' % (img, fallback)) logger.warn(u'Failed to get image %s, falling back to %s.' % (img, fallback))
fbi = None if fallback in common.DEFAULT_IMAGES:
if fallback == 'poster': fbi = common.DEFAULT_IMAGES[fallback]
fbi = common.DEFAULT_POSTER_THUMB
elif fallback == 'cover':
fbi = common.DEFAULT_COVER_THUMB
elif fallback == 'art':
fbi = common.DEFAULT_ART
if fbi:
fp = os.path.join(plexpy.PROG_DIR, 'data', fbi) fp = os.path.join(plexpy.PROG_DIR, 'data', fbi)
return serve_file(path=fp, content_type='image/png') return serve_file(path=fp, content_type='image/png')
@ -4137,14 +4133,8 @@ class WebInterface(object):
img_hash = args[0].split('.')[0] img_hash = args[0].split('.')[0]
if img_hash in ('poster', 'cover', 'art'): if img_hash in common.DEFAULT_IMAGES:
if img_hash == 'poster': fbi = common.DEFAULT_IMAGES[img_hash]
fbi = common.DEFAULT_POSTER_THUMB
elif img_hash == 'cover':
fbi = common.DEFAULT_COVER_THUMB
elif img_hash == 'art':
fbi = common.DEFAULT_ART
fp = os.path.join(plexpy.PROG_DIR, 'data', fbi) fp = os.path.join(plexpy.PROG_DIR, 'data', fbi)
return serve_file(path=fp, content_type='image/png') return serve_file(path=fp, content_type='image/png')