You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tl;dr It's possible to negate exclusion patterns to turn them into an inclusion pattern using !(<pattern>). For example, if I want an external library to only include files if they're inside a directory called jpegs somewhere in the filesystem, I can use an exclusion pattern of !(**/jpegs/**) to exclude everything except those directories. The upshot being only things inside a directory called jpegs are put in the library.
I didn't see this technique called out anywhere in the docs or in past discussions, and it solved my particular use case, so I wanted to write about it here in case it's useful to other folks in similar positions and saves some searching.
My use case is that my external library folder structure looks like below (only there are multiple users rather than just alice and bob), and I wanted each of these users in Immich to have an external library that has just their photos.
photos
/2025-01-03 Some Event Name
/alice
/photo-1.jpg
/photo-2.jpg
/...
/bob
/photo-other-1.jpg
/photo-other-2.jpg
/...
/2025-02-14 Some Other Event
/alice
/...
/bob
/...
I considered a few different approaches,
Add photos/ as an external library for each user, with exclusion patterns for every other user. So user bob's external library would have patterns such as **/alice/**, **/other-user/**, **/yet-another-user/**, and so on. This works, but gets painful to manage when users are added later, as every other library would have to have the new pattern added.
Write a script adding multiple external libraries for each user that goes just to their specific paths. e.g. alice would have libraries for photos/2025-01-03 Some Event Name/alice, photos/2025-02-14 Some Other Event/alice, and so on. I have ~1,000 of these locations, so I didn't dig further into this but rather kept it as a "only if I have to" solution.
Reorganize my entire photo collection to have a root folder for each user and add them as external libraries by that path. While this would work, I really wanted to try and avoid this as I'm stuck in my ways and fear change it would be a lot of work.
Figure out some way to get an inclusion pattern instead of an exclusion pattern. Some way to say "Only include photos if they're in an **/alice/** path".
After some experimentation, I found a working solution for the last option. For each user I can add photos/ as an external library, and then each user gets an exclusion pattern that is !(**/<username>/**). So alice gets !(**/alice/**) as their exclusion pattern, which excludes everything that isn't in a directory with their name somewhere in the path.
This works perfectly, and is exactly what I was looking for, so I figured it was worth calling out for anyone who may have a similar use case to me.
The Immich documentation says the devs "recommend against advanced usage", which this maybe? counts as. I think one negation at the start should easily translate to Postgres LIKE syntax though, as I'm guessing it just changes to NOT LIKE behind the scenes. In any case, while this works now, it is not officially supported and may break in future, etc.
I also experimented with multiple inclusion patterns, which are possible but have a slightly different syntax (I don't need these for my use case, I was just curious). Let's say I had a new user bobice who needed photos from both alice and bob, the pattern would be !(**/?(alice|bob)/**). This worked in my testing, but is most definitely in the "advanced usage" category, so YMMV.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
tl;dr It's possible to negate exclusion patterns to turn them into an inclusion pattern using
!(<pattern>)
. For example, if I want an external library to only include files if they're inside a directory calledjpegs
somewhere in the filesystem, I can use an exclusion pattern of!(**/jpegs/**)
to exclude everything except those directories. The upshot being only things inside a directory calledjpegs
are put in the library.I didn't see this technique called out anywhere in the docs or in past discussions, and it solved my particular use case, so I wanted to write about it here in case it's useful to other folks in similar positions and saves some searching.
My use case is that my external library folder structure looks like below (only there are multiple users rather than just
alice
andbob
), and I wanted each of these users in Immich to have an external library that has just their photos.I considered a few different approaches,
Add
photos/
as an external library for each user, with exclusion patterns for every other user. So userbob
's external library would have patterns such as**/alice/**
,**/other-user/**
,**/yet-another-user/**
, and so on. This works, but gets painful to manage when users are added later, as every other library would have to have the new pattern added.Write a script adding multiple external libraries for each user that goes just to their specific paths. e.g.
alice
would have libraries forphotos/2025-01-03 Some Event Name/alice
,photos/2025-02-14 Some Other Event/alice
, and so on. I have ~1,000 of these locations, so I didn't dig further into this but rather kept it as a "only if I have to" solution.Reorganize my entire photo collection to have a root folder for each user and add them as external libraries by that path. While this would work, I really wanted to try and avoid this as
I'm stuck in my ways and fear changeit would be a lot of work.Figure out some way to get an inclusion pattern instead of an exclusion pattern. Some way to say "Only include photos if they're in an
**/alice/**
path".After some experimentation, I found a working solution for the last option. For each user I can add
photos/
as an external library, and then each user gets an exclusion pattern that is!(**/<username>/**)
. Soalice
gets!(**/alice/**)
as their exclusion pattern, which excludes everything that isn't in a directory with their name somewhere in the path.This works perfectly, and is exactly what I was looking for, so I figured it was worth calling out for anyone who may have a similar use case to me.
The Immich documentation says the devs "recommend against advanced usage", which this maybe? counts as. I think one negation at the start should easily translate to Postgres
LIKE
syntax though, as I'm guessing it just changes toNOT LIKE
behind the scenes. In any case, while this works now, it is not officially supported and may break in future, etc.I also experimented with multiple inclusion patterns, which are possible but have a slightly different syntax (I don't need these for my use case, I was just curious). Let's say I had a new user
bobice
who needed photos from bothalice
andbob
, the pattern would be!(**/?(alice|bob)/**)
. This worked in my testing, but is most definitely in the "advanced usage" category, so YMMV.Beta Was this translation helpful? Give feedback.
All reactions