self,
media_item: MediaItemType,
img_type: ImageType = ImageType.THUMB,
- size: Optional[int] = None,
+ size: int = 0,
) -> bytes | None:
"""Get image data for given MedaItem."""
img_path = await self.get_image_url_for_item(
media_item: MediaItemType,
img_type: ImageType = ImageType.THUMB,
allow_local: bool = True,
- local_as_base64: bool = True,
+ local_as_base64: bool = False,
) -> str | None:
"""Get url to image for given media media_item."""
if not media_item:
return None
async def get_thumbnail(
- self, path: str, size: Optional[int] = None, base64: bool = False
+ self, path: str, size: int = 0, base64: bool = False
) -> bytes | str:
"""Get/create thumbnail image for path (image url or local path)."""
# check if we already have this cached in the db
from music_assistant.mass import MusicAssistant
-SCHEMA_VERSION = 10
+SCHEMA_VERSION = 11
TABLE_PROV_MAPPINGS = "provider_mappings"
TABLE_TRACK_LOUDNESS = "track_loudness"
# recreate missing tables
await self.__create_database_tables(db)
+ if prev_version < 11:
+ # fix for duplicate thumbs creation
+ await db.execute(f"DROP TABLE IF EXISTS {TABLE_THUMBS}")
+ # recreate missing tables
+ await self.__create_database_tables(db)
+
# store current schema version
await self.set_setting("version", str(SCHEMA_VERSION), db=db)
f"""CREATE TABLE IF NOT EXISTS {TABLE_THUMBS}(
id INTEGER PRIMARY KEY AUTOINCREMENT,
path TEXT NOT NULL,
- size INTEGER NULL,
+ size INTEGER DEFAULT 0,
data BLOB,
UNIQUE(path, size));"""
)
mass: MusicAssistant, path: str, size: Optional[int]
) -> bytes:
"""Create thumbnail from image url."""
- if not size:
- size = 200
img_data = None
if path.startswith("http"):
async with mass.http_session.get(path, verify_ssl=False) as response:
def _create_image():
data = BytesIO(img_data)
img = Image.open(data)
- img.thumbnail((size, size), Image.ANTIALIAS)
+ if size:
+ img.thumbnail((size, size), Image.ANTIALIAS)
img.save(data, format="png")
return data.getvalue()