simulot / immich-go

An alternative to the immich-CLI command that doesn't depend on nodejs installation. It tries its best for importing google photos takeout archives.
GNU Affero General Public License v3.0
1.18k stars 35 forks source link

Help me understand how immich-go parses date from filename #308

Closed erkexzcx closed 1 week ago

erkexzcx commented 2 weeks ago

Here is the picture: image

As you can see, it doesn't detect date correctly. That is fine, but my question is - how can I help immich-go to understand this? Maybe rename folder to specific date format? Rename each file to specific date format? Any suggestions?

EDIT: Oooops, this is actually a log timestamp and not picture/video timestamp seen by Immich. Anyway, how do I help immich-go to understand date when it's not provided in the filename or in the file itself?

simulot commented 2 weeks ago

EDIT: Oooops, this is actually a log timestamp and not picture/video timestamp seen by Immich. Anyway, how do I help immich-go to understand date when it's not provided in the filename or in the file itself?

Correct, that's the timestamp of the action. I should log the date of capture found by immich-go as well.

Immich server takes exif data. If it doesn't find it, it use the date provided by immich-go.

immich-go provides the date of capture comes from the linked JSON file of google photos takeout. Then it tries to guess the date from the file name, not it's full path. Then it read the exif data

erkexzcx commented 2 weeks ago

Is there a way to capture date from a folder of where image/video is stored?

simulot commented 2 weeks ago

I can implement this.
Hopefully you have formatted the date like YYYYMMDD...

I have seen some creative folder schemas:

With slashes or dashes or dots as separator And date format is a rabbit hole!

erkexzcx commented 2 weeks ago

I am kind of thinking - would it be possible to write a script that would take full path of each image/video, use AI (e.g. OpenAI via API) to extract any possible year/month/day/hour/minute/second timestamp and write it to a filename.

E.g. this:

/volume1/media/IPAD_20171013_video_nuotraukos/IMG_1552.JPG

would be come this:

/volume1/media/IPAD_20171013_video_nuotraukos/2017-10-13_IMG_1552.JPG

or something like that...

Considering this scenario, would it be possible to parse such timestamps from filename using immich-go? If so, what format is accepted? :)

simulot commented 2 weeks ago

Let's keep it simple...

Split the full path on "/":

Parts are checked from the file name up to the root. When a valid date if found for that part, take it. If no date found, check the full path

Ex: /volume1/media/IPAD_20171013_video_nuotraukos/IMG_1552.JPG

Ex: /volume1/media/IPAD_20171013_video_nuotraukos/2017-10-13_IMG_1552.JPG

Ex: /volume1/media/2017/10/13/IMG_1552.JPG

erkexzcx commented 1 week ago

Here are example folders that I have:

..._2018-06-08
... 2009.03.11 ... - ...
2012-12-21
... 2006
... 2007_06_20
... 2009 10 04-11
<something> 480
<something> 600
... 2005-07

I highly suggest to remove it as it is manually edited folder name with manually added date: https://github.com/simulot/immich-go/commit/6ca66d6b3f1c3a82b7297202e7854eb1e00ef3f5#diff-f2724c0d4209d12f67a9cff2d7a333f7768d5ac88894f180d7aeb77790fc3133R120-R123

First of all - these are not automatically created names and dates. These are handwritten folder names. I assume you misunderstood this github issue - my goal was to ask of how would I manually sort these folders, so immich-go can understand them?

So the main question - what is the date (datetime) format understandable by immich-go? Can I give the following folder names and it will be understood?

Crete 2022-01-23
Something else 2000-05-25

Bonus: is it possible to update dates in already existing immich library that I've created using immich-go? Or regular simple upload action would fix the dates automatically if folders are properly updated out by hand?

erkexzcx commented 1 week ago

Also regarding this: https://github.com/simulot/immich-go/commit/6ca66d6b3f1c3a82b7297202e7854eb1e00ef3f5#diff-f2724c0d4209d12f67a9cff2d7a333f7768d5ac88894f180d7aeb77790fc3133R88-R123

I would suggest clearing this out and leave only the following cases:

  1. When it is 100% confirmed that such path/name is generated by a camera/system/immich. If not - not worth implementing it.
  2. Some custom and "true" format, written by human, that is parseable by immich-go. For example: yyyy-mm-dd for date. Time shouldn't be parsed from paths/names, unless it's put automatically by a camera.

Having this strict format, it would become much clearer on how to deal with it, so I can modify existing folders accordingly, put a valid date format and it would work fine. :)

@simulot tagging, because this issue is closed. I would suggest re-opening it for now, so we can brainstorm. :pray:

erkexzcx commented 1 week ago

So I've created a PR, but basically the way immich-go parses timestamp is like this:

  1. It first tries to parse timestamp from file name.
  2. If not found, then parses each directory name going up until root directory is reached.
  3. If still not found, then it uses whole path to extract filename.

For parsing, it uses this regex: (\d{4})\D?(\d\d)\D?(\d\d)\D?(\d\d)?\D?(\d\d)?\D?(\d\d)?

This regex basically means that:

All of these would be parsed correctly.

Also, as mentioned before, first it tries file name, then each directory going up, then lastly against whole path. For example, below would work too!

/path/to/2023/01/25/pic1.png

Here are some invalid formats that wouldn't be parsed:

/path/to/2023/pic1.png (missing month and day)
/path/to/2023-03/pic1.png (missing day)
/path/to/2023/Crete/May/pic1.png (not matching regex at all)
/path/to/2023/Crete/pic1.png (it's just a year, no month and day)
/path/to/Crete 2023-05/pic1.png (missing day)