Can you add a script function for date processing?


#1

I mainly use mp3tag for processing BBC podcasts. These typically have filenames of form

prg_yyyymmdd.mp3

where 'prg' is a truncated version of the original radio programme's name, and the 'yyyymmdd' portion is the original radio programme's transmission date.

I've developed several quite complicated action lists where I typically copy the filename to other fields (eg 'Album' or 'Title') then manipulate the filename and whatever was originally in those fields, using a series of regex based replaces, to reset them to values I want.

Unfortunately for some BBC programmes the same 'prg' letters are used to represent programmes transmitted several times per week, in somewhat differing formats. For example in one program what's transmitted on a Sat/Sun reports on a particular problem, while in the following Wednesday's transmission there's a phone-in about a related matter.

At the moment I end up with both sorts of programme in the same 'Album' subfolder on my mp3 player because I cannot distinguish between the two types of podcast which both have the same 'prg' value in their filenames.

I'd like to be able to derive the transmission date's day name from the yyyymmdd value in the filename. If you could provde a function which, when given 'yyyymmdd' returned an integer in range 1-7 or 0-6 or whatever, this would be extremely useful.


#2

You can use a converter funcion to split the filename into several tag fields, alternatively you may use an action "guess values".
Here is a converter example:

Convert | Filename - Tag | ALT+2

Select format string

Formatstring: prg_yyyymmdd.mp3
%prg_title%_%prg_datetime%

Preview
prg_title | prg
prg_datetime | yyyymmdd

Further on you may evaluate the new tag fields to make your decisions.

As I understand .. you need a $weekday() function returning the weekday number in the format of ISO 8601 (1..7, monday..sunday) or american standard (0..6, sunday..saturday).
Such a function does not exist in Mp3tag scripting language.
I think it is not possible to calculate a weekday number by Mp3tag scripting language now.

DD.20090823.0825.CEST


#3

Precisely, which is why I am asking for it.


#4

Here is a Mp3tag action script, which calculates the ISO weekday number and the ISO weekday name from a given ISO date string.

For example ... ISO Date Day-Nr Day-Name-Short Day-Name-Long

1954-12-01   3       Wed             Wednesday
1958-10-27   1       Mon             Monday
1966-02-17   4       Thu             Thursday
1993-10-05   2       Tue             Tuesday
2009-02-01   7       Sun             Sunday    
2014-03-16   7       Sun             Sunday
9999-12-31   5       Fri             Friday

The action group expects the tag-field TMP_ISO_DATE filled with a correct ISO date string of format "YYYY-MM-DD".

The action group creates three new tag-fields ...

TMP_ISO_DAYOW       number of weekday (1..7 for Monday..Sunday)
TMP_ISO_DAYNAME_L   name of weekday in long version (Monday..Sunday)
TMP_ISO_DAYNAME_S   name of weekday as 3-letter abbreviation (Mon..Sun)
Begin Action Group Format DATE#Get DayOfWeek from ISO Date

Action #1
Actiontype 5: Format value
Field ______: TMP_ISO_DATE
Formatstring: $if2(%TMP_ISO_DATE%,'9999-12-31')

Action #2
Actiontype 7: Import tag fields (guess values)
Source format __: %TMP_ISO_DATE%
Guessing pattern: %TMP_ISO_YEAR%-%TMP_ISO_MONTH%-%TMP_ISO_DAY%

Action #3
Actiontype 5: Format value
Field ______: TMP_ISO_YEAR
Formatstring: $sub(%TMP_ISO_YEAR%,$if($less(%TMP_ISO_MONTH%,3),1,0))

Action #4
Actiontype 5: Format value
Field ______: TMP_ISO_DAYOW
Formatstring: $mod($add(%TMP_ISO_YEAR%,$div(%TMP_ISO_YEAR%,4),$div(%TMP_ISO_YEAR%,-100),$div(%TMP_ISO_YEAR%,400),$regexp(';0=0;1=3;2=2;3=5;4=0;5=3;6=5;7=1;8=4;9=6;10=2;11=4;','^.;'$sub(%TMP_ISO_MONTH%,1)'=(\d);.$','$1'),%TMP_ISO_DAY%),7)

Action #5
Actiontype 5: Format value
Field ______: TMP_ISO_DAYOW
Formatstring: $if($eql(0,%TMP_ISO_DAYOW%),7,%TMP_ISO_DAYOW%)

Action #6
Actiontype 5: Format value
Field ______: TMP_ISO_DAYNAME_S
Formatstring: $regexp(';0=Sun;1=Mon;2=Tue;3=Wed;4=Thu;5=Fri;6=Sat;7=Sun;','^.;'%TMP_ISO_DAYOW%'=(\w{3});.$','$1')

Action #7
Actiontype 5: Format value
Field ______: TMP_ISO_DAYNAME_L
Formatstring: $regexp(';0=Sunday;1=Monday;2=Tuesday;3=Wednesday;4=Thursday;5=Friday;6=Saturday;7=Su
nday;','^.;'%TMP_ISO_DAYOW%'=(\w{6,9});.$','$1')

Action #8
Actiontype 9: Remove fields
Fields to remove (semicolon separated): TMP_ISO_YEAR;TMP_ISO_MONTH;TMP_ISO_DAY

End Action Group Format DATE#Get DayOfWeek from ISO Date (8 Actions)

Format_DATE_Get_DayOfWeek_from_ISO_Date.mta (1.07 KB)
After downloading rename the mta file to ...
"Format DATE#Get DayOfWeek from ISO Date"

I have derived this Mp3tag solution from the methods of Sakamoto, Lachman, Keith and Craver.
http://en.wikipedia.org/wiki/Determination...eith_and_Craver

DD.20140316.1540.CET

Format_DATE_Get_DayOfWeek_from_ISO_Date.mta (1.07 KB)


Extract weekdays and month names from timestamp