import asyncio
import logging
import os
+import urllib.parse
from base64 import b64encode
from random import shuffle
from time import time
import aiofiles
from aiohttp import web
-from music_assistant.common.models.enums import (
- ImageType,
- MediaType,
- ProviderFeature,
- ProviderType,
-)
+from music_assistant.common.models.enums import ImageType, MediaType, ProviderFeature, ProviderType
from music_assistant.common.models.media_items import (
Album,
Artist,
"""Handle request for image proxy."""
path = request.query["path"]
size = int(request.query.get("size", "0"))
- image_data = await self.get_thumbnail(path, size)
+ if "%" in path:
+ # assume (double) encoded url, decode it
+ path = urllib.parse.unquote(path)
+
+ try:
+ image_data = await self.get_thumbnail(path, size)
+ except Exception as err:
+ LOGGER.exception(str(err), exc_info=err)
+
# we set the cache header to 1 year (forever)
# the client can use the checksum value to refresh when content changes
return web.Response(
continue
if not await prov.exists(path):
continue
- path = await prov.resolve(path)
- img_data = await get_embedded_image(path.local_path)
+ img_data = await get_embedded_image(prov.read_file_content(path))
if img_data:
return img_data
raise FileNotFoundError(f"Image not found: {path}")
await proc.write(chunk)
except BrokenPipeError:
break # race-condition: read enough data for tags
+ proc.write_eof()
proc.attach_task(chunk_feeder())
async with AsyncProcess(
args, enable_stdin=file_path == "-", enable_stdout=True, enable_stderr=False
) as proc:
- if file_path == "-":
- # feed the file contents to the process
- async for chunk in input_file:
- await proc.write(chunk)
-
if file_path == "-":
# feed the file contents to the process
async def chunk_feeder():
+ bytes_written = 0
async for chunk in input_file:
- await proc.write(chunk)
+ try:
+ await proc.write(chunk)
+ except BrokenPipeError:
+ break # race-condition: read enough data for tags
+
+ # grabbing the first 5MB is enough to get the embedded image
+ bytes_written += len(chunk)
+ if bytes_written > (5 * 1024000):
+ break
+ proc.write_eof()
proc.attach_task(chunk_feeder())