Is it possible to automatically update YAML frontmatter by moving it to a specific folder?

Things I have tried

I have not tried much because I don’t know if its possible.

What I’m trying to do

I’m modifying my media database. For movies I have folders for various services; Netflix, Prime, Disney etc. I was hoping that by including a "Service: " line in the YAML, that it would auto populate the name of said Service based on the folder it was moved to.
ie: moving a movie to the Netflix folder would result in “Service: Netflix” in the YAML front matter. This way when I compile a dataview query I can see what service the movie/series is on.
Any help appreciated.
Thanks

1 Like

I suggest you use the Templater-plugin. It will not only give you access to the whole metadata of the file but also allow file manipulation. Just create a one-liner template (see below) and move it to your templates folder. Once you’ve done this you can insert the template at the proper location in your YAML frontmatter (note, that you have to manually place the cursor to the correct position).

<%tp.file.folder()%>
or
Service: <%tp.file.folder()%>


Depending of your workflow, you may find it helpful to use a template that both, moves the file and inserts the folder-name based on a user-promt. (In the below code change “BasePath/” and “Netflix” according to your setup!)

<%await tp.file.move("BasePath/"+ await tp.system.prompt("Enter Service (must be identical to folder name)", "Netflix", false)+"/"+tp.file.title)%><%await tp.file.folder()%>


Tipps:

  • In case you run into errors, have a look in the Console (Ctr/Cmd+Shift+I)
  • You may achieve similar workflow with the “QuickAdd Plugin” as well.
1 Like

since u mention dataview and folder, perhaps your issue can be resolve with dataview query – it can filter results based on folder. you can use FROM (or even WHERE clause if u feel like it). sth like this.

TABLE movie-name AS Movie
FROM "Services/Netflix"
1 Like

Great suggestions, both!
@lab Yes I use Templater a lot so created a Service Template which is handy. Right now. I’m using the Media DB plugin to fetch tv/movie data. That goes to the Media DB folder. Within it are sub-folders I created with each of the services.
I then amend the YAML with the Template above and it works great. I will investigate Metaedit because I would love this line to auto-update when I move a Media DB file into any of the folders.
@efemkay thats also a good solution. But I have a dataview query which searches all of the services collectively and sorts by rating. So, when I see something good I also want to know which service its on. See image below as ref.

Good to have this process now somewhat automated!
Thanks folks!

2 Likes

Actually, after reading the suggestion from @efemkay, as well as your reply, I think you should really go for adapting your dataview queries. Like so:

TABLE movie-name AS Movie, file.folder AS Service, ...
FROM <ParentFolder>
SORT <rating>

Note, that you are not restricted to field-names to build up your dataview-table. So, as in templater, you can simply access file.folder/path/name etc. in dataview, too.

Haven’t tested the code, but it should work, I think. Good luck!

1 Like

Of course! What an elegant and simple solution!
I was not thinking of folder paths in dataview queries, focusing instead on YAML etc.
Still learning. That covers everything automatically!
I will amend my queries this weekend!
Thanks again for this solution @lab and to @efemkay for prompt.
:slight_smile:

2 Likes

I’ve been wondering about how to do this too. Thank you for sharing!

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.