Skip to content

Commit 5a153b1

Browse files
fix: Better Scraper Image Processing (#2821)
* add additional case for scraped image parsing * made scraper more fault tolerant for missing images * re-ordered case to favor better implementations --------- Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
1 parent a6ec488 commit 5a153b1

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

mealie/services/scraper/cleaner.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ def clean_image(image: str | list | dict | None = None, default: str = "no image
8989
image attempts to parse the image field from a recipe and return a string. Currenty
9090
9191
Supported Structures:
92-
- `https://exmaple.com` - A string
93-
- `{ "url": "https://exmaple.com" }` - A dictionary with a `url` key
94-
- `["https://exmaple.com"]` - A list of strings
95-
- `[{ "url": "https://exmaple.com" }]` - A list of dictionaries with a `url` key
92+
- `https://example.com` - A string
93+
- `{ "url": "https://example.com" }` - A dictionary with a `url` key
94+
- `["https://example.com"]` - A list of strings
95+
- `[{ "url": "https://example.com" }]` - A list of dictionaries with a `url` key
9696
9797
Raises:
9898
TypeError: If the image field is not a supported type a TypeError is raised.
@@ -112,8 +112,11 @@ def clean_image(image: str | list | dict | None = None, default: str = "no image
112112
return [x["url"] for x in image]
113113
case {"url": str(image)}:
114114
return [image]
115+
case [{"@id": str(_)}, *_]:
116+
return [x["@id"] for x in image]
115117
case _:
116-
raise TypeError(f"Unexpected type for image: {type(image)}, {image}")
118+
logger.exception(f"Unexpected type for image: {type(image)}, {image}")
119+
return [default]
117120

118121

119122
def clean_instructions(steps_object: list | dict | str, default: list | None = None) -> list[dict]:

0 commit comments

Comments
 (0)