from functools import cached_property from io import BytesIO import requests from attr import attrib, attrs from PIL import Image @attrs(hash=True) class PlaylistSearchResult: image_url = attrib() id = attrib() country_code = attrib() vendor = attrib() name = attrib() owner = attrib(default=None) personalized = attrib(default=None, type=bool) followers = attrib(default=None) position = attrib(default=None) # position on ui, starts from 1 @cached_property def image(self): return Image.open(BytesIO(requests.get(self.image_url, timeout=600).content))