mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 07:22:37 -07:00
Add Cloudinary image hosting option
This commit is contained in:
parent
81e04269fd
commit
6554136a8f
8 changed files with 183 additions and 50 deletions
|
@ -955,7 +955,10 @@
|
||||||
<p class="help-block">Enable to host newsletters on your own domain. This will generate a link to an HTML page where you can view the newsletter.</p>
|
<p class="help-block">Enable to host newsletters on your own domain. This will generate a link to an HTML page where you can view the newsletter.</p>
|
||||||
</div>
|
</div>
|
||||||
<div id="self_host_newsletter_options" style="overlfow: hidden; display: ${'block' if config['newsletter_self_hosted'] == 'checked' else 'none'}">
|
<div id="self_host_newsletter_options" style="overlfow: hidden; display: ${'block' if config['newsletter_self_hosted'] == 'checked' else 'none'}">
|
||||||
<p class="help-block" id="self_host_newsletter_message">Note: The <span class="inline-pre">${http_root}newsletter</span> endpoint on your domain must be publicly accessible from the internet.</p>
|
<p class="help-block" id="self_host_newsletter_message">
|
||||||
|
Note: The <span class="inline-pre">${http_root}newsletter</span> endpoint on your domain must be publicly accessible from the internet.<br>
|
||||||
|
Note: Newsletter images will be self-hosted regardless of the Image Hosting setting below.<br>
|
||||||
|
</p>
|
||||||
<p class="help-block settings-warning base-url-warning">Warning: Public Tautulli domain not set under <a data-tab-destination="tabs-web_interface" data-target="#http_base_url">Web Interface</a>.</p>
|
<p class="help-block settings-warning base-url-warning">Warning: Public Tautulli domain not set under <a data-tab-destination="tabs-web_interface" data-target="#http_base_url">Web Interface</a>.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -970,6 +973,7 @@
|
||||||
<select class="form-control" id="notify_upload_posters" name="notify_upload_posters">
|
<select class="form-control" id="notify_upload_posters" name="notify_upload_posters">
|
||||||
<option value="0" ${'selected' if config['notify_upload_posters'] == 0 else ''}>Disabled</option>
|
<option value="0" ${'selected' if config['notify_upload_posters'] == 0 else ''}>Disabled</option>
|
||||||
<option value="1" ${'selected' if config['notify_upload_posters'] == 1 else ''}>Imgur</option>
|
<option value="1" ${'selected' if config['notify_upload_posters'] == 1 else ''}>Imgur</option>
|
||||||
|
<option value="3" ${'selected' if config['notify_upload_posters'] == 3 else ''}>Cloudinary</option>
|
||||||
<option value="2" ${'selected' if config['notify_upload_posters'] == 2 else ''}>Self-hosted on public Tautulli domain</option>
|
<option value="2" ${'selected' if config['notify_upload_posters'] == 2 else ''}>Self-hosted on public Tautulli domain</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
@ -977,6 +981,7 @@
|
||||||
<p class="help-block">Select where to host Plex images for notifications and newsletters.</p>
|
<p class="help-block">Select where to host Plex images for notifications and newsletters.</p>
|
||||||
</div>
|
</div>
|
||||||
<div id="imgur_upload_options" style="overlfow: hidden; display: ${'none' if config['notify_upload_posters'] != 1 else 'block'}">
|
<div id="imgur_upload_options" style="overlfow: hidden; display: ${'none' if config['notify_upload_posters'] != 1 else 'block'}">
|
||||||
|
<p class="help-block" id="imgur_upload_message">Warning: Imgur uploads are rate-limited and newsletters may exceed the limit.</p>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="imgur_client_id">Imgur Client ID</label>
|
<label for="imgur_client_id">Imgur Client ID</label>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -994,6 +999,41 @@
|
||||||
<p class="help-block" id="self_host_image_message">Note: The <span class="inline-pre">${http_root}image</span> endpoint on your domain must be publicly accessible from the internet.</p>
|
<p class="help-block" id="self_host_image_message">Note: The <span class="inline-pre">${http_root}image</span> endpoint on your domain must be publicly accessible from the internet.</p>
|
||||||
<p class="help-block settings-warning base-url-warning">Warning: Public Tautulli domain not set under <a data-tab-destination="tabs-web_interface" data-target="#http_base_url">Web Interface</a>.</p>
|
<p class="help-block settings-warning base-url-warning">Warning: Public Tautulli domain not set under <a data-tab-destination="tabs-web_interface" data-target="#http_base_url">Web Interface</a>.</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="cloudinary_upload_options" style="overlfow: hidden; display: ${'none' if config['notify_upload_posters'] != 3 else 'block'}">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="cloudinary_cloud_name">Cloudinary Cloud Name</label>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<input type="text" class="form-control" id="cloudinary_cloud_name" name="cloudinary_cloud_name" value="${config['cloudinary_cloud_name']}" data-parsley-trigger="change">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p class="help-block">
|
||||||
|
Enter your Cloudinary Cloud Name.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="cloudinary_api_key">Cloudinary API Key</label>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<input type="text" class="form-control" id="cloudinary_api_key" name="cloudinary_api_key" value="${config['cloudinary_api_key']}" data-parsley-trigger="change">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p class="help-block">
|
||||||
|
Enter your Cloudinary API Key.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="cloudinary_api_secret">Cloudinary API Secret</label>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<input type="text" class="form-control" id="cloudinary_api_secret" name="cloudinary_api_secret" value="${config['cloudinary_api_secret']}" data-parsley-trigger="change">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p class="help-block">
|
||||||
|
Enter your Cloudinary API Secret.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" name="themoviedb_lookup" id="themoviedb_lookup" value="1" ${config['themoviedb_lookup']}> Lookup TheMovieDB Links
|
<input type="checkbox" name="themoviedb_lookup" id="themoviedb_lookup" value="1" ${config['themoviedb_lookup']}> Lookup TheMovieDB Links
|
||||||
|
@ -1041,7 +1081,7 @@
|
||||||
Add a new newsletter agent, or configure an existing newsletter agent by clicking the settings icon on the right.
|
Add a new newsletter agent, or configure an existing newsletter agent by clicking the settings icon on the right.
|
||||||
</p>
|
</p>
|
||||||
<p class="help-block settings-warning" id="newsletter_upload_warning">
|
<p class="help-block settings-warning" id="newsletter_upload_warning">
|
||||||
Note: Either <a data-tab-destination="tabs-notifications" data-target="#notify_upload_posters">Image Hosting</a> on Imgur or <a data-tab-destination="tabs-notifications" data-target="#newsletter_self_hosted">Self-Hosted Newsletters</a> must be enabled.</span>
|
Note: Either <a data-tab-destination="tabs-notifications" data-target="#notify_upload_posters">Image Hosting</a> or <a data-tab-destination="tabs-notifications" data-target="#newsletter_self_hosted">Self-Hosted Newsletters</a> must be enabled.</span>
|
||||||
</p>
|
</p>
|
||||||
<br/>
|
<br/>
|
||||||
<div id="plexpy-newsletters-table">
|
<div id="plexpy-newsletters-table">
|
||||||
|
@ -2538,6 +2578,11 @@ $(document).ready(function() {
|
||||||
} else {
|
} else {
|
||||||
$('#self_host_image_options').slideUp();
|
$('#self_host_image_options').slideUp();
|
||||||
}
|
}
|
||||||
|
if (upload_val === '3') {
|
||||||
|
$('#cloudinary_upload_options').slideDown();
|
||||||
|
} else {
|
||||||
|
$('#cloudinary_upload_options').slideUp();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$('#notify_upload_posters').change(function () {
|
$('#notify_upload_posters').change(function () {
|
||||||
imageUpload();
|
imageUpload();
|
||||||
|
@ -2557,7 +2602,7 @@ $(document).ready(function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
function newsletterUploadEnabled() {
|
function newsletterUploadEnabled() {
|
||||||
if ($('#notify_upload_posters').val() === '1' || $('#newsletter_self_hosted').is(':checked')) {
|
if ($('#notify_upload_posters').val() !== '2' || $('#newsletter_self_hosted').is(':checked')) {
|
||||||
$('#newsletter_upload_warning').hide();
|
$('#newsletter_upload_warning').hide();
|
||||||
} else {
|
} else {
|
||||||
$('#newsletter_upload_warning').show();
|
$('#newsletter_upload_warning').show();
|
||||||
|
|
|
@ -693,6 +693,12 @@ def dbcheck():
|
||||||
'img_hash TEXT, imgur_title TEXT, imgur_url TEXT, delete_hash TEXT)'
|
'img_hash TEXT, imgur_title TEXT, imgur_url TEXT, delete_hash TEXT)'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# cloudinary_lookup table :: This table keeps record of the Cloudinary uploads
|
||||||
|
c_db.execute(
|
||||||
|
'CREATE TABLE IF NOT EXISTS cloudinary_lookup (id INTEGER PRIMARY KEY AUTOINCREMENT, '
|
||||||
|
'img_hash TEXT, cloudinary_title TEXT, cloudinary_url TEXT)'
|
||||||
|
)
|
||||||
|
|
||||||
# Upgrade sessions table from earlier versions
|
# Upgrade sessions table from earlier versions
|
||||||
try:
|
try:
|
||||||
c_db.execute('SELECT started FROM sessions')
|
c_db.execute('SELECT started FROM sessions')
|
||||||
|
@ -1689,7 +1695,8 @@ def dbcheck():
|
||||||
img_hash = notification_handler.set_hash_image_info(
|
img_hash = notification_handler.set_hash_image_info(
|
||||||
rating_key=row['rating_key'], width=600, height=1000, fallback='poster')
|
rating_key=row['rating_key'], width=600, height=1000, fallback='poster')
|
||||||
data_factory.set_imgur_info(img_hash=img_hash, imgur_title=row['poster_title'],
|
data_factory.set_imgur_info(img_hash=img_hash, imgur_title=row['poster_title'],
|
||||||
imgur_url=row['poster_url'], delete_hash=row['delete_hash'])
|
imgur_url=row['poster_url'], delete_hash=row['delete_hash'],
|
||||||
|
service='imgur')
|
||||||
|
|
||||||
db.action('DROP TABLE poster_urls')
|
db.action('DROP TABLE poster_urls')
|
||||||
except sqlite3.OperationalError:
|
except sqlite3.OperationalError:
|
||||||
|
|
|
@ -115,6 +115,9 @@ _CONFIG_DEFINITIONS = {
|
||||||
'CHECK_GITHUB_INTERVAL': (int, 'General', 360),
|
'CHECK_GITHUB_INTERVAL': (int, 'General', 360),
|
||||||
'CHECK_GITHUB_ON_STARTUP': (int, 'General', 1),
|
'CHECK_GITHUB_ON_STARTUP': (int, 'General', 1),
|
||||||
'CLEANUP_FILES': (int, 'General', 0),
|
'CLEANUP_FILES': (int, 'General', 0),
|
||||||
|
'CLOUDINARY_CLOUD_NAME': (str, 'Cloudinary', ''),
|
||||||
|
'CLOUDINARY_API_KEY': (str, 'Cloudinary', ''),
|
||||||
|
'CLOUDINARY_API_SECRET': (str, 'Cloudinary', ''),
|
||||||
'CONFIG_VERSION': (int, 'Advanced', 0),
|
'CONFIG_VERSION': (int, 'Advanced', 0),
|
||||||
'DO_NOT_OVERRIDE_GIT_BRANCH': (int, 'General', 0),
|
'DO_NOT_OVERRIDE_GIT_BRANCH': (int, 'General', 0),
|
||||||
'EMAIL_ENABLED': (int, 'Email', 0),
|
'EMAIL_ENABLED': (int, 'Email', 0),
|
||||||
|
|
|
@ -1132,12 +1132,12 @@ class DataFactory(object):
|
||||||
|
|
||||||
return ip_address
|
return ip_address
|
||||||
|
|
||||||
def get_imgur_info(self, img=None, rating_key=None, width=None, height=None,
|
def get_img_info(self, img=None, rating_key=None, width=None, height=None,
|
||||||
opacity=None, background=None, blur=None, fallback=None,
|
opacity=None, background=None, blur=None, fallback=None,
|
||||||
order_by=''):
|
order_by='', service=None):
|
||||||
monitor_db = database.MonitorDatabase()
|
monitor_db = database.MonitorDatabase()
|
||||||
|
|
||||||
imgur_info = []
|
img_info = []
|
||||||
|
|
||||||
where_params = []
|
where_params = []
|
||||||
args = []
|
args = []
|
||||||
|
@ -1174,26 +1174,46 @@ class DataFactory(object):
|
||||||
if order_by:
|
if order_by:
|
||||||
order_by = 'ORDER BY ' + order_by + ' DESC'
|
order_by = 'ORDER BY ' + order_by + ' DESC'
|
||||||
|
|
||||||
query = 'SELECT imgur_title, imgur_url FROM imgur_lookup ' \
|
if service == 'imgur':
|
||||||
'JOIN image_hash_lookup ON imgur_lookup.img_hash = image_hash_lookup.img_hash ' \
|
query = 'SELECT imgur_title AS img_title, imgur_url AS img_url FROM imgur_lookup ' \
|
||||||
'%s %s' % (where, order_by)
|
'JOIN image_hash_lookup ON imgur_lookup.img_hash = image_hash_lookup.img_hash ' \
|
||||||
|
'%s %s' % (where, order_by)
|
||||||
|
elif service == 'cloudinary':
|
||||||
|
query = 'SELECT cloudinary_title AS img_title, cloudinary_url AS img_url FROM cloudinary_lookup ' \
|
||||||
|
'JOIN image_hash_lookup ON cloudinary_lookup.img_hash = image_hash_lookup.img_hash ' \
|
||||||
|
'%s %s' % (where, order_by)
|
||||||
|
else:
|
||||||
|
logger.warn(u"Tautulli DataFactory :: Unable to execute database query for get_img_info: "
|
||||||
|
"service not provided.")
|
||||||
|
return img_info
|
||||||
|
|
||||||
try:
|
try:
|
||||||
imgur_info = monitor_db.select(query, args=args)
|
img_info = monitor_db.select(query, args=args)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn(u"Tautulli DataFactory :: Unable to execute database query for get_imgur_info: %s." % e)
|
logger.warn(u"Tautulli DataFactory :: Unable to execute database query for get_img_info: %s." % e)
|
||||||
|
|
||||||
return imgur_info
|
return img_info
|
||||||
|
|
||||||
def set_imgur_info(self, img_hash=None, imgur_title=None, imgur_url=None, delete_hash=None):
|
def set_img_info(self, img_hash=None, img_title=None, img_url=None, delete_hash=None, service=None):
|
||||||
monitor_db = database.MonitorDatabase()
|
monitor_db = database.MonitorDatabase()
|
||||||
|
|
||||||
keys = {'img_hash': img_hash}
|
keys = {'img_hash': img_hash}
|
||||||
values = {'imgur_title': imgur_title,
|
|
||||||
'imgur_url': imgur_url,
|
|
||||||
'delete_hash': delete_hash}
|
|
||||||
|
|
||||||
monitor_db.upsert('imgur_lookup', key_dict=keys, value_dict=values)
|
if service == 'imgur':
|
||||||
|
table = 'imgur_lookup'
|
||||||
|
values = {'imgur_title': img_title,
|
||||||
|
'imgur_url': img_url,
|
||||||
|
'delete_hash': delete_hash}
|
||||||
|
elif service == 'cloudinary':
|
||||||
|
table = 'cloudinary_lookup'
|
||||||
|
values = {'cloudinary_title': img_title,
|
||||||
|
'cloudinary_url': img_url}
|
||||||
|
else:
|
||||||
|
logger.warn(u"Tautulli DataFactory :: Unable to execute database query for set_img_info: "
|
||||||
|
"service not provided.")
|
||||||
|
return
|
||||||
|
|
||||||
|
monitor_db.upsert(table, key_dict=keys, value_dict=values)
|
||||||
|
|
||||||
def delete_imgur_info(self, rating_key=None):
|
def delete_imgur_info(self, rating_key=None):
|
||||||
monitor_db = database.MonitorDatabase()
|
monitor_db = database.MonitorDatabase()
|
||||||
|
@ -1234,7 +1254,7 @@ class DataFactory(object):
|
||||||
poster_info = {}
|
poster_info = {}
|
||||||
|
|
||||||
if poster_key:
|
if poster_key:
|
||||||
imgur_info = self.get_imgur_info(rating_key=poster_key, order_by='height', fallback='poster')
|
imgur_info = self.get_img_info(rating_key=poster_key, order_by='height', fallback='poster', service='imgur')
|
||||||
if imgur_info:
|
if imgur_info:
|
||||||
poster_info = {'poster_title': imgur_info[0]['imgur_title'],
|
poster_info = {'poster_title': imgur_info[0]['imgur_title'],
|
||||||
'poster_url': imgur_info[0]['imgur_url']}
|
'poster_url': imgur_info[0]['imgur_url']}
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
# along with Tautulli. If not, see <http://www.gnu.org/licenses/>.
|
# along with Tautulli. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
|
import cloudinary
|
||||||
|
from cloudinary.uploader import upload
|
||||||
import datetime
|
import datetime
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
import geoip2.database, geoip2.errors
|
import geoip2.database, geoip2.errors
|
||||||
|
@ -28,7 +30,6 @@ import math
|
||||||
import maxminddb
|
import maxminddb
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
import os
|
import os
|
||||||
from ratelimit import rate_limited
|
|
||||||
import re
|
import re
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
|
@ -705,14 +706,13 @@ def anon_url(*url):
|
||||||
return '' if None in url else '%s%s' % (plexpy.CONFIG.ANON_REDIRECT, ''.join(str(s) for s in url))
|
return '' if None in url else '%s%s' % (plexpy.CONFIG.ANON_REDIRECT, ''.join(str(s) for s in url))
|
||||||
|
|
||||||
|
|
||||||
@rate_limited(450, 3600)
|
|
||||||
def upload_to_imgur(img_data, img_title='', rating_key='', fallback=''):
|
def upload_to_imgur(img_data, img_title='', rating_key='', fallback=''):
|
||||||
""" Uploads an image to Imgur """
|
""" Uploads an image to Imgur """
|
||||||
client_id = plexpy.CONFIG.IMGUR_CLIENT_ID
|
client_id = plexpy.CONFIG.IMGUR_CLIENT_ID
|
||||||
img_url = delete_hash = ''
|
img_url = delete_hash = ''
|
||||||
|
|
||||||
if not client_id:
|
if not client_id:
|
||||||
logger.error(u"Tautulli Helpers :: Cannot upload poster to Imgur. No Imgur client id specified in the settings.")
|
logger.error(u"Tautulli Helpers :: Cannot upload image to Imgur. No Imgur client id specified in the settings.")
|
||||||
return img_url, delete_hash
|
return img_url, delete_hash
|
||||||
|
|
||||||
headers = {'Authorization': 'Client-ID %s' % client_id}
|
headers = {'Authorization': 'Client-ID %s' % client_id}
|
||||||
|
@ -761,6 +761,32 @@ def delete_from_imgur(delete_hash, img_title='', fallback=''):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def upload_to_cloudinary(img_data, img_title='', rating_key='', fallback=''):
|
||||||
|
""" Uploads an image to Cloudinary """
|
||||||
|
cloudinary.config(
|
||||||
|
cloud_name=plexpy.CONFIG.CLOUDINARY_CLOUD_NAME,
|
||||||
|
api_key=plexpy.CONFIG.CLOUDINARY_API_KEY,
|
||||||
|
api_secret=plexpy.CONFIG.CLOUDINARY_API_SECRET
|
||||||
|
)
|
||||||
|
img_url = ''
|
||||||
|
|
||||||
|
if not plexpy.CONFIG.CLOUDINARY_CLOUD_NAME or not plexpy.CONFIG.CLOUDINARY_API_KEY or not plexpy.CONFIG.CLOUDINARY_API_SECRET:
|
||||||
|
logger.error(u"Tautulli Helpers :: Cannot upload image to Cloudinary. Cloudinary settings not specified in the settings.")
|
||||||
|
return img_url
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = upload('data:image/png;base64,{}'.format(base64.b64encode(img_data)),
|
||||||
|
public_id='{}_{}'.format(fallback, rating_key),
|
||||||
|
tags=[fallback, rating_key],
|
||||||
|
context={'title': img_title, 'rating_key': rating_key, 'fallback': fallback})
|
||||||
|
logger.debug(u"Tautulli Helpers :: Image '{}' ({}) uploaded to Cloudinary.".format(img_title, fallback))
|
||||||
|
img_url = response.get('url', '')
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(u"Tautulli Helpers :: Unable to upload image '{}' ({}) to Cloudinary: {}".format(img_title, fallback, e))
|
||||||
|
|
||||||
|
return img_url
|
||||||
|
|
||||||
|
|
||||||
def cache_image(url, image=None):
|
def cache_image(url, image=None):
|
||||||
"""
|
"""
|
||||||
Saves an image to the cache directory.
|
Saves an image to the cache directory.
|
||||||
|
|
|
@ -674,7 +674,7 @@ class RecentlyAdded(Newsletter):
|
||||||
return recently_added
|
return recently_added
|
||||||
|
|
||||||
def retrieve_data(self):
|
def retrieve_data(self):
|
||||||
from notification_handler import get_imgur_info, set_hash_image_info
|
from notification_handler import get_img_info, set_hash_image_info
|
||||||
|
|
||||||
if not self.config['incl_libraries']:
|
if not self.config['incl_libraries']:
|
||||||
logger.warn(u"Tautulli Newsletters :: Failed to retrieve %s newsletter data: no libraries selected." % self.NAME)
|
logger.warn(u"Tautulli Newsletters :: Failed to retrieve %s newsletter data: no libraries selected." % self.NAME)
|
||||||
|
@ -715,7 +715,7 @@ class RecentlyAdded(Newsletter):
|
||||||
item['art_url'] = ''
|
item['art_url'] = ''
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Upload posters and art to Imgur
|
# Upload posters and art to image hosting service
|
||||||
for item in movies + shows + albums:
|
for item in movies + shows + albums:
|
||||||
if item['media_type'] == 'album':
|
if item['media_type'] == 'album':
|
||||||
height = 150
|
height = 150
|
||||||
|
@ -724,17 +724,17 @@ class RecentlyAdded(Newsletter):
|
||||||
height = 225
|
height = 225
|
||||||
fallback = 'poster'
|
fallback = 'poster'
|
||||||
|
|
||||||
imgur_info = get_imgur_info(
|
img_info = get_img_info(
|
||||||
img=item['thumb'], rating_key=item['rating_key'], title=item['title'],
|
img=item['thumb'], rating_key=item['rating_key'], title=item['title'],
|
||||||
width=150, height=height, fallback=fallback)
|
width=150, height=height, fallback=fallback)
|
||||||
|
|
||||||
item['poster_url'] = imgur_info.get('imgur_url') or common.ONLINE_POSTER_THUMB
|
item['poster_url'] = img_info.get('img_url') or common.ONLINE_POSTER_THUMB
|
||||||
|
|
||||||
imgur_info = get_imgur_info(
|
img_info = get_img_info(
|
||||||
img=item['art'], rating_key=item['rating_key'], title=item['title'],
|
img=item['art'], rating_key=item['rating_key'], title=item['title'],
|
||||||
width=500, height=280, opacity=25, background='282828', blur=3, fallback='art')
|
width=500, height=280, opacity=25, background='282828', blur=3, fallback='art')
|
||||||
|
|
||||||
item['art_url'] = imgur_info.get('imgur_url')
|
item['art_url'] = img_info.get('img_url')
|
||||||
|
|
||||||
item['thumb_hash'] = ''
|
item['thumb_hash'] = ''
|
||||||
item['art_hash'] = ''
|
item['art_hash'] = ''
|
||||||
|
|
|
@ -632,9 +632,9 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, m
|
||||||
else:
|
else:
|
||||||
poster_thumb = ''
|
poster_thumb = ''
|
||||||
|
|
||||||
if plexpy.CONFIG.NOTIFY_UPLOAD_POSTERS == 1:
|
if plexpy.CONFIG.NOTIFY_UPLOAD_POSTERS in (1, 3):
|
||||||
imgur_info = get_imgur_info(img=poster_thumb, rating_key=poster_key, title=poster_title, fallback='poster')
|
img_info = get_img_info(img=poster_thumb, rating_key=poster_key, title=poster_title, fallback='poster')
|
||||||
poster_info = {'poster_title': imgur_info['imgur_title'], 'poster_url': imgur_info['imgur_url']}
|
poster_info = {'poster_title': img_info['img_title'], 'poster_url': img_info['img_url']}
|
||||||
notify_params.update(poster_info)
|
notify_params.update(poster_info)
|
||||||
elif plexpy.CONFIG.NOTIFY_UPLOAD_POSTERS == 2 and plexpy.CONFIG.HTTP_BASE_URL:
|
elif plexpy.CONFIG.NOTIFY_UPLOAD_POSTERS == 2 and plexpy.CONFIG.HTTP_BASE_URL:
|
||||||
img_hash = set_hash_image_info(img=poster_thumb, fallback='poster')
|
img_hash = set_hash_image_info(img=poster_thumb, fallback='poster')
|
||||||
|
@ -1076,9 +1076,22 @@ def format_group_index(group_keys):
|
||||||
return ','.join(num) or '0', ','.join(num00) or '00'
|
return ','.join(num) or '0', ','.join(num00) or '00'
|
||||||
|
|
||||||
|
|
||||||
def get_imgur_info(img=None, rating_key=None, title='', width=600, height=1000,
|
def get_img_info(img=None, rating_key=None, title='', width=600, height=1000,
|
||||||
opacity=100, background='000000', blur=0, fallback=None):
|
opacity=100, background='000000', blur=0, fallback=None):
|
||||||
imgur_info = {'imgur_title': '', 'imgur_url': ''}
|
img_info = {'img_title': '', 'img_url': ''}
|
||||||
|
|
||||||
|
if not rating_key and not img:
|
||||||
|
return img_info
|
||||||
|
|
||||||
|
if rating_key and not img:
|
||||||
|
if fallback == 'art':
|
||||||
|
img = '/library/metadata/{}/art'.format(rating_key)
|
||||||
|
else:
|
||||||
|
img = '/library/metadata/{}/thumb'.format(rating_key)
|
||||||
|
|
||||||
|
img_split = img.split('/')
|
||||||
|
img = '/'.join(img_split[:5])
|
||||||
|
rating_key = rating_key or img_split[3]
|
||||||
|
|
||||||
image_info = {'img': img,
|
image_info = {'img': img,
|
||||||
'rating_key': rating_key,
|
'rating_key': rating_key,
|
||||||
|
@ -1089,33 +1102,49 @@ def get_imgur_info(img=None, rating_key=None, title='', width=600, height=1000,
|
||||||
'blur': blur,
|
'blur': blur,
|
||||||
'fallback': fallback}
|
'fallback': fallback}
|
||||||
|
|
||||||
|
if plexpy.CONFIG.NOTIFY_UPLOAD_POSTERS == 1:
|
||||||
|
service = 'imgur'
|
||||||
|
elif plexpy.CONFIG.NOTIFY_UPLOAD_POSTERS == 3:
|
||||||
|
service = 'cloudinary'
|
||||||
|
else:
|
||||||
|
service = None
|
||||||
|
|
||||||
# Try to retrieve poster info from the database
|
# Try to retrieve poster info from the database
|
||||||
data_factory = datafactory.DataFactory()
|
data_factory = datafactory.DataFactory()
|
||||||
database_imgur_info = data_factory.get_imgur_info(**image_info)
|
database_img_info = data_factory.get_img_info(service=service, **image_info)
|
||||||
|
|
||||||
if database_imgur_info:
|
if database_img_info:
|
||||||
imgur_info = database_imgur_info[0]
|
img_info = database_img_info[0]
|
||||||
|
|
||||||
elif not database_imgur_info and img:
|
elif not database_img_info and img:
|
||||||
pms_connect = pmsconnect.PmsConnect()
|
pms_connect = pmsconnect.PmsConnect()
|
||||||
result = pms_connect.get_image(**image_info)
|
result = pms_connect.get_image(**image_info)
|
||||||
|
|
||||||
if result and result[0]:
|
if result and result[0]:
|
||||||
imgur_url, delete_hash = helpers.upload_to_imgur(img_data=result[0],
|
img_url = delete_hash = ''
|
||||||
img_title=title,
|
|
||||||
rating_key=rating_key,
|
|
||||||
fallback=fallback)
|
|
||||||
|
|
||||||
if imgur_url:
|
if service == 'imgur':
|
||||||
|
img_url, delete_hash = helpers.upload_to_imgur(img_data=result[0],
|
||||||
|
img_title=title,
|
||||||
|
rating_key=rating_key,
|
||||||
|
fallback=fallback)
|
||||||
|
elif service == 'cloudinary':
|
||||||
|
img_url = helpers.upload_to_cloudinary(img_data=result[0],
|
||||||
|
img_title=title,
|
||||||
|
rating_key=rating_key,
|
||||||
|
fallback=fallback)
|
||||||
|
|
||||||
|
if img_url:
|
||||||
img_hash = set_hash_image_info(**image_info)
|
img_hash = set_hash_image_info(**image_info)
|
||||||
data_factory.set_imgur_info(img_hash=img_hash,
|
data_factory.set_img_info(img_hash=img_hash,
|
||||||
imgur_title=title,
|
img_title=title,
|
||||||
imgur_url=imgur_url,
|
img_url=img_url,
|
||||||
delete_hash=delete_hash)
|
delete_hash=delete_hash,
|
||||||
|
service=service)
|
||||||
|
|
||||||
imgur_info = {'imgur_title': title, 'imgur_url': imgur_url}
|
img_info = {'img_title': title, 'img_url': img_url}
|
||||||
|
|
||||||
return imgur_info
|
return img_info
|
||||||
|
|
||||||
|
|
||||||
def set_hash_image_info(img=None, rating_key=None, width=600, height=1000,
|
def set_hash_image_info(img=None, rating_key=None, width=600, height=1000,
|
||||||
|
|
|
@ -2739,6 +2739,9 @@ class WebInterface(object):
|
||||||
"group_history_tables": checked(plexpy.CONFIG.GROUP_HISTORY_TABLES),
|
"group_history_tables": checked(plexpy.CONFIG.GROUP_HISTORY_TABLES),
|
||||||
"git_token": plexpy.CONFIG.GIT_TOKEN,
|
"git_token": plexpy.CONFIG.GIT_TOKEN,
|
||||||
"imgur_client_id": plexpy.CONFIG.IMGUR_CLIENT_ID,
|
"imgur_client_id": plexpy.CONFIG.IMGUR_CLIENT_ID,
|
||||||
|
"cloudinary_cloud_name": plexpy.CONFIG.CLOUDINARY_CLOUD_NAME,
|
||||||
|
"cloudinary_api_key": plexpy.CONFIG.CLOUDINARY_API_KEY,
|
||||||
|
"cloudinary_api_secret": plexpy.CONFIG.CLOUDINARY_API_SECRET,
|
||||||
"cache_images": checked(plexpy.CONFIG.CACHE_IMAGES),
|
"cache_images": checked(plexpy.CONFIG.CACHE_IMAGES),
|
||||||
"pms_version": plexpy.CONFIG.PMS_VERSION,
|
"pms_version": plexpy.CONFIG.PMS_VERSION,
|
||||||
"plexpy_auto_update": checked(plexpy.CONFIG.PLEXPY_AUTO_UPDATE),
|
"plexpy_auto_update": checked(plexpy.CONFIG.PLEXPY_AUTO_UPDATE),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue