Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Title formatting head scratcher - what am I doing wrong? (Read 675 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Title formatting head scratcher - what am I doing wrong?

Over the years I've changes the way certain title are formatted and have for the most part written scripts to go from the old format to the new format.  I'm working on changing titles like 'Clarinet Quintet In A, K. 581 - I. Allegro' to 'Clarinet Quintet, K. 581 In A - I. Allegro'.  The thought is that there may be several pieces in A minor but only one K. 581, so I want to sort on that.  The first part of the script works fine, it is:

$substr(%title%,1,$sub($strchr(%title%,'I'),2))$substr(%title%,$strchr(%title%,','),$sub($strchr(%title%,'-'),1))$substr(%title%,$strchr(%title%,'I'),$sub($strchr(%title%,','),1))$substr(%title%,$strstr(' - '),$sub($substr(%title%,$strstr(' - '),$len(%title%)))

Here's the result:


This isolates everything starting with ' - '
 $substr(%title%,$strstr(%title%,' - '),$len(%title%))

Here's the result:


The problem is when I use them together it doesn't work.  Here's the script:
$substr(%title%,1,$sub($strchr(%title%,'I'),2))$substr(%title%,$strchr(%title%,','),$sub($strchr(%title%,'-'),1))$substr(%title%,$strchr(%title%,'I'),$sub($strchr(%title%,','),1))$substr(%title%,$strstr(' - '),$sub($substr(%title%,$strstr(' - '),$len(%title%))) $substr(%title%,$strstr(%title%,' - '),$len(%title%))

Here's the result:


I'm clearly missing something.  Any suggestions?


Re: Title formatting head scratcher - what am I doing wrong?

Reply #1
Your first string is missing a closing parenthesis ')' so appending extra string to it gets treated as garbage at the end of length parameter.
Your first string looks scary, are you certain it's a good idea to cut things simply at single character 'I'? Wouldn't it make more sense to for example look for string 'In '?

Re: Title formatting head scratcher - what am I doing wrong?

Reply #2
That's it, thanks!  I checked parenthesis but clearly missed that issue.  I agree, it would be better to look for 'In ' instead of 'I' and I'll make that change.   However, I'm pretty good about consistent formatting of tags and I scan the results before I hit Apply so I would not expect it to be an issue.  That said, I've been bitten in my rear end before...

Re: Title formatting head scratcher - what am I doing wrong?

Reply #3
A safer way is to populate temporary fields. File properties -> right-click for Automatically fill values and then with target
%titlefirstpart% In %titlekey%, %titlekv% - %titlepart%

Then do sanity checks by searching, making sure %titlekey% doesn't look weird and that the Köchel numbers start with "K. " etc., and then you can populate back. Less elegant, but less butt bitten.

Re: Title formatting head scratcher - what am I doing wrong?

Reply #4
I've never used Automatically fill values before, I'll take a look.  Thanks.

Re: Title formatting head scratcher - what am I doing wrong?

Reply #5
Search first for, say,
%title% IS * In *, K.* - *
to make sure that you select only items which has the information in the appropriate order in %title%. (Yes wildcard asterisks and question marks do work, I don't think that is well documented.)

Re: Title formatting head scratcher - what am I doing wrong?

Reply #6
Search first for, say,
%title% IS * In *, K.* - *
to make sure that you select only items which has the information in the appropriate order in %title%. (Yes wildcard asterisks and question marks do work, I don't think that is well documented.)
I've been doing title formatting in search for over 15 years now and this is the first I'm hearing about it :D