mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-09 03:04:54 -04:00
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>
This commit is contained in:
parent
a6ec488864
commit
5a153b178d
@ -89,10 +89,10 @@ def clean_image(image: str | list | dict | None = None, default: str = "no image
|
|||||||
image attempts to parse the image field from a recipe and return a string. Currenty
|
image attempts to parse the image field from a recipe and return a string. Currenty
|
||||||
|
|
||||||
Supported Structures:
|
Supported Structures:
|
||||||
- `https://exmaple.com` - A string
|
- `https://example.com` - A string
|
||||||
- `{ "url": "https://exmaple.com" }` - A dictionary with a `url` key
|
- `{ "url": "https://example.com" }` - A dictionary with a `url` key
|
||||||
- `["https://exmaple.com"]` - A list of strings
|
- `["https://example.com"]` - A list of strings
|
||||||
- `[{ "url": "https://exmaple.com" }]` - A list of dictionaries with a `url` key
|
- `[{ "url": "https://example.com" }]` - A list of dictionaries with a `url` key
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
TypeError: If the image field is not a supported type a TypeError is raised.
|
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
|
|||||||
return [x["url"] for x in image]
|
return [x["url"] for x in image]
|
||||||
case {"url": str(image)}:
|
case {"url": str(image)}:
|
||||||
return [image]
|
return [image]
|
||||||
|
case [{"@id": str(_)}, *_]:
|
||||||
|
return [x["@id"] for x in image]
|
||||||
case _:
|
case _:
|
||||||
raise TypeError(f"Unexpected type for image: {type(image)}, {image}")
|
logger.exception(f"Unexpected type for image: {type(image)}, {image}")
|
||||||
|
return [default]
|
||||||
|
|
||||||
|
|
||||||
def clean_instructions(steps_object: list | dict | str, default: list | None = None) -> list[dict]:
|
def clean_instructions(steps_object: list | dict | str, default: list | None = None) -> list[dict]:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user