Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Render hierarchical tags (e.g. "Parent|Child") as nested albums #275

Open
seanakabry opened this issue Dec 18, 2021 · 6 comments
Labels
enhancement New feature or functionality

Comments

@seanakabry
Copy link

Could the functionality of the %keywords option for the --albums-from flag be expanded to handle nested IPTC keywords?

The section on keywords in the relevant IPTC specification doesn't say anything about hierarchies, but Adobe Bridge's default delimiter is a pipe, which is also recognised by LIghtroom Classic.

If an image were assigned the keywords tag|subtag and tag|subtag|subsubtag, it would appear in the albums /tag/subtag and /tag/subtag/subsubtag, but not /tag.


In the meantime, can this behaviour be achieved using a custom mapping function (--albums-from "file://...)?

I got as far as this function, which is supposed to recognise keywords containing one pipe: (apologies for my ignorance of JS)

const eventRegex = /(.+)\|(.+)/
const tags = new Array();
module.exports = file => {
  file.meta.keywords.forEach(function(tag) {
    const match = eventRegex.exec(tag)
    if (match) {
      const parent = match[1]
      const child = match[2]
      tags.push([`Tags/${parent}/${child}`])
    } else {
      tags.push([`Tags/${tag}`])
    }
  })
  return tags
}

but the gallery will not compile:

Unexpected error The "path" argument must be of type string. Received an instance of Array

If the array tags is returned as a comma-delimited string, the gallery compiles, but the albums are recursively nested like so:

Tags/ParentA/ChildA/Tags/ParentB/ChildB

Thank you for the excellent software.

@seanakabry seanakabry added the enhancement New feature or functionality label Dec 18, 2021
@rprieto
Copy link
Member

rprieto commented Dec 18, 2021

Hi, I like this idea very much. Thanks for raising it.
Would it make sense to also recognise keyword1/keyword2 as a hierarchy (slash in addition to pipe)?
Edit: it's undocumented, but I realise now it might already behave like this

I'll try to troubleshoot your custom mapper, and as a second steps see if we can support this by default in %keywords.
Stay tuned!

@seanakabry
Copy link
Author

Thank you, Romain. I just switched to using / as a delimiter, and confirm that this feature is already implemented as you suggest. (So please feel free to ignore the mapper.)

Perhaps the option to use other delimiters would be a welcome nicety (for users with extensive, already-tagged collections), but I don't think Thumbsup is wrong to prefer the forward slash as the default; it certainly seems most intuitive to me.

Adobe Bridge defaults to | but lets users choose from /, \, and :. Lightroom Classic is probably not a relevant consideration after all, because it doesn't preserve keyword hierarchies on export (just exports them flat).

@rprieto
Copy link
Member

rprieto commented Jan 29, 2022

Hi, sorry for the delay. Do you think it's reasonable if:

  • you could pass additional delimiters via a flag like --album-path-delimiters
  • thumbsup simply does a string replace of these characters to a /

The awkward edge case is if you have a slash in your tags,e.g. Holidays|Japan/Australia 2021.

I'm guessing it should keep Japan/Australia 2021 as a single album.

@seanakabry
Copy link
Author

Please don't apologise!

I think the new flag would be best, with / as the default. Though | and \ are rare, it's not hard to imagine problematic edge cases with a string replacement of :, such as 2022/Conference Title: Conference Subtitle.

If Thumbsup interprets --album-path-delimiters | to mean that only pipes are delimiters (not the default plus pipes), the flag also side-steps the edge case you gave (which I think is what you were saying). This seems more elegant than introducing an escape character.

In any case, I think the lowest hanging fruit is probably to mention in the documentation that Thumbsup is already capable of interpreting hierarchical tags.

@rprieto
Copy link
Member

rprieto commented Jan 29, 2022

In fact it's trickier than planned. Initially I thought we could change the whole hierarchy system to understand a different character.

However, the code is based on file system helpers and specifically expects /. Moreover, if we changed it, the very basic use case of creating albums per file path wouldn't work anymore.

So I think the logic will have to be specific to IPTC keywords:

if --keyword-path-separator is specified:
  remove all / characters from keywords
  replace the specified character with /

So a file with the keyword Holidays|Japan/Australia 2021 would end up in the album Holidays > Japan Australia 2021.

That would be easy to implement and test, and have minimal side effects!

@rprieto
Copy link
Member

rprieto commented Jan 29, 2022

And agreed on the low hanging fruit! I'll update the documentation later, unless you want to submit a pull request to https://github.com/thumbsup/docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or functionality
Projects
None yet
Development

No branches or pull requests

2 participants