Extract weekdays and month names from timestamp

I'm trying to create an Export script which will export to a standards-compliant podcast RSS feed.

However (as usual :stuck_out_tongue:) I've encountered a few problems.

1. How can I copy the weekdays and month names from the File Create timestamp, it seems Mp3Tag re-formats them into digits before inserting them into the tag.

The RFC 2822 standard for RSS feeds is: Thu, 31 05 2012 10:56:46 GMT

Seeing as I had no way to extract the weekdays I tried to at least convert the 2-digit month name into a name, one for each month, but my RegExp failed. Could anyone correct this (excuse my ignorance):

Original (in %pubdate% tag): 31 05 2012 10:56:46 GMT

What I wanted my code to do: 31 May 2012 10:56:46 GMT

My code:

Solution (thanks to DetlevD for the brilliant code and support):

2. I'm trying to set a limit to the number of exported $loop entries. Using the format: $loop(%fieldname%,num) as stated in the help documents doesn't appear to work, as I'm sorting by %releasetime%, and each item's value is different.

Eg: $loop(%releasetime%,20)

Where '20' is the number of looped s I'd like in the Export output. However this doesn't work, so I'm guessing the number of loop entries should be controlled by some function that would wrap around the tag, but I'm unsure. I tried $repeat(.....,20) but that didn't work.

The idea is if the user had 100 items selected and then used Export that only 20 entries (with exclusions based on extension and directory name) would be appear the output. I have the conditional exclusions set up, all I need now is a way to set a limit on the number of displayed entries.

3. How can the $loop be sorted in the reverse order? Currently the newest (as sorted by the timestamp) are last, but I'd like them to be first in the list. Sorting them differently in the main Mp3Tag window doesn't change their order.

I found this topic but I'm unsure how I would apply it to the format: YYYY-MM-DDThh:mm:ssZ.


4. How would it be possible to only include items in the $loop that match certain extensions, and hide others (similar to a conditional export)?

Eg: display Mp3s and Mp4s in the $loop, but not FLACs or WAVs.

Solution - wrap the entire tag within this conditional $if parameter:
.........inner content here.........

Older solution (works, but only allows for two matching extensions, DetlevD's revised code above allows for more extensions to be added):
.........inner content here.........

5. In my testing I noticed that that paragraphs and line breaks need to formatted in HTML to be displayed as such in feed readers. The text content is entered in a multi-line comment box, saved to the Comment tag, which the Export script would then format to HTML.

The first line of the Comments would start with a

and end with a

. Additionally any line of text following two carriage returns (?) would start with a

followed by the text and end with a

. Line breaks would only have to start with a

What I'm hoping to achieve:

First line of text.....

Another line.....
Line break.


First line of text.....

Another line.....

Line break.

After the remainding problems have been fixed I'm thinking of submitting it to the Export configuration sub-forum for people to use who make podcasts, complete with annotations and alternative codes. The Export script would be fully automatic, turning Mp3Tag into a useful feed generator :music: !

Thanks :slight_smile:

1 Like

See manual ...
%_extension%, $or, $eql, $if


See current RFC 5322 ...

On my computer system (set to Germany and ISO8601) the Mp3tag system variables provide these values:
%_file_create_date% ... 2012-02-15
%_file_create_datetime% ... 2012-02-15 06:29:14
%_file_create_datetime_raw% ... 1329283754

Mp3tag does not support weekday names or month names.
Mp3tag does not provide any function for date time calculations or formatting.

See also ...


Please check again, there are month names which are not conform with the standard RFC 5322.

Please provide a small example script.

Another proposal to solve this problem ...


... or ...



Updated main post.

See also ...

I do not think, that the second parameter 'num' within the function '$loop(%fieldname%,num)' can control the number of loops.
The documention description may be incorrect.

I understand the second parameter as a boolean switch, which allows only two values 0 or 1.
The documention description may be incorrect.

$loop(%fieldname%,0) ...
... allows each item from the item list to be processed.

$loop(%fieldname%,1) ...
... allows only the first item of ambiguous items from the item list to be processed.
... restricts the focus to the first item of a group of items with the same value.


I now know why Mp3Tag would crash when such a value is added to the loop. Thanks for the clarification, the help file could be a little clearer on this.

Hm, you can use a user defined variable to count how much iterations have been done so far.
See Mp3tag Export Scripting Language functions: $put, $puts, $get.

Set variable in display mode (will be printed) ...
... counts from $loop starting with 1 by 1 until $loopend.

Set variable in silent mode (will be not printed) ...
... counts from $loop starting with 1 by 1 until $loopend.

Use content of variable ...
$ifgreater($get(MyCounter),20,'do nothing','do something')

But do not expect that the Mp3tag Export Scripting Language do behave like other programming languages!

Here is a test script to visualize the visibility of user defined variables within an export script.
Note the quirky behaviour, when loops are embedded.
20120607.Test.Visibility._put._get.zip (689 Bytes)


20120607.Test.Visibility._put._get.zip (689 Bytes)

Here is hex-view of a sample content copied from a COMMENT tag-field ...

"000000000 4C 69 6E 65 20 31 0D 0A-4C 69 6E 65 20 32 0D 0A |Line 1..Line 2..|"
"000000010 4C 69 6E 65 20 33 0D 0A-0D 0A 4C 69 6E 65 20 34 |Line 3....Line 4|"
"000000020 0D 0A 4C 69 6E 65 20 35- |..Line 5 |"

So a single CRLF (0D0A) should be converted into a HTML linebreak (BR) and a double CRLF should be converted into a HTML paragraph end tag?

You can use Mp3tag functions $replace or $regexp to solve this task.

For example:

Trim the comment string at both edges ...


Note, the regular expression character class "\s" includes all "whitespace" characters ...
$char(9), $char(10), $char(11), $char(12), $char(13), $char(32).

Set paragraph end and start tags ...


Set break tags ...

$regexp(%COMMENT%,'(\r\n)',' ')

Enclose the string in paragraph start and end tags ... putting it all together ...

''$regexp($regexp($regexp(%COMMENT%,'\A\s+|\s+\Z',),'(\r\n){2}',''),'(\r\n)',' ')''

.. .will result into HTML line ...

Line 1 Line 2 Line 3

Line 4 Line 5


The HTML formatting code works beautifully! Where there's a will there's a RegEx :laughing: !

Thanks to your suggested code I've (almost) managed to successfully limit the number of outputted items in the $loop!

It has a bug that I can't figure out, though:

If none of the files selected in Mp3Tag to be Exported are from an excluded directory (excluded extensions don't cause this problem) then the limit function works as expected.

However, if there is one file selected that is from an excluded directory then the loop outputs 1 less . If two files in the selection are from an excluded directory then a further 1 less is outputted.

Eg (with an example limit of '3'):

Selected in Mp3Tag:

Export output:

Selected in Mp3Tag:
4 [excluded directory, can be in any position in the selection]

Export output:

Adding a sub-$loop (sorted by the variable) fixes the problem for selected excluded files but adds 1 more if the selection doesn't contain excluded files, so the problem is then inversed!

The code I'm using (I know, looks a bit messy):




Basically the 'Edit|Edits|edit|edits|' section is the names of the directories to be excluded from the $loop output. It seems that the following %dummy% could be causing the issue, but I'm uncertain how I should change the code to fix the problem.

Just for the test I reformatted the code, what helped me to understand ... and the result looks ok to me.
But ... there is something confusing ... why the counter is updated by plus one on each loop, even in the case, when the script logic does not run through the code part, where the counter code resides?

Hm, that is what I've said above ... do not expect that the Mp3tag Export Scripting Language do behave like other programming languages!

I need some time to poke around ... in the meantime you can see yourself ...

01: $filename($getEnv('USERPROFILE')'\Desktop\TEST.1.txt',UTF-8)

02: $loop(%_path%)
03: $ifgreater($strstr('|Edit|Edits|edit|edits|','|'%_directory%'|'),0,
04: '# Excluded Folder: '%_folderpath%,
05: $ifgreater($strstr('|mp3|m4a|','|'%_extension%'|'),0,
06: $put(LC,$add($get(LC),1))
07: $ifgreater($get(LC),20,
08: '# Excluded File: '%_path%,
09: ''%TITLE%''),
10: '# Excluded Ext: '%_extension%
11: ))
12: $loopend()

01: $filename($getEnv('USERPROFILE')'\Desktop\TEST.3.txt',UTF-8)

02: $loop(%_path%)'=== '$put(LC,$add($get(LC),1))' ==='
03: $ifgreater($strstr('|Edit|Edits|edit|edits|','|'%_directory%'|'),0,
04: '# Excluded Folder: '%_folderpath%,
05: $ifgreater($strstr('|mp3|m4a|','|'%_extension%'|'),0,
06: $ifgreater($get(LC),20,
07: '# Excluded File: '%_path%,
08: ''%TITLE%''),
09: '# Excluded Ext: '%_extension%
10: ))
11: $repeat('=',20)
12: $loopend()

The trouble is, that $put is not allowed to be used within other functions, that means not even in a $if function branch.
$put is only allowed on the first logical level within $loop.
Any $if decision must be done in the inner part of the $put parameter list.
I always stumble over this hurdle.


Here comes my Mp3tag Export Scripting code, that no one can pay.
I feel like after punching a stack of 1024 punch cards.
Hopefully it can help to solve your problem.

In this state the script gives plenty of room to play with.
Try out changing the $puts to $put and see what information will be displayed in the output file.
Tweak the variable intOutputMax to set the maximal number of items to be written out.

If you have understood what is going on there, then do the fine tuning.
Tie the code lines together and make the code human unreadable by removing the line feeds at the right places.
Hopefully you get human readable output.

01: $filename($getEnv('USERPROFILE')'\Desktop\TEST.4.txt',UTF-8)

02: $loop($sub(999999999,%_counter%))
03: $puts(intOutputMax,20)
04: $puts(intOutputCount,$if($eql(%_counter%,1),0,$get(intOutputCount)))
05: $puts(blnExcludeFileExt,$if($eql(%_counter%,1),0,$get(blnExcludeFileExt)))
06: $puts(blnExcludeFolder,$if($eql(%_counter%,1),0,$get(blnExcludeFolder)))
07: $puts(blnExcludeOutput,$if($eql(%_counter%,1),0,$get(blnExcludeOutput)))
08: $repeat('=',80)
09: $puts(REM,'File Nr ..........: '%_counter%)
10: $puts(REM,'strOutputText ....: ')$puts(strOutputText,''%TITLE%'')
11: $puts(REM,'intOutputCount ...: ')$puts(intOutputCount,$add(1,$get(intOutputCount)))
12: $puts(REM,'blnExcludeOutput : ')$puts(blnExcludeOutput,$ifgreater($get(intOutputCount),$get(intOutputMax),1,0))
13: $puts(REM,'blnExcludeFolder : ')$puts(blnExcludeFolder,$ifgreater($strstr('|Edit|Edits|edit|edits|','|'%_directory%'|'),0,1,0))
14: $puts(REM,'blnExcludeFileExt : ')$puts(blnExcludeFileExt,$ifgreater($strstr('|mp3|m4a|','|'%_extension%'|'),0,0,1))
15: $puts(REM,'blnCountDown .....: ')$puts(blnCountDown,$ifgreater($add($get(blnExcludeFolder),$get(blnExcludeFileExt),$get(blnExcludeOutput)),0,1,0))
16: $puts(REM,'intOutputCount ...: ')$puts(intOutputCount,$ifgreater($get(blnCountDown),0,$sub($get(intOutputCount),1),$get(intOutputCount)))
17: $ifgreater($get(blnExcludeFileExt),0,'# Excluded FileExt: '%_extension%' | '%_path%,
18: $ifgreater($get(blnExcludeFolder),0,'# Excluded Folder : '%_folderpath%,
19: $ifgreater($get(blnExcludeOutput),0,'# Excluded File : '%_path%,
20: 'Item Nr ..........: '$get(intOutputCount)
21: 'Item String ......: '$get(strOutputText))))
22: $loopend()
23: $repeat('=',80)


Please would you be so kind and show a preview file, how the end product podcast file, including example content, should look like?
Thank you in advance.


Absolutely, see attached zip file. Includes sample mp3 and flac files in a directory, the Export template, and the Export output XML. Note: things like the formatting of the %title% will be changed for the final release, and strings like 'YOUR TITLE HERE' would be edited by the user.

It should also be noted that the files to be Exported should be sorted by a column in Mp3Tag by the 'ReleaseTime' tag, with newest dates last.

:astonished: What a piece of work! You've practically coded a micro application.

The code works perfectly and solves the problem, and although the Export script itself is completely unreadable when all the line feeds are removed I still think I know a way of documenting what each function does when I come to making the help file on this Export script.

Mp3Tag has the quirk of still leaving empty lines when an item in the loop is excluded, but that isn't an issue, as RSS readers don't care about blank spaces between elements.

I tried merging all the $loop code into a single line (using the $char(x) for various carriage returns and spaces) yet the empty lines still appear, however I'm not concerned, it doesn't affect anything.

From what I can tell the Export script is now ready for use. The only thing left is the required GUID tag, which a user would still have to manually tag each file with. A couple of days ago I submitted a feature request for a $guid() function, which hopefully will be considered for the next development build of Mp3Tag.

Thanks for all your efforts once again, I wouldn't have known how to accomplish such code with my limited knowledge.

Podcast_Export_script_examples_and_file_samples.zip (57.4 KB)

Thank you, I will look into.

In the meantime you can fill the GUID tag with the same URL (which is also an unique value) as within the LINK tag.

So I hope, that I will be mentioned in detail by my full name, for all the honors, you will earn for your assembly :wink: ... oops, wait a moment ... I didn't see your code yet.


There is a possible simplification for the conversion of datetime from ISO 8601 to RFC 5322/2822/822 ...

$num($mid(%_datetime%,9,2),1)' '$regexp('01Jan02Feb03Mar04Apr05May06Jun07Jul08Aug09Sep10Oct11Nov12Dec','^.*'$mid(%_datetime%,6,2)'(\w\w\w).*$','$1')' '$left(%_datetime%,4)' '$mid(%_datetime%,12,8)

ISO 8601
2009-02-01 07:12:53

Date RFC 5322/2822/822
Sun, 1 Feb 2009 07:12:53 GMT (obsolet)
Sun, 1 Feb 2009 07:12:53 +0000
1 Feb 2009 07:12:53 +0000
1 Feb 2009 07:12:53

The Mp3tag scripting code from above converts ...
2009-02-01 07:12:53
1 Feb 2009 07:12:53

Because Mp3tag does not provide datetime calculations, it is not possible to detect the name of the weekday from a given date automatically.
But this is not crucial, because the RFC quasi standard proposals make the weekday optional, also the time zone is optional.
If you need to set your specific time zone, then it can be added to the converted RFC datetime string, for example ...
1 Feb 2009 07:12:53 +0100


There I have published an action group, which computes the number and the name of a weekday, for a given ISO date ...
Can you add a script function for date processing?


The script needs more reliability when working with special characters in names and URLs.
Even UTF-8 XML needs a few characters to be escaped.
And an URL needs some more characters to be escaped.

I tremendously miss two functions in Mp3tag:
- HtmlEncode

  • UrlEncode

Repeatedly those missing basic functionality messes up all joy on new coding adventures.