more removal of cloud services, progress on setup wizard

This commit is contained in:
2021-02-06 00:21:58 +01:00
parent 38f0a44fa0
commit 3fb7f4ddd1
4 changed files with 294 additions and 373 deletions

View File

@@ -15,11 +15,9 @@
# You should have received a copy of the GNU General Public License
# along with Tautulli. If not, see <http://www.gnu.org/licenses/>.
import json
from itertools import groupby
import jellypy
from jellypy import common
from jellypy import database
from jellypy import datatables
@@ -1607,38 +1605,38 @@ class DataFactory(object):
if old_key_list and new_key_list:
mapping = get_pairs(old_key_list, new_key_list)
# TODO: Jellyfin
# if mapping:
# logger.info("Tautulli DataFactory :: Updating metadata in the database.")
# for old_key, new_key in mapping.items():
# metadata = pms_connect.get_metadata_details(new_key)
#
# if metadata:
# if metadata['media_type'] == 'show' or metadata['media_type'] == 'artist':
# # check grandparent_rating_key (2 tables)
# monitor_db.action(
# 'UPDATE session_history SET grandparent_rating_key = ? WHERE grandparent_rating_key = ?',
# [new_key, old_key])
# monitor_db.action(
# 'UPDATE session_history_metadata SET grandparent_rating_key = ? WHERE grandparent_rating_key = ?',
# [new_key, old_key])
# elif metadata['media_type'] == 'season' or metadata['media_type'] == 'album':
# # check parent_rating_key (2 tables)
# monitor_db.action(
# 'UPDATE session_history SET parent_rating_key = ? WHERE parent_rating_key = ?',
# [new_key, old_key])
# monitor_db.action(
# 'UPDATE session_history_metadata SET parent_rating_key = ? WHERE parent_rating_key = ?',
# [new_key, old_key])
# else:
# # check rating_key (2 tables)
# monitor_db.action('UPDATE session_history SET rating_key = ? WHERE rating_key = ?',
# [new_key, old_key])
# monitor_db.action('UPDATE session_history_media_info SET rating_key = ? WHERE rating_key = ?',
# [new_key, old_key])
#
# # update session_history_metadata table
# self.update_metadata_details(old_key, new_key, metadata)
# TODO: Jellyfin
# if mapping:
# logger.info("Tautulli DataFactory :: Updating metadata in the database.")
# for old_key, new_key in mapping.items():
# metadata = pms_connect.get_metadata_details(new_key)
#
# if metadata:
# if metadata['media_type'] == 'show' or metadata['media_type'] == 'artist':
# # check grandparent_rating_key (2 tables)
# monitor_db.action(
# 'UPDATE session_history SET grandparent_rating_key = ? WHERE grandparent_rating_key = ?',
# [new_key, old_key])
# monitor_db.action(
# 'UPDATE session_history_metadata SET grandparent_rating_key = ? WHERE grandparent_rating_key = ?',
# [new_key, old_key])
# elif metadata['media_type'] == 'season' or metadata['media_type'] == 'album':
# # check parent_rating_key (2 tables)
# monitor_db.action(
# 'UPDATE session_history SET parent_rating_key = ? WHERE parent_rating_key = ?',
# [new_key, old_key])
# monitor_db.action(
# 'UPDATE session_history_metadata SET parent_rating_key = ? WHERE parent_rating_key = ?',
# [new_key, old_key])
# else:
# # check rating_key (2 tables)
# monitor_db.action('UPDATE session_history SET rating_key = ? WHERE rating_key = ?',
# [new_key, old_key])
# monitor_db.action('UPDATE session_history_media_info SET rating_key = ? WHERE rating_key = ?',
# [new_key, old_key])
#
# # update session_history_metadata table
# self.update_metadata_details(old_key, new_key, metadata)
return 'Updated metadata in database.'
else:

View File

@@ -37,15 +37,11 @@ from urllib.parse import urlencode
from xml.dom import minidom
import arrow
import cloudinary
import ipwhois
import ipwhois.exceptions
import ipwhois.utils
import xmltodict
from IPy import IP
from cloudinary.api import delete_resources_by_tag
from cloudinary.uploader import upload
from cloudinary.utils import cloudinary_url
import jellypy
from jellypy import common
@@ -795,110 +791,6 @@ def delete_from_imgur(delete_hash, img_title='', fallback=''):
return False
def upload_to_cloudinary(img_data, img_title='', rating_key='', fallback=''):
""" Uploads an image to Cloudinary """
img_url = ''
if not jellypy.CONFIG.CLOUDINARY_CLOUD_NAME or not jellypy.CONFIG.CLOUDINARY_API_KEY or not jellypy.CONFIG.CLOUDINARY_API_SECRET:
logger.error(
"Tautulli Helpers :: Cannot upload image to Cloudinary. Cloudinary settings not specified in the settings.")
return img_url
cloudinary.config(
cloud_name=jellypy.CONFIG.CLOUDINARY_CLOUD_NAME,
api_key=jellypy.CONFIG.CLOUDINARY_API_KEY,
api_secret=jellypy.CONFIG.CLOUDINARY_API_SECRET
)
# Cloudinary library has very poor support for non-ASCII characters on Python 2
if jellypy.PYTHON2:
_img_title = latinToAscii(img_title, replace=True)
else:
_img_title = img_title
try:
response = upload((img_title, img_data),
public_id='{}_{}'.format(fallback, rating_key),
tags=['tautulli', fallback, str(rating_key)],
context={'title': _img_title, 'rating_key': str(rating_key), 'fallback': fallback})
logger.debug("Tautulli Helpers :: Image '{}' ({}) uploaded to Cloudinary.".format(img_title, fallback))
img_url = response.get('url', '')
except Exception as e:
logger.error(
"Tautulli Helpers :: Unable to upload image '{}' ({}) to Cloudinary: {}".format(img_title, fallback, e))
return img_url
def delete_from_cloudinary(rating_key=None, delete_all=False):
""" Deletes an image from Cloudinary """
if not jellypy.CONFIG.CLOUDINARY_CLOUD_NAME or not jellypy.CONFIG.CLOUDINARY_API_KEY or not jellypy.CONFIG.CLOUDINARY_API_SECRET:
logger.error(
"Tautulli Helpers :: Cannot delete image from Cloudinary. Cloudinary settings not specified in the settings.")
return False
cloudinary.config(
cloud_name=jellypy.CONFIG.CLOUDINARY_CLOUD_NAME,
api_key=jellypy.CONFIG.CLOUDINARY_API_KEY,
api_secret=jellypy.CONFIG.CLOUDINARY_API_SECRET
)
if delete_all:
delete_resources_by_tag('tautulli')
logger.debug("Tautulli Helpers :: Deleted all images from Cloudinary.")
elif rating_key:
delete_resources_by_tag(str(rating_key))
logger.debug("Tautulli Helpers :: Deleted images from Cloudinary with rating_key {}.".format(rating_key))
else:
logger.debug("Tautulli Helpers :: Unable to delete images from Cloudinary: No rating_key provided.")
return True
def cloudinary_transform(rating_key=None, width=1000, height=1500, opacity=100, background='000000', blur=0,
img_format='png', img_title='', fallback=None):
url = ''
if not jellypy.CONFIG.CLOUDINARY_CLOUD_NAME or not jellypy.CONFIG.CLOUDINARY_API_KEY or not jellypy.CONFIG.CLOUDINARY_API_SECRET:
logger.error(
"Tautulli Helpers :: Cannot transform image on Cloudinary. Cloudinary settings not specified in the settings.")
return url
cloudinary.config(
cloud_name=jellypy.CONFIG.CLOUDINARY_CLOUD_NAME,
api_key=jellypy.CONFIG.CLOUDINARY_API_KEY,
api_secret=jellypy.CONFIG.CLOUDINARY_API_SECRET
)
img_options = {'format': img_format,
'fetch_format': 'auto',
'quality': 'auto',
'version': timestamp(),
'secure': True}
if width != 1000:
img_options['width'] = str(width)
img_options['crop'] = 'fill'
if height != 1500:
img_options['height'] = str(height)
img_options['crop'] = 'fill'
if opacity != 100:
img_options['opacity'] = opacity
if background != '000000':
img_options['background'] = 'rgb:{}'.format(background)
if blur != 0:
img_options['effect'] = 'blur:{}'.format(blur * 100)
try:
url, options = cloudinary_url('{}_{}'.format(fallback, rating_key), **img_options)
logger.debug("Tautulli Helpers :: Image '{}' ({}) transformed on Cloudinary.".format(img_title, fallback))
except Exception as e:
logger.error(
"Tautulli Helpers :: Unable to transform image '{}' ({}) on Cloudinary: {}".format(img_title, fallback, e))
return url
def cache_image(url, image=None):
"""
Saves an image to the cache directory.

View File

@@ -19,7 +19,7 @@ from jellyfin_apiclient_python import JellyfinClient
class Jellyfin(object):
def __init__(self, url, token):
def __init__(self, url, token=None):
self.jf = JellyfinClient()
def get_library(self, section_id):
@@ -30,3 +30,6 @@ class Jellyfin(object):
def get_item(self, rating_key):
return self.jf.fetchItem(rating_key)
def login(self, user, password):
pass