Welcome Guest

Pages: 1 2
Creating an action to tag files based on folders they are in...
CosmasPostMay 22, 2024, 17:06
Newbie
Posts: 10
Registered:
May 20, 2024, 23:02
Hot topicCreating an action to tag files based on folders they are in...

I suspect this is easily doable since Yate seems to be capable of everything know to humanity (which I'm amazed by!), but I'm still not quite up to speed yet on my scripting.

I have a very large set of folders with a name configuration of: '__NewMusic_240315' with the 'XXXX15' portion changing each year and month. (The day '15' portion is always the same)
Inside these folder sets I have folders called called things like '03_OK' and '05_No' which I'd like to give different tags to the music files within (the actual music files are usually within an album folder a level below the '__NewMusic_240315/03_OK or /05_NO' folder.

So, for example, I'd love to make an action whereby I take all the music files inside '__NewMusic_??????/03_OK/' and give them a ROONALBUMTAG of 'OK'
and '__NewMusic_??????/05_NO/' givning them a ROONALBUMTAG of 'NO'
That way I can easily filter them out of searches on my collection in Roon.
Actual path of the music files is likely as such: '__NewMusic_240315/03_OK/(album folder here)/(songs here)'

I feel like Yate probably has the ability to query folders and such, right?

...and don't worry I'll try to figure out a more unique tag than just 'NO' or 'OK' in my actual case as I can already see that could be problematic.

Thanks!

2MR2PostMay 22, 2024, 22:49
Avatar photo
Administrator
Posts: 2156
Registered:
August 23, 2012, 19:27
Hot topicCreating an action to tag files based on folders they are in...

Sure it can be done :). Yate can read folder contents and it can dynamically load audio files. It can't however handle recursion when calling actions. Luckily recursion can be emulated by using lists ... at which Yate is really good.

Download:

https://2manyrobots.com/actions/Cosmas--Walk-Folders.zip

The action is named Cosmas: Walk Folders

I've assumed that the __NewFolder_###### name can optionally have leading text. I've also made no assumptions on where these files live in the hierarchy under the supplied root folder. I assumed that the _NO and _OK folders are immediately under a __NewFolder_######. I've also assumed that the tracks are in a subfolder immediately under a _NO or _OK folder.

The action prompts for a folder. This can be a single __NewFolder_###### if you wish or any other folder with one or more __NewFolder_###### folders under it somewhere in the hierarchy.

The action then issues two prompts. One for OK data and one for NO data. You must specify at least one or both.

The action will work fine if ROONABUMTAG is mapped to a custom field but it is not necessary.

I've done some testing by mocking up a few folders. It's entirely possible I've missed something. I tested by selecting 'test' in the attached screenshot. Note that file 3, file 4 and file8 ar never modified due to my assumptions.

Please test.
Image

CosmasPostMay 23, 2024, 09:59
Newbie
Posts: 10
Registered:
May 20, 2024, 23:02
Hot topicCreating an action to tag files based on folders they are in...

Wow, what an amazing script. I don't think I would have had a chance of figured that one out!
I just gave it a whirl and it worked perfectly for the OK folders but not the NO folders, so I'll take another look to see if I can figure out what might need to be added.

One other question I just realized would be prudent to ask. If there is already something in the ROONALBUMTAG, would it add to it or replace it? I suppose it would be good if we made sure to only add to the tag rather than replacing it.

Looking forward to diving into this more as I get time today. This action is going to be super helpful for me, thanks again!

2MR2PostMay 23, 2024, 11:20
Avatar photo
Administrator
Posts: 2156
Registered:
August 23, 2012, 19:27
Hot topicCreating an action to tag files based on folders they are in...

Hmmm .... do the NO folders look something like what I have in my example? NO is being set with my test data.

As for appending ... line 89 sets the Tag. Change the data to be whatever you like. Here's an example:

Set User Defined Text Item 'ROONALBUMTAG' to "\^ROONALBUMTAG^ - \<data>"

As you can't append to a UDTI, I've included the previous value via an escape sequence. If you keep a unique delimiter you can even remove the old appended data before adding new. eg.

Set Variable 0 to "\^ROONALBUMTAG^"
Find "·-·" in Variable 0, remove it and everything after then trim whitespace characters
Set User Defined Text Item 'ROONALBUMTAG' to "\v0 - \<data>"

CosmasPostMay 23, 2024, 12:55
Newbie
Posts: 10
Registered:
May 20, 2024, 23:02
Hot topicCreating an action to tag files based on folders they are in...

Thanks for getting back to me. I'll try to experiment with what might be different about the OK portions and the NO portions that you made. Wonder if it can't handle both in one action? Anyway, we can both look into it.

The 'no' folders are all named exactly as such: "05_No" if that's any help.

2MR2PostMay 23, 2024, 13:15
Avatar photo
Administrator
Posts: 2156
Registered:
August 23, 2012, 19:27
Hot topicCreating an action to tag files based on folders they are in...

That's it. I'm looking for _NO, not _No. I've changed it to be case insensitive ... for NO and OK. I've also changed the action such that it appends to an existing value (delimited by a space). I've you want to change how the UDTI is set, it's all done in the incline action named Set the new data on line 88. The action can be downloaded at:

https://2manyrobots.com/actions/Cosmas--Walk-Folders-2.zip

The action will have the same name but will be v1.1 (Check it in the Action Manager).

CosmasPostMay 23, 2024, 16:34
Newbie
Posts: 10
Registered:
May 20, 2024, 23:02
Hot topicCreating an action to tag files based on folders they are in...

Eureka! It works. Wonderful. And I figured out how to do it so if I want to append multiple roontags, I can do tag;tag2;tag3, etc.
...though I've just discovered that sometimes I have examples with music files futher down, such as 04_OK/Album/CD1/music_files, so maybe I'll look closer about how to make it look further levels down.

Thanks again, you've been so much help. this is going to save massive amounts of time for dealing with the past 16 years of music folders I have!

2MR2PostMay 23, 2024, 20:41
Avatar photo
Administrator
Posts: 2156
Registered:
August 23, 2012, 19:27
Hot topicCreating an action to tag files based on folders they are in...

Ok I took one more pass to put this one to bed.

Download:

https://2manyrobots.com/actions/Cosmas--Walk-Folders-3.zip

The action is now v1.2.

I now find all audio files under a _NO or _OK folder .. at any depth.

I've also changed the setting of the tag to use ; as a delimiter and it will no longer append duplicate items. Inline action Set the new data on line 93

CosmasPostMay 24, 2024, 09:02
Newbie
Posts: 10
Registered:
May 20, 2024, 23:02
Hot topicCreating an action to tag files based on folders they are in...

I'm so sorry to report, but for some reason I think something broke in that 1.2 version. It now just hangs while it looks for files 🙁
I had to force quit to stop it.
I tried the v1.1 version and that still runs, so I guess something in this most recent version caused an endless loop or something.
Sorry this has turned out to be more arduous than I thought.

2MR2PostMay 24, 2024, 09:15
Avatar photo
Administrator
Posts: 2156
Registered:
August 23, 2012, 19:27
Hot topicCreating an action to tag files based on folders they are in...

Oops. I'll have a look at it. I'm flying today so it may be a day or two.

You don't have to force quit. Do a Yate>Cancel and it will stop in a few seconds. I recommend putting a Cancel button on the toolbar.

Pages: 1 2
Mingle Forum by Cartpauj | Version: 1.1.0beta | Page loaded in: 0.036 seconds.