Compare track length in Picard

Tags: #<Tag:0x00007fa5cbdf00e8>

Is it possible to compare an actual length in a file with the length of the matched track in the database, in Picard?


Not with scripting, as you don’t have the lengths for files and tracks available there. There is the %length% variable, but it only has the length for either a track or file and also in the format “hh:mm:ss”, which is not too useful for length comparison.

A plugin however could do it, so you could have a right click action to do some comparison. What is your goal actually, what would you like to do with the info?

1 Like

My goal is to use a script to assign a tag to files that are a mismatch of greater than x seconds. One purpose would be to then go and do more research on those tracks at some point, to see why there’s a mismatch (single vs album version, for instance). I know I have examples like that from early days when my tagging was sloppier, so I’m trying to get them corrected now.

I have searched for a long time to find a script or plugin which does this, didn’t find anything. And my programming skills are insufficient to write a plugin :slight_smile:

So for the moment I use a workaround.

I added this at the start of my filenaming script:


and then end the filename with “- %MB_Length% - %MB_Timediff%”

This adds track length according to the database and time difference (both in seconds) to the filename. Timediff will always be 0 on the first save. And I added both tags to the preserve tag list.

Next, I open the files in MP3Tag, and have it convert the filename to tags. MP3Tag has the actual track length available as %_length_seconds%, combined with the value it just wrote to the %MB_Length% tag it can calculate the difference and store the result in %MB_Timediff%. Then it’s just a matter of creating an extra column to show the %MB_Timediff% value, sort by it, and select the tracks that are too far off.

Since you can drag&drop between open windows of both programs, this works pretty fast once it is set up.

Interesting. That makes me think it should be possible to just write the length itself to a tag. Then I can probably use MusicBee to do a comparison. I’ll have to play with that.

I tried to write a tagger script again, since that uses the same syntax as the file naming script. And it actually kind of worked.

It’s actually 2 tagger scripts, which are almost identical. Here is one of them:


This creates a Length_File tag with the track length in seconds as value. For the second script, on the second line Length_File is changed to Length_MB.

If you run this script on tracks in the right pane, it uses the track length according to the database. When run on tracks in the left pane, it uses the actual track length. So there are 2 scripts to make sure the lengths are stored in the correct tag (Length_File for the left pane, Length_MB for the right pane). I didn’t find a way to select the correct tag automatically.

The last 2 lines calculate the difference and create a tag that indicates if this difference is acceptable or not. These can be run from both panes.

I know it’s not perfect, as it requires quite some manual input to execute the scripts and save the files in both panes, but it’s a start. I’ll leave it up to someone with better programming skills to translate it into a plugin :slight_smile: