Skip to content

Commit

Permalink
Merge pull request #291 from damongolding/feature/filter
Browse files Browse the repository at this point in the history
feature/date_filter
  • Loading branch information
damongolding authored Feb 5, 2025
2 parents 4118706 + 323027f commit 529b21e
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 24 deletions.
43 changes: 35 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
- [Albums](#albums)
- [People](#people)
- [Date range](#date-range)
- [Filters](#filters)
- [Image fit](#image-fit)
- [Image effects](#image-effects)
- [Date format](#date-format)
Expand Down Expand Up @@ -249,6 +250,8 @@ services:
KIOSK_PERSON: "PERSON_ID,PERSON_ID,PERSON_ID"
KIOSK_DATE: "DATE_RANGE,DATE_RANGE,DATE_RANGE"
KIOSK_MEMORIES: false
# FILTER
KIOSK_DATE_FILTER: ""
# UI
KIOSK_DISABLE_UI: false
KIOSK_FRAMELESS: false
Expand Down Expand Up @@ -355,6 +358,7 @@ See the file `config.example.yaml` for an example config file
| [person](#people) | KIOSK_PERSON | []string | [] | The ID(s) of a specific person or people you want to display. See [People](#people) for more information. |
| [date](#date-range) | KIOSK_DATE | []string | [] | A date range or ranges in `YYYY-MM-DD_to_YYYY-MM-DD` format. See [Date range](#date-range) for more information. |
| memories | KIOSK_MEMORIES | bool | false | Display memory lane assets. |
| [date_filter](#filters) | KIOSK_DATE_FILTER | string | "" | Filter person and random assets by date. See [date filter](#filters) for more information. |
| disable_ui | KIOSK_DISABLE_UI | bool | false | A shortcut to set show_time, show_date, show_image_time and image_date_format to false. |
| frameless | KIOSK_FRAMELESS | bool | false | Remove borders and rounded corners on images. |
| hide_cursor | KIOSK_HIDE_CURSOR | bool | false | Hide cursor/mouse via CSS. |
Expand Down Expand Up @@ -626,18 +630,19 @@ http://{URL}?person=PERSON_ID&person=PERSON_ID&person=PERSON_ID
### Date range
> [!WARNING]
> I have found an issue in the Immich API which means that the date range is not working as expected.
> It seems API is matching against "createdBefore" and "createdAfter" instead of the EXIF meta data.
> I have raised this with the Immich team and will update this when it is fixed.
> [!TIP]
> You can use `today` as an alias for the current date.
> e.g. `http://{URL}?date=2023-01-01_to_today`
### How multiple date ranges work
When you specify multiple date ranges, Immich Kiosk creates a pool of all the requested date ranges.
For each image refresh, Kiosk randomly selects one date range from this pool and fetches an image within that date range.
### How date ranges work as asset buckets
Date ranges in Immich Kiosk create distinct pools (or "buckets") of assets based on their timestamps.
Unlike filters that modify existing collections, each date range defines its own independent set of assets.
When you specify multiple date ranges, Kiosk maintains separate buckets for each range and randomly selects
one bucket during image refresh to fetch an asset from.
### Allowed formats
- `YYYY-MM-DD_to_YYYY-MM-DD` e.g.2023-01-01_to_2023-02-01
- `last-XX-days` e.g. last-30-days
There are **three** ways you can set date ranges:
Expand All @@ -651,6 +656,7 @@ There are **three** ways you can set date ranges:
date:
- 2023-01-01_to_2023-02-01
- 2024-11-12_to_2023-11-18
- last-30-days
```
2. via ENV in your docker-compose file use a `,` to separate IDs
Expand All @@ -668,6 +674,27 @@ http://{URL}?date=DATE_RANGE&date=DATE_RANGE&date=DATE_RANGE
------
## Filters
> [!NOTE]
> Not all filters work on all asset source/buckets.
Filter allow you to filter asset buckets (people/albums/date ect) by certain criteria.
### Date filter
> [!NOTE]
> `date_filter` only currently applies to person and random assets.
`date_filter` accepts the same values as [date range](#date-range).
examples:
`http://{URL}?person=PERSON_ID&date_filter=2023-01-01_to_2023-02-01` will only show assets of the supplied person between 2023-01-01 and 2023-02-01.
`http://{URL}?date_filter=last-30-days` will only show (random) assets from the last 30 days.
------
## Image fit
This controls how the image will fit on your screen.
Expand Down
3 changes: 3 additions & 0 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ date:

memories: false # show memories

## Filters
# date_filter: last-30-days # only applies to people and random assets

## Experimental
experimental_album_video: false

Expand Down
3 changes: 3 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ type Config struct {
// Memories show memories
Memories bool `json:"memories" mapstructure:"memories" query:"memories" form:"memories" default:"false"`

// DateFilter filter certain asset bucket assets by date
DateFilter string `json:"dateFilter" mapstructure:"date_filter" query:"date_filter" form:"date_filter" default:""`

// ExperimentalAlbumVideo whether to display videos
// Currently limited to albums
ExperimentalAlbumVideo bool `json:"experimentalAlbumVideo" mapstructure:"experimental_album_video" query:"experimental_album_video" form:"experimental_album_video" default:"false"`
Expand Down
39 changes: 24 additions & 15 deletions internal/immich/immich_date.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,9 @@ import (
// Returns an error if no valid images are found after max retries
func (i *ImmichAsset) RandomImageInDateRange(dateRange, requestID, deviceID string, isPrefetch bool) error {

var dateStart time.Time
var dateEnd time.Time
var err error

switch {
case strings.Contains(dateRange, "_to_"):
dateStart, dateEnd, err = processDateRange(dateRange)
if err != nil {
return err
}
case strings.Contains(dateRange, "last_"):
dateStart, dateEnd, err = processLastDays(dateRange)
if err != nil {
return err
}
dateStart, dateEnd, err := determineDateRange(dateRange)
if err != nil {
return err
}

dateStartHuman := dateStart.Format("2006-01-02")
Expand Down Expand Up @@ -156,6 +144,27 @@ func (i *ImmichAsset) RandomImageInDateRange(dateRange, requestID, deviceID stri
return fmt.Errorf("No images found for '%s'. Max retries reached.", dateRange)
}

func determineDateRange(dateRange string) (time.Time, time.Time, error) {
var dateStart time.Time
var dateEnd time.Time
var err error

switch {
case strings.Contains(dateRange, "_to_"):
dateStart, dateEnd, err = processDateRange(dateRange)
if err != nil {
return dateStart, dateEnd, err
}
case strings.Contains(dateRange, "last-"):
dateStart, dateEnd, err = processLastDays(dateRange)
if err != nil {
return dateStart, dateEnd, err
}
}

return dateStart, dateEnd, err
}

// processDateRange parses a date range string in the format "YYYY-MM-DD_to_YYYY-MM-DD"
// and returns the start and end times. The special value "today" can be used for
// either date. If the end date is before the start date, they will be swapped.
Expand Down
11 changes: 11 additions & 0 deletions internal/immich/immich_person.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"net/url"
"path"
"time"

"github.com/charmbracelet/log"
"github.com/damongolding/immich-kiosk/internal/cache"
Expand Down Expand Up @@ -85,6 +86,16 @@ func (i *ImmichAsset) RandomImageOfPerson(personID, requestID, deviceID string,
requestBody.WithArchived = true
}

if requestConfig.DateFilter != "" {
dateStart, dateEnd, err := determineDateRange(requestConfig.DateFilter)
if err != nil {
log.Error("malformed filter", "err", err)
} else {
requestBody.TakenAfter = dateStart.Format(time.RFC3339)
requestBody.TakenBefore = dateEnd.Format(time.RFC3339)
}
}

// convert body to queries so url is unique and can be cached
queries, _ := query.Values(requestBody)

Expand Down
2 changes: 1 addition & 1 deletion taskfile.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: "3"
env:
VERSION: 0.16.0-beta.4
VERSION: 0.16.0-beta.4.1

includes:
frontend:
Expand Down

0 comments on commit 529b21e

Please sign in to comment.