mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-05 20:51:15 -07:00
parent
940c2ae6cd
commit
2d3271376b
1 changed files with 0 additions and 35 deletions
|
@ -24,8 +24,6 @@ from cloudinary.utils import cloudinary_url
|
|||
from collections import OrderedDict
|
||||
from datetime import date, datetime, timezone
|
||||
from functools import reduce, wraps
|
||||
import hashlib
|
||||
import imghdr
|
||||
from itertools import groupby
|
||||
from future.moves.itertools import islice, zip_longest
|
||||
from ipaddress import ip_address, ip_network, IPv4Address
|
||||
|
@ -943,39 +941,6 @@ def cloudinary_transform(rating_key=None, width=1000, height=1500, opacity=100,
|
|||
return url
|
||||
|
||||
|
||||
def cache_image(url, image=None):
|
||||
"""
|
||||
Saves an image to the cache directory.
|
||||
If no image is provided, tries to return the image from the cache directory.
|
||||
"""
|
||||
# Create image directory if it doesn't exist
|
||||
imgdir = os.path.join(plexpy.CONFIG.CACHE_DIR, 'images/')
|
||||
if not os.path.exists(imgdir):
|
||||
logger.debug("Tautulli Helpers :: Creating image cache directory at %s" % imgdir)
|
||||
os.makedirs(imgdir)
|
||||
|
||||
# Create a hash of the url to use as the filename
|
||||
imghash = hashlib.md5(url).hexdigest()
|
||||
imagefile = os.path.join(imgdir, imghash)
|
||||
|
||||
# If an image is provided, save it to the cache directory
|
||||
if image:
|
||||
try:
|
||||
with open(imagefile, 'wb') as cache_file:
|
||||
cache_file.write(image)
|
||||
except IOError as e:
|
||||
logger.error("Tautulli Helpers :: Failed to cache image %s: %s" % (imagefile, e))
|
||||
|
||||
# Try to return the image from the cache directory
|
||||
if os.path.isfile(imagefile):
|
||||
imagetype = 'image/' + imghdr.what(os.path.abspath(imagefile))
|
||||
else:
|
||||
imagefile = None
|
||||
imagetype = 'image/jpeg'
|
||||
|
||||
return imagefile, imagetype
|
||||
|
||||
|
||||
def build_datatables_json(kwargs, dt_columns, default_sort_col=None):
|
||||
""" Builds datatables json data
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue