Yes, this may not be the best solution, and believe me I do weigh your objections to my strategies. But after consideration, I still think this best suits my purposes. It is nice to have individual fields one can change without having to edit a field with a lot of values, plus I can repurpose some tags to other fields if they are discrete. For example, I used to include a country code, language and mood in my genres (I know you probably object to this as well) and now I have moved them to dedicated fields and then write them in shorthand to the comments field to aid in smart playlist creation.
Unfortunately, your script still produces a leading Forward Slash if genre1 and genre2 were not present. I need to only put the forward slash if ANY of the previous genres were present. So in a 3 genre example, genre3 will only produce a " / " preceding it IF a genre3 exists AND either genre1 OR genre2 is present. (Capitalizing what I assume would be functions).
Really there should not be any instance that genre1 should not be populated, but since I just created it, as I was using genre as genre1 (see script in 1st post), it brought about this problem that I had not considered (because genre was always populated).
I did populate all genre1s after I noticed this but I thought I would fool-proof the script in case, for some reason genre1 was no populated for whatever reason.
Are you sure that you used the square brackets?
a leading slash will only appear if GENRE is not filled but %genre1% (or any of the subsequent ones) is filled.
You can try that in Converter>Tag-Tag.
The reason why I am a little reluctant about the user-defined fields with an index in the name is that you have to hard-code the names into all the actions that rely on these fields.
If you use a multi-value-field then you can merge the data of several fields into one and treat them in one go - and split them afterwards again. But, of course, you are .free to do what you want.
In this case it looks like the current approach produces a number of problems that need the help of the forum.
Unfortunately I really am not versed enough to understand why hard coding the names into the actions can cause problems, nor do I expect you to explain why. It will probably go over my head anyway. I will say that if I tried to use one field, I would probably have just as many questions of how to split and reassign, as this very thread proves! But you may be right, what do I know?
I did as you suggested and tried Tag-Tag and with nothing in genre1 & genre2 and "Space Rock" in %genre3% the result is "/Space Rock"
I think its because in your script you instruct MP3Tag to add the " / " if there is a Genre3, but you do not, AFAIS, place a condition that either genre1 or genre2 must exist to add the preceding " / ". IF only Genre3 exists, it should be inserted without the forward slash preceding it.
Like I said, there should be no reason why genre1 would not be populated, so this probably will never be a problem, as the script as it stands can handle any other genre field after genre1 being blank, but I am doing this more to try to learn how to do this with Reg Ex as an exercise as well as to foolproof the script. I can survive without solving this, but since I am trying to grasp Reg Ex, I thought I would see it through. Unfortunately I cannot solve it so I came here but I don't want to impose if it is too much trouble.
In the example that you show, you have an initial field GENRE
If that is missing, then, as you have observed, the first string that you insert into GENRE is one from the user-defined fields. If it is there, then the slash will only appear if a field within the square brackets exists.
The only thing that the square brackets make easier is to avoid the lengthy $IF() statements.
Apparently, I don't understand what you intend to do and also I did not suspect that you did not fill the standard field GENRE at all but carried around all those user-defined ones.
I am not using the original script. I am trying to create a better one.
This worked if there were only 2 genres:
If there both genre 1 & genre2 existed, then " / " would be inserted prior to genre2, but if not genre2 would appear with not preceding " / ". The problem is when there is more than 2 genres.
I am trying to write a script that will not put in a forward slash in front of genre3 unless genre3 exists AND either genre1 OR genre2 exists.
I tired $if($and(%genre3%,(%genre2%|%genre1)), / ,) which I thought meant if genre3 exists and either genre2 or genre1 exist, insert the " / ," but obviously I am wrong, as it is not working.
I am consolidating all the individual fields into the main genre field separating the with a " / " so I can access it in iTunes but I am keeping the individual fields as well. I initially erased everything in the indexed genre fields after consolidating them, but thought it was better to also keep them in the individual fields. That was the original intent of this thread.
I don't know what you are doing.
I just tried the following for GENRE
Format string: %genre%[ / %genre1%][ / %bpm%][ / %genre3%][ / %language%]
and, naturally, none of the %genreX% fields exist. which would be like
The result is: Downtempo / 95 / eng
no leading slash, even though there are 5 addressed fields, only 3 pieces of information are displayed as all the non-existing ones are left out.
Your $if() $and() and $or() may work in the end but will be extremely complicatedto maintain in comparison to the simple string that I used here.
I am not defining the genre field with %genre% as that would just append more and more values to genre. I am defining genre with genre 1-10.
The script should not start with %genre%
In your example, I assume your %genre% exists, correct? What if it did not? How would you be able to omit the " / " if it did not? You would need to tell MP3 that if genre did not exist, to not include the " / ". I have solved that with:
$if($and(%genre1%,%bpm%), / ,)$if(%bpm%,bpm)
However, this become more difficult when you have more than 2 terms. The question is how would you instruct MP3Tag to only put the " / " in front of language if language existed AND neither genre1, bpm, or genre 3 existed, and if not to just list %language% if %language% existed and none of the other fields had values?
That is what I was trying to do with $if($and(%genre3%,(%genre2%|%genre1)), / ,)
It looks like I am using more and more the context - you said
and then you start with
In which field does this string appear? Not in GENRE?
I think that the easiest approach would be to create an action of the type "replace with regular expression" for whatever field may contain that list of genre terms:
Seach string: `^/\s*
This should remove a leading slash.
I tried your script with and without the initial back tick (I think you forgot to put in another back tick at the end) and the forward slash in " / Space Rock" was not removed. I then realized there was a space in front of the slash because the genre script adds " / " so I modified it to ^ /\s* and that worked! I can add it to the end of the action to clean up any leading forward slashes that may occur.
I also see I was not being very clear. Sorry. I thought I had posted it, but I see I did not.
I changed the script to: $if(%genre1%,%genre1%,)$if(%genre2%, / %genre2%,)$if(%genre3%, / %genre3%,)$if(%genre4%, / %genre4%,)$if(%genre5%, / %genre5%,)$if(%genre6%, / %genre6%,)$if(%genre7%, / %genre7%,)$if(%genre8%, / %genre8%,)$if(%genre9%, / %genre9%,)$if(%genre10%, / %genre10%,)
I used it with a Format Value with the field being %genre%
However, your solution should work, so the only reason to work on this any further is to learn how to write a script that creates and AND/OR function (if genre3 AND (genre2 OR genre1) exist, then insert " / "
It may come in handy and I would like to put it in my notes but again, I do not want to impose and it may not be worth your effort. I will try to figure this out! Thanks again for your help.
Unless you really want to meet that intellectual challenge, I suggest the following:
Create an action of the type "format value" for GENRE
Format string: [\\%genre1%][\\%genre2%][\\%genre3%][\\%genre4%][\\%genre5%]
(as many as you need for the maximum number)
This creates n fields of the type genre - but only as many as really exist.
Then use an action of the type "Merge duplicate fields"
with " / " (without the inverted commas) as separator.
And you will get the list of genres with blank slash blank without leading slashes or trailing ones in the field GENRE.
I was just trying to figure out what it would do before I tried it. I am really trying to grasp Reg Ex. I got some traction using iMatch, but it seems that I must use Reg Ex a least once a week to remember it. Everything I learn seems to pour out of my brain as soon as it can.
anyhow, the reason I asked was because looking at the action I did not think it would work, and I think I am right.
I wrote the action and you are right, I do not get a leading forward slash, but now very genre is listed in GENRE but with two backward slashes, where I want " / " as the separator.
I think I will just ensure that Genre1 is populated and I can use the modified script: $if(%genre1%,%genre1%,)$if(%genre2%, / %genre2%,)$if(%genre3%, / %genre3%,)$if(%genre4%, / %genre4%,)$if(%genre5%, / %genre5%,)$if(%genre6%, / %genre6%,)$if(%genre7%, / %genre7%,)$if(%genre8%, / %genre8%,)$if(%genre9%, / %genre9%,)$if(%genre10%, / %genre10%,)
or just add the action ^/\s* to the action to remove any forward slash that may occur if genre1 is not populated. I am also adding a step to remove any duplicate genre.
Damn, I cannot figure out what I am doing wrong. I and get step one to work but step 2, The split fields is not, for whatever reason. I tired to write it from scratch several times and I get the same result with not fields split. Everything else is as you said, including the extended tag. I am at a loss, frustratingly so!
I would have believed you if you said it worked, no need to go through all that effort, though it is nice to see. I am going to attach my action in case you want to check it out and see why it is not working. genre fields ohrenkino.mta (200 Bytes)
P.S. Thanks for the tip on making things shorter. I think I just the if function because it is easier for me to understand what I am doing, but I will write it in my notes and try to use that format from now on.
I was talking about the post where you instructed and linked Split Fields by Separator. I wanted to wait until you changed it to mark it as the solution for others in the future, but you are correct, I missed where you stated that you merged the fields in the following post. Sorry.