Skip to content

Add Unsplash illustration collection mode (and fix import)#692

Open
k4m454k wants to merge 1 commit into
fatihak:mainfrom
k4m454k:unsplash-add-illustrations
Open

Add Unsplash illustration collection mode (and fix import)#692
k4m454k wants to merge 1 commit into
fatihak:mainfrom
k4m454k:unsplash-add-illustrations

Conversation

@k4m454k

@k4m454k k4m454k commented May 20, 2026

Copy link
Copy Markdown

This PR updates the Unsplash plugin so it can load not only regular photos, but also Unsplash illustration assets from collections.

Previously, the plugin used /photos/random when no search query was provided. That works for photo collections, but Unsplash does not return asset_type: illustration items through that endpoint. Collections that contain only illustrations therefore failed with No photos found, even though /collections/{id}/photos returned valid items.

The plugin now supports an explicit content type setting:

  • Photos keeps the existing behavior.
  • Illustrations from collections loads only asset_type: illustration items.
  • Photos and illustrations from collections loads both photos and illustrations.

Key Changes

  • Added asset_type handling in src/plugins/unsplash/unsplash.py.
  • Preserved existing photo behavior via:
    • /search/photos when search_query is set.
    • /photos/random otherwise.
  • Added collection-based loading for illustration and mixed modes using:
    • /collections/{collection_id}/photos
  • Added support for multiple comma-separated collection IDs.
  • Added filtering by asset_type.
  • Added image URL fallback order:
    • selected size (regular on low-resource devices, full otherwise)
    • regular
    • small
    • full
    • raw
  • Added clear runtime errors for invalid combinations:
    • illustration or mixed without collections.
    • illustration or mixed with search_query.
    • collections with no matching assets.
  • Updated src/plugins/unsplash/settings.html with a new Content Type select.
  • Added tests/test_unsplash_plugin.py covering the new behavior.

Behavior Notes

  • Illustration support intentionally uses the documented collection photos endpoint rather than an undocumented /illustrations/random endpoint.
  • Search remains photo-only because Unsplash’s documented public search endpoint is /search/photos.
  • In collection-based illustration and mixed modes, orientation is passed through, but color is not sent because the collection photos endpoint does not document a color parameter.
  • No separate SVG/vector conversion is needed: Unsplash returns raster image URLs in urls.regular, urls.full, etc., and the existing image loader already downloads and converts them through Pillow.

Testing
Ran:

PYTHONDONTWRITEBYTECODE=1 python3 -m unittest tests.test_unsplash_plugin -v

Result:

Ran 5 tests in 0.054s

OK

Covered scenarios:

  • Existing photo random endpoint behavior is preserved.
  • Illustration mode uses collection endpoint and selects only illustrations.
  • Mixed mode combines photos and illustrations across multiple collections.
  • Illustration mode rejects search_query.
  • Empty/no-match illustration collections produce a clear error.

@saulobenignoBraza

Copy link
Copy Markdown

Where can I find the collection ID? I can't seem to find it anywhere on the Unsplash website. All collections appear to be identified by name now

@k4m454k

k4m454k commented Jun 24, 2026

Copy link
Copy Markdown
Author

Where can I find the collection ID? I can't seem to find it anywhere on the Unsplash website. All collections appear to be identified by name now

The collection ID is the part immediately after /collections/ in the URL. For example, in /collections/QZU1xPqbVYM/its-getting-dark, the ID is QZU1xPqbVYM. I’ll update the helper text to make this clearer.

@saulobenignoBraza

Copy link
Copy Markdown

Got it, thanks for the explanation

It worked with numeric IDs, for example:
https://unsplash.com/pt-br/cole%C3%A7%C3%B5es/3660951/world
https://unsplash.com/pt-br/cole%C3%A7%C3%B5es/4885435/pastel

But IDs containing underscores, hyphens, or letters failed, for example:

https://unsplash.com/pt-br/cole%C3%A7%C3%B5es/2_1SzDWjSSs/travel
https://unsplash.com/pt-br/cole%C3%A7%C3%B5es/_GoY-Muh7Po/business

The example you gave also did not work for me: QZU1xPqbVYM

/collections/QZU1xPqbVYM/its-getting-dark

The error I get is:

Error! An error occurred: Failed to fetch image from Unsplash API, please check logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants