chore: apply pending code updates
This commit is contained in:
@@ -125,7 +125,7 @@ class ImageDownloader:
|
||||
# Check if file already exists
|
||||
if skip_existing and local_path.exists():
|
||||
if local_path.stat().st_size >= self.min_file_size:
|
||||
logger.debug(f"Image already exists: {local_path}")
|
||||
logger.debug("Image already exists: %s", local_path)
|
||||
return True
|
||||
|
||||
# Ensure parent directory exists
|
||||
@@ -137,15 +137,16 @@ class ImageDownloader:
|
||||
for attempt in range(self.max_retries):
|
||||
try:
|
||||
logger.debug(
|
||||
f"Downloading image from {url} "
|
||||
f"(attempt {attempt + 1})"
|
||||
"Downloading image from %s (attempt %d)",
|
||||
url,
|
||||
attempt + 1,
|
||||
)
|
||||
|
||||
# Use persistent session
|
||||
session = self._get_session()
|
||||
async with session.get(url) as resp:
|
||||
if resp.status == 404:
|
||||
logger.warning(f"Image not found: {url}")
|
||||
logger.warning("Image not found: %s", url)
|
||||
return False
|
||||
|
||||
resp.raise_for_status()
|
||||
@@ -168,21 +169,25 @@ class ImageDownloader:
|
||||
local_path.unlink(missing_ok=True)
|
||||
raise ImageDownloadError("Image validation failed")
|
||||
|
||||
logger.info(f"Downloaded image to {local_path}")
|
||||
logger.info("Downloaded image to %s", local_path)
|
||||
return True
|
||||
|
||||
except (aiohttp.ClientError, IOError, ImageDownloadError) as e:
|
||||
last_error = e
|
||||
if attempt < self.max_retries - 1:
|
||||
logger.warning(
|
||||
f"Download failed (attempt {attempt + 1}): {e}, "
|
||||
f"retrying in {delay}s"
|
||||
"Download failed (attempt %d): %s, retrying in %s",
|
||||
attempt + 1,
|
||||
e,
|
||||
delay,
|
||||
)
|
||||
await asyncio.sleep(delay)
|
||||
delay *= 2
|
||||
else:
|
||||
logger.error(
|
||||
f"Download failed after {self.max_retries} attempts: {e}"
|
||||
"Download failed after %d attempts: %s",
|
||||
self.max_retries,
|
||||
e,
|
||||
)
|
||||
|
||||
raise ImageDownloadError(
|
||||
@@ -211,7 +216,7 @@ class ImageDownloader:
|
||||
try:
|
||||
return await self.download_image(url, local_path, skip_existing)
|
||||
except ImageDownloadError as e:
|
||||
logger.warning(f"Failed to download poster: {e}")
|
||||
logger.warning("Failed to download poster: %s", e)
|
||||
return False
|
||||
|
||||
async def download_logo(
|
||||
@@ -236,7 +241,7 @@ class ImageDownloader:
|
||||
try:
|
||||
return await self.download_image(url, local_path, skip_existing)
|
||||
except ImageDownloadError as e:
|
||||
logger.warning(f"Failed to download logo: {e}")
|
||||
logger.warning("Failed to download logo: %s", e)
|
||||
return False
|
||||
|
||||
async def download_fanart(
|
||||
@@ -261,7 +266,7 @@ class ImageDownloader:
|
||||
try:
|
||||
return await self.download_image(url, local_path, skip_existing)
|
||||
except ImageDownloadError as e:
|
||||
logger.warning(f"Failed to download fanart: {e}")
|
||||
logger.warning("Failed to download fanart: %s", e)
|
||||
return False
|
||||
|
||||
def validate_image(self, image_path: Path) -> bool:
|
||||
@@ -280,13 +285,13 @@ class ImageDownloader:
|
||||
|
||||
# Check file size
|
||||
if image_path.stat().st_size < self.min_file_size:
|
||||
logger.warning(f"Image file too small: {image_path}")
|
||||
logger.warning("Image file too small: %s", image_path)
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"Image validation failed for {image_path}: {e}")
|
||||
logger.warning("Image validation failed for %s: %s", image_path, e)
|
||||
return False
|
||||
|
||||
async def download_all_media(
|
||||
@@ -341,7 +346,7 @@ class ImageDownloader:
|
||||
|
||||
for (media_type, _), result in zip(tasks, task_results):
|
||||
if isinstance(result, Exception):
|
||||
logger.error(f"Error downloading {media_type}: {result}")
|
||||
logger.error("Error downloading %s: %s", media_type, result)
|
||||
results[media_type] = False
|
||||
else:
|
||||
results[media_type] = result
|
||||
|
||||
@@ -209,5 +209,5 @@ def validate_nfo_xml(xml_string: str) -> bool:
|
||||
etree.fromstring(xml_string.encode('utf-8'))
|
||||
return True
|
||||
except etree.XMLSyntaxError as e:
|
||||
logger.error(f"Invalid NFO XML: {e}")
|
||||
logger.error("Invalid NFO XML: %s", e)
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user