I’d like the Date to be set to the minimum of the years represented in %_recording_firstreleasedate% and %originaldate%.
So far I’ve been using this script, which I understand sets it to %_recording_firstreleasedate%, if present, else %originaldate% if present else leaves it at its current value. $set(date,$if2(%_recording_firstreleasedate%,%originaldate%,%date%))
…which is not what I’m after
I can’t see any scripting function for arithmetic minimum. But I can see there are functions for numeric comparison e.g. $gt, $lt. So I (naively) guessed I’d need to do something like: $set(date,if($lt(%_recording_firstreleasedate%,%originaldate%),%_recording_firstreleasedate%,%originaldate%) – which gets error: "1:14 Unexpected character ‘(’.
I see that is the character after the “$lt”. I am confused why that is an error.
Also I wonder what $gt would do (in my script) if one or both of the date-related variables was empty. Would a complete script have to test for empty first before applying comparison functions?
I’m relatively new to scripting in Picard, struggling, but having a go. Any tips (hopefully to avoid fruitless experiment/scouting journeys) would be welcome. Is there a good interactive playground for such functions? Like in foobar or some other app?
Yes that works great! And it’s good to be certain that’s the logical way to go about this kind of conditional in Picard. Amazing that you could just knock it together so quickly on a phone.
To fully clarify how your script worked, I tab-structured and bracket-coloured it (in a /code block inside Notion), as shown (in the screenshot image) below. I appreciate that Picard-script is not Bash-script, but the auto-colouring worked pretty well. Maybe helpful to others also.
It’s all in a state of flux, as I learn and experiment.
Just now for example, I reshaped outsidecontext’s script to: $set(date,$if2($if($lt(%firstrelyear%,%originalyear%),%firstrelyear%,%originalyear%),%originalyear%,%originalyear%,%date%))
…because in one track for example, the tag specifies:
firstrelyear: 1998 – which relates to the compilation album it came from
Original Year: 1967 – which is the year I want in Date
firstrelyear itself is assigned by the following script: $if($gt($left(%_recording_firstreleasedate%,4),$get(origyear)),$set(firstrelyear,%origyear%),$set(firstrelyear,$left(%_recording_firstreleasedate%,4)))
That notation is good to visualize, but be aware that the tagger script language unfortunately is very whitespace sensitive, and all the spaces and linebreaks are part of the input, so the script likely won’t work if you enter it like this in Picard.
There are also tagger script plugins for some text editors, e.g. I have some for vscode and atom. Maybe that’s also something that can help when working with some more complex scripts
could be for different edits of a track. for example, Speak to Me / Breathe in the Air was combined into a single track on CDs after around 1983, even though The Dark Side of the Moon came out in 1973, (where the two tracks are seperate). I tried listening to my library in order of _recording_firstreleasedate, and that wreaked havoc on that album in particular.
Not exactly, because $lt only works if the arguments are integers. The dates (YYYY-MM-DD) in the arguments will cause $lt to always return “” (False) as would a blank argument. To properly compare the full dates, you would need to compare the year, month and date components individually.
In the revised @davidesp script, the comparison works because they are using just the year portion of the date.
You could also remove the dashes and compare “YYYYMMDD” as a number, no? Since it isn’t using weird US nomenclature of MM-DD-YYYY it should still sort and $lt/$gt compare properly, I think.
Yes, but only if you have complete dates. If day or month and day are missing this need to be handled (e.g. by setting it to “00”). So a bit more complicated to do than just replacing the dashes