Make image cache use the request wrapper
This commit is contained in:
1 parent
c682b75e2d
commit
5afc7ec27d
1 file changed
+2
-2
@@ -8,7 +8,6 @@ from typing import Dict, TypedDict, NewType, TYPE_CHECKING
|
|||||||
from utils import json_load, json_save
|
from utils import json_load, json_save
|
||||||
from constants import URLType, CACHE_PATH, CACHE_DB
|
from constants import URLType, CACHE_PATH, CACHE_DB
|
||||||
|
|
||||||
import aiohttp
|
|
||||||
from PIL import Image as Image_module
|
from PIL import Image as Image_module
|
||||||
from PIL.ImageTk import PhotoImage
|
from PIL.ImageTk import PhotoImage
|
||||||
|
|
||||||
@@ -37,6 +36,7 @@ class ImageCache:
|
|||||||
|
|
||||||
def __init__(self, manager: GUIManager) -> None:
|
def __init__(self, manager: GUIManager) -> None:
|
||||||
self._root = manager._root
|
self._root = manager._root
|
||||||
|
self._twitch = manager._twitch
|
||||||
CACHE_PATH.mkdir(parents=True, exist_ok=True)
|
CACHE_PATH.mkdir(parents=True, exist_ok=True)
|
||||||
self._hashes: Hashes = json_load(CACHE_DB, default_database, merge=False)
|
self._hashes: Hashes = json_load(CACHE_DB, default_database, merge=False)
|
||||||
self._images: dict[ImageHash, Image] = {}
|
self._images: dict[ImageHash, Image] = {}
|
||||||
@@ -94,7 +94,7 @@ class ImageCache:
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
if image is None:
|
if image is None:
|
||||||
async with aiohttp.request("GET", url) as response:
|
async with self._twitch.request("GET", url) as response:
|
||||||
image = Image_module.open(io.BytesIO(await response.read()))
|
image = Image_module.open(io.BytesIO(await response.read()))
|
||||||
img_hash = self._hash(image)
|
img_hash = self._hash(image)
|
||||||
self._images[img_hash] = image
|
self._images[img_hash] = image
|
||||||
|
|||||||
Reference in new issue
Block a user