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

Simplify and improve time parsing from filename/fullpath #316

Closed erkexzcx closed 1 week ago

erkexzcx commented 1 week ago

This PR does the following:

  1. Simplified and enforced better time parsing from filename and/or fullpath of the file. 1.1 Use only 1 regex instead of 2 1.2 Predict certain numbers instead of their amount. E.g. for year, (19[89]\d|20\d\d) is better than (\d\d\d\d), same for month, day, hour, minute, second... This reduces chance for regex to pick invalid numbers from filename/filepath 1.3 Simplified code
  2. Added few more tests
  3. Slight deduplication for local variable.

All tests pass, also added 2 benchmark functions (they can be removed as per your request).

Please let me know what you think. P.S. The way immich-go parses datetime from filename/path is just awesome :heart:

erkexzcx commented 1 week ago

Related: https://github.com/simulot/immich-go/issues/308

erkexzcx commented 1 week ago

Hope it helps someone to understand how immich-go parses timestamps from filenames and paths: https://github.com/simulot/immich-go/issues/308#issuecomment-2182607356