Disabled Album Art caching as it was causing sync issues
This commit is contained in:
+48
-27
@@ -1,5 +1,5 @@
|
|||||||
# Versioning
|
# Versioning
|
||||||
APP_VERSION = "0.0.1"
|
APP_VERSION = "0.0.2"
|
||||||
DEVELOPER = "nutty"
|
DEVELOPER = "nutty"
|
||||||
|
|
||||||
|
|
||||||
@@ -262,29 +262,52 @@ try:
|
|||||||
"Thumbnail": None
|
"Thumbnail": None
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add the album art (i.e. "Thumbnail") as a Base64 string.
|
# CACHE THE THUMBNAIL, DON'T ENCODE IT EVERY TIME, IT'S SLOW AS FUCK
|
||||||
# We will cache this so we don't have to read it every single call.
|
# # Add the album art (i.e. "Thumbnail") as a Base64 string.
|
||||||
# Use the track title and artist as the key -> {title} - {artist}
|
# # We will cache this so we don't have to read it every single call.
|
||||||
|
# # Use the track title and artist as the key -> {title} - {artist}
|
||||||
|
|
||||||
# Build the key
|
# # Build the key
|
||||||
title = raw_media.title if raw_media else "Unknown"
|
# title = raw_media.title if raw_media else "Unknown"
|
||||||
artist = raw_media.artist if raw_media else "Unknown"
|
# artist = raw_media.artist if raw_media else "Unknown"
|
||||||
track_key = f"{title} - {artist}"
|
# track_key = f"{title} - {artist}"
|
||||||
|
|
||||||
# Check if the album art is cached.
|
# # Check if the album art is cached.
|
||||||
# If yes:
|
# # If yes:
|
||||||
# - Retrieve it from the cache.
|
# # - Retrieve it from the cache.
|
||||||
# - Add it to the payload
|
# # - Add it to the payload
|
||||||
if app_id in ARTWORK_CACHE and ARTWORK_CACHE[app_id]["track_key"] == track_key:
|
# if app_id in ARTWORK_CACHE and ARTWORK_CACHE[app_id]["track_key"] == track_key:
|
||||||
media_data["Thumbnail"] = ARTWORK_CACHE[app_id]["base64"]
|
# media_data["Thumbnail"] = ARTWORK_CACHE[app_id]["base64"]
|
||||||
|
|
||||||
# If not
|
# # If not
|
||||||
# - Read the Base64 string
|
# # - Read the Base64 string
|
||||||
# - Cache the Base64 string
|
# # - Cache the Base64 string
|
||||||
# - Add it to the payload
|
# # - Add it to the payload
|
||||||
elif raw_media and raw_media.thumbnail:
|
# elif raw_media and raw_media.thumbnail:
|
||||||
|
# try:
|
||||||
|
# # Read the Base64 string
|
||||||
|
# stream_ref = raw_media.thumbnail
|
||||||
|
# stream = await stream_ref.open_read_async()
|
||||||
|
# reader = DataReader(stream.get_input_stream_at(0))
|
||||||
|
# await reader.load_async(stream.size)
|
||||||
|
# buffer = bytearray(stream.size)
|
||||||
|
# reader.read_bytes(buffer)
|
||||||
|
|
||||||
|
# img = Image.open(io.BytesIO(buffer))
|
||||||
|
# base64_art = f"data:image/png;base64,{base64.b64encode(buffer).decode('utf-8')}"
|
||||||
|
|
||||||
|
# # Cache the Base64 string
|
||||||
|
# ARTWORK_CACHE[app_id] = {"track_key": track_key, "base64": base64_art}
|
||||||
|
|
||||||
|
# # Add it to the payload
|
||||||
|
# media_data["Thumbnail"] = base64_art
|
||||||
|
# except Exception:
|
||||||
|
# pass
|
||||||
|
|
||||||
|
# Read the Base64 string
|
||||||
|
base64_art = None
|
||||||
|
if raw_media and raw_media.thumbnail:
|
||||||
try:
|
try:
|
||||||
# Read the Base64 string
|
|
||||||
stream_ref = raw_media.thumbnail
|
stream_ref = raw_media.thumbnail
|
||||||
stream = await stream_ref.open_read_async()
|
stream = await stream_ref.open_read_async()
|
||||||
reader = DataReader(stream.get_input_stream_at(0))
|
reader = DataReader(stream.get_input_stream_at(0))
|
||||||
@@ -294,14 +317,12 @@ try:
|
|||||||
|
|
||||||
img = Image.open(io.BytesIO(buffer))
|
img = Image.open(io.BytesIO(buffer))
|
||||||
base64_art = f"data:image/png;base64,{base64.b64encode(buffer).decode('utf-8')}"
|
base64_art = f"data:image/png;base64,{base64.b64encode(buffer).decode('utf-8')}"
|
||||||
|
|
||||||
# Cache the Base64 string
|
|
||||||
ARTWORK_CACHE[app_id] = {"track_key": track_key, "base64": base64_art}
|
|
||||||
|
|
||||||
# Add it to the payload
|
|
||||||
media_data["Thumbnail"] = base64_art
|
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
# Fallback if the stream fails to open or read
|
||||||
|
base64_art = None
|
||||||
|
|
||||||
|
# Add it to the payload
|
||||||
|
media_data["Thumbnail"] = base64_art
|
||||||
|
|
||||||
# Finally, assemble all the data into a session object, and add it to the session list
|
# Finally, assemble all the data into a session object, and add it to the session list
|
||||||
sessions_list.append({
|
sessions_list.append({
|
||||||
|
|||||||
Reference in New Issue
Block a user