Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Add an option for a filter command #113

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

evancharlton
Copy link

When importing many files (especially from generated backups), there are often files which aren't really worth importing. For example, an old photo library might include many thumbnails, and these low-resolution images don't really belong in my fancy new Immich installation.

This change adds a --filter <cmd> argument to the upload command. This allows the user to pass in a command to be executed (which will be passed the full filename as the first argument). If this command (plus file) returns a non-zero exit code, the file will not be processed by the upload script.

Examples

For the below examples, assume that there exists a script called demo.sh (and is executable) in the current directory.
It would be used like this: upload --filter "./demo.sh".

Exclude thumbnails

#!/usr/bin/env bash
# demo.sh

grep -q -v _thumb <<< "$1"

Exclude low-resolution images

#!/usr/bin/env bash
# demo.sh

W=$(exiftool -ExifImageWidth "$1" | awk -F' : ' '{print $2}')
H=$(exiftool -ExifImageHeight "$1" | awk -F' : ' '{print $2}')

(( $W > 800 )) && (( $H > 800 ))

When importing many files (especially from generated backups), there are
often files which aren't really worth importing. For example, an old
photo library might include many thumbnails, and these low-resolution
images don't really belong in my fancy new Immich installation.

This change adds a `--filter <cmd>` argument to the `upload` command.
This allows the user to pass in a command to be executed (which will be
passed the full filename as the first argument). If this command (plus
file) returns a non-zero exit code, the file will not be processed by
the upload script.

 ## Examples

For the below examples, assume that there exists a script called
`demo.sh` (and is executable) in the current directory.

 ### Exclude thumbnails

```sh
 #!/usr/bin/env bash

grep -q -v _thumb <<< "$1"
```

 ### Exclude low-resolution images

```sh
 #!/usr/bin/env bash

W=$(exiftool -ExifImageWidth "$1" | awk -F' : ' '{print $2}')
H=$(exiftool -ExifImageHeight "$1" | awk -F' : ' '{print $2}')

(( $W > 800 )) && (( $H > 800 ))
```
@evancharlton
Copy link
Author

evancharlton commented Sep 2, 2023

This has a similar objective to #91, but offers more flexibility in terms of allowing the script to do anything -- including file introspection.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant