Scripting for isolating part of a number

This is embarrassing because this should be simple. I can do this in Excel, SQL, etc. but in Picard, not a chance. All I want to do is strip this: 1039.86 kbps to “1039 kbps”. Anyone?

Try (untested code):

$set(_source,1039.86 kbps)
$if($find(%_source%,.),
  $set(_target,$left(%_source%,$find(%_source%,.) kbps),
  $set(_target,%_source%)
)

You could also do it a bit more efficiently using a $rreplace() function like (untested code):

$set(_source,1039.86 kbps)
$set(_target,$rreplace(%_source%,\(\\.\\d*\),)
3 Likes

That works great. Thanks :slight_smile:

Can you explain this to me? This works. By trial and error and looking at samples it works but I don’t know why. I don’t understand why putting the $eq part and the number 1 makes a difference, but it does.

Can you break it down in English? LOL

$if($eq(originaldate,)1,$set(originaldate,%originaldate%))

I’m not sure what you’re trying to do here, but there are a couple of problems. First, your $eq() will always return false because you are comparing “originaldate” to “”. I suspect that you meant to use %originaldate% instead. Second, by entering the “1” within the first part of the $if() statement, the evaluation will always be true. Third, you are setting the tag originaldate to the value that it already holds.

2 Likes

So LOL now you know why I needed to have someone explain this. Back to the drawing board.

I do have trouble with the conditions. I struggle with it for some reason here. I don’t seem to have that problem with SQL or Excel.

I’m trying to figure out this next task. Maybe you have some ideas on if this is possible.

IF %_bitrate% falls in the range of:

  • 128-159 then Quality is Fair
  • 160-199 then Quality is Good
  • 200-480 then Quality is Very Good
  • 481-2000 then Quality is Excellent

I’m trying :frowning:

Perhaps something like:

$set(Quality,Really Bad)$noop( This is the default value )
$if($gte(%_bitrate%,128),$set(Quality,Fair)
$if($gte(%_bitrate%,160),$set(Quality,Good)
$if($gte(%_bitrate%,200),$set(Quality,Very Good)
$if($gte(%_bitrate%,481),$set(Quality,Excellent)
2 Likes

What does the “$noop” do? Comment?

It actually does nothing at all. Good for entering comments in the code. See the documentation for more information.

1 Like