Apostrophe's in Action Items

In action groups the apostrophe behavior is not as expected.

Logically $if(%composer%,%composer%,'') should keep composer if it exists and leave it blank if it does not exist (I know, dumb example, but it's simple). Instead if the target is blank I end up with a single apostrophe (') as the result of this statement.

Yes I know I can do $if(%composer%,%composer%,) but that's not the point.

I generate my action groups programmatically and having this result for apostrophe's makes life difficult.

So it looks like a bug to me.

k

more info, in case there's a work-around.

During tag cleanup I replace composer with an album-level composer where some albums have apostrophe's in their names (e.g., UCL - London's Global University) and others are blank. So I need a regex that can simultaneously handle both situations.
Simply adding more apostrophes to the target of the example regex did not work.

Please see these threads on the need to escape the apostrophe and ways to do it:
/t/15384/1
and a thread that you created yourself:
/t/16547/1

You may nest functions, e.g. $regexp($replace(...),...)

This gives an unwanted result: $if(%composer%,%composer%,'')
... because it creates one single apostrophe in case of the tagfield COMPOSER does not exist.

This is correct: $if(%composer%,%composer%,)

Note: The Mp3tag Scripting Language has no symbol for an empty string.
You know it already ...

You may apply the function call ... $char(0) ... to visualize an empty string within Mp3tag Scripting Language.

DD.20160620.1000.CEST

yes i was aware of my earlier posts ... hence the comment that adding additional apostrophe's doesn't help. i still think it's a bug that the mp3 scripting language doesn't have a symbol for an empty string ... but that being said do you have any ideas for a single regex that can handle the two cases I posed?

  1. composer is blank OR
  2. composer has a single apostrophe as integral to its name

I've tried many different combinations and permutations and haven't hit upon a solution.

K

If this or that, ... what follows then ?

DD.20160621.0947.CEST

Sorry for the ambiguity. Here are two sample FORMAT statements from the ACTION GROUP. These FORMAT statements are generated using an Export Config which grabs the default composer from tiny mp3's I maintain for each album (album-level tags). This is the regex that gives me the extra single apostrophe when the default COMPOSER is blank:

REM Format Value: COMPOSER
REM Album has default composer UCL - London's Global University

$if($eql($regexp(%album%,'',),'Lunch Hour Lectures'),
$if($and(%composer%,$neql(%composer%,podcast),$neql(%composer%,iTunes U))
,%composer%, 'UCL - London''''s Global University'), %composer%)

REM Format Value: COMPOSER
REM Album has blank composer

$if($eql($regexp(%album%,'',),'Unbelievable┬┐'),
$if($and(%composer%,$neql(%composer%,podcast),$neql(%composer%,iTunes U))
,%composer%,
''),
%composer%)

Verbal explanation: for each album, if the composer exists and it's not 'podcast' or 'itunes u' then keep it, otherwise replace it with the album-level default composer

Sometimes just writing about an issue helps. I have solved the problem.
Below is the Export Config that handles the situation:

$filename('C:\Documents and Settings\IDES\Application Data\Mp3tag\data\actions\Composer Fill.mta',UTF-8)'[#0]'$loop(%album%)
'T=5'
'F=COMPOSER'
'1=$if($eql($regexp(%album%,'''''',),'''$regexp(%album%,'',)'''),$if($and(%composer%,$neql(%composer%,podcast),$neql(%composer%,iTunes U)),%composer%,'$replace(%composer%,'','''')'),%composer%)'$puts(counter,$add(1,$get(counter)))

'[#'$get(counter)']'$loopend()

$puts(REM,'if composer is empty or eql -podcast- or -itunesu- fill it with the albumtags default value')

Thanks for helping me work my way through this.
K

Well, I have to say, I do not understand why and what you are doing there, ...
but it is somewhat remarkable, please explain, why do you do this?
Why don't you walk the direct way and apply all the rules within one standard action group?

Does this help to understand how to remove an apostrophe character?
From: COMPOSER <== UCL - London's Global University

Action Format value
Field: COMPOSER
Formatstring: $replace(%COMPOSER%,$char(39),$char(0))

To: COMPOSER ==> UCL - Londons Global University

DD.20160621.1826.CEST

Try this ...

Action: Format value Field: COMPOSER Formatstring: $iflonger($replace(%COMPOSER%,'podcast',,'iTunes U',),0,%COMPOSER%,%ALBUM_DEFAULT_COMPOSER%)

... or ...

Action: Format value Field: COMPOSER Formatstring: $iflonger($replace($lower(%COMPOSER%),'podcast',,'itunes u',),0,%COMPOSER%,%ALBUM_DEFAULT_COMPOSER%)

DD.20160621.1916.CEST, DD.20160704.0921.CEST

Thanks for responding.

Each podcast has unique formatting, based on the author of the podcast. In order to listen to my podcasts in an orderly fashion I must harmonize them all, at least somewhat. Once I got above a few hundred podcasts the task became overwhelming.

I hit on the idea of maintaining the unique editing rules for each podcast in tiny (empty) mp3's, one for each album.

So I have a folder of tiny mp3's 1-to-1 with each podcast download folder. And each month I 'build' the Action Groups by parsing through this folder. Hence the Export Config solution.

Mostly these 'rules' embodied in the tiny mp3's don't change, but each month there are a half dozen or so that do. So I can't just have a standardize edit.

The Composer issue was just one of many (Title, Artist, Genre, PodcastURL, Comment, etc.).

Again thanks for helping me work my way through this (longstanding) issue.

K

My earlier solution was wrong. Some of the composers have commas in their names, so the output needs to be literalized (surrounded in single quotes). So how to literalize a blank composer?

The only solution I could come up with is to count the length of the composer and to manually fill in composers shorter than three (3) with an un-literalized blank.

REM Export Config to generate an Action Group
REM Purpose is to replace blank composers with a default album-level composer
$if($and(%composer%,$neql(%composer%,podcast),$neql(%composer%,iTunes U)),%composer%,
$if($grtr($len('''$replace(%composer%,'','''''''')'''),2),'''$replace(%composer%,'','''''''')''',))

Examples of Generated Action Groups
REM Composer with a comma
$if($and(%composer%,$neql(%composer%,podcast),$neql(%composer%,iTunes U)),%composer%,
$if($grtr($len('Composer w, a comma'),2),'Composer w, a comma',))

REM Composer with single apostrophe
$if($and(%composer%,$neql(%composer%,podcast),$neql(%composer%,iTunes U)),%composer%,
$if($grtr($len('example with '''' single apostrophe'),2),'example with '''' single apostrophe',))

REM Blank Composer
$if($and(%composer%,$neql(%composer%,podcast),$neql(%composer%,iTunes U)),%composer%,$if($grtr($len(''),2),'',))

I noticed it doesn't work when there's a single apostrophe at the end of a composer, but I don't yet have that case.

So I still think there's a need for a way to literalize a blank output ... hence this should still be considered a 'bug' (or at least a needed enhancement).

K

See above post #3, a "string of nothing" can be created by $char(0).

DD.20160704.0924.CEST

thanks. I tried all the above recommendations and none of them seemed to help.
if you literalize $char(0) it doesn't execute to a blank

Apply it as it is: it is a function call.
Note: $char(0) delivers nothing, which means, it is not a "blank".

DD.20160704.1949.CEST

I guess I'm not understanding. I meant empty, not blank.

I need one Export Config that can output an Action Group for three different cases

  1. a composer containing a comma
  2. a composer containing a single apostrophe

so the album-level composer can be of three flavors

  1. master composer, the real master
  2. master's composer

#'s 1 and 3 must be literalized, and #3 requires MANY single apostrophe's to achieve its goal. So how to use $char(0) for #2 if literalization must be used?

Can I impose on you to take a look at the example Export config I supplied and show me how I might use your $char(0) suggestion?

Maybe it can help at first to create the wanted actionsgroup in the normal way from within Mp3tag.
Then open the actionsgroup's related mta script file with a text editor.
Then copy the text and insert the apostrophes where it should be needed in order to create a proper mte export text file.
Maybe, leave out function calls from 'literalization'?

DD.20160705.0917.CEST

Then you agree it's a bug.

Each Action Group is ~1700 lines long (yes, that many albums). Hence the approach I took.

There are 12 of these massive action groups (title, album, genre, podcasturl, etc.).

My work-around functions fine for me now and doesn't require the manual steps you propose.

K

Hi rko31415.
Using the Export function to write an MTA file: what a great idea!
Maybe it's been done before, but this is the first time I've paid attention.
I'll keep it in mind.

Try this Export script. It seems to work for the 3 specified cases.

$filename(C:\Documents and Settings\IDES\Application Data\Mp3tag\data\actions\Composer Fill.mta,UTF-8)'[#0]'$loop(%album%,1)

'T=5'
'F=COMPOSER'
'1=$if($eql(%album%,'$replace(%album%,'','''',',',''',''','[','''[''',']',''']''','%','''%''')'),$if($and(%composer%,$neql(%composer%,podcast),$neql(%composer%,iTunes U)),%composer%,'$replace(%composer%,'','''',',',''',''','[','''[''',']',''']''','%','''%''')'),%composer%)'$puts(counter,$add(1,$get(counter)))

'[#'$get(counter)']'$loopend()

$puts(REM,'if composer is empty or eql -podcast- or -itunesu- fill it with the albumtags default value')

It's always a challenge to parse somebody's code, especially when it is as "low-level" as Mp3tag scripts.
It seems as if you are using the $regexp function to ensure that the album-level tags are applied to only the files of the corresponding album.
However, my tests show that an apostrophe in the album-level ALBUM field will cause a syntax error.

Instead, I've used the $if($eql(w,x),y,z) structure.
Here's the template:
$if($eql(%album%, ALBUM_LEVEL_ALBUM), make changes (if appropriate) to %composer%, %composer%)

When writing the MTA file, various special characters must be escaped when writing ALBUM_LEVEL_ALBUM:
$replace(%album%,',',''',''') to replace comma with escaped comma
$replace(%album%,'[','''[''') to replace [ with escaped [
$replace(%album%,']',''']''') to replace ] with escaped ]
$replace(%album%,'%','''%''') to replace % with escaped %
$replace(%album%,'','''') to replace apostrophe with escaped apostrophe
(My tests showed that $ did not have to be escaped, which seems to be at odds with with the documentation.)

These can be combined into this single function:
$replace(%album%,'','''',',',''',''','[','''[''',']',''']''','%','''%''')

And the same replace function is used when writing the album-level composer.

BTW, I changed $loop(%album%) to $loop(%album%,1).

ryerman,

Confirmed your export config works great. Even better than my work-around.

And the single function: $replace(%album%,'','''',',',''',''','[','''[''',']',''']''','%','''%''') is incredibly clever. I learn something new every day with this package.

K

just a quick addendum to the fabulous replace statement:

$replace(%album%,'','''',',',''',''','[','''[''',']',''']''','%','''%''',=,''\u003d'')

For podcasturl you'll need to escape the = sign, as I've included.

That's good. Thanks for posting that information.

This also works:
$replace(%album%,'','''',',',''',''','[','''[''',']',''']''','%','''%''',=,\u003d)
The equal sign does not need single quotes in the MTA file.

I guess there is some reason, but I can't readily understand or explain.

I won't be surprised if there are other characters that need to be escaped but haven't been needed yet.