Tagger-Script: current time?

Hello, i want to add a custom tag to my audiofiles with the current timestamp when i am processing them via picard and adding them to my archive. Is there some way to do this with the tagger script?

thank you :3

4 Likes

I find it interesting that nobody requested this before :slight_smile: It is not possible with Picard out if the box, but a simple plugin could add a tagger script function for that. I can’t properly type one right now, maybe somebody else here wants to write it? :joy:

If not I’ll try to remember to post the plugin here tomorrow.

2 Likes

thanks for the hint with the plugin, i thought i try myself and i don’t know what i did exactly but it seems to work.

timestamp.py

# -*- coding: utf-8 -*-
# This work is free. You can redistribute it and/or modify it under the
# terms of the Do What The Fuck You Want To Public License, Version 2.
# See http://www.wtfpl.net/ for more details.
PLUGIN_NAME = 'timestamp'
PLUGIN_AUTHOR = 'ehrgeiz'
PLUGIN_LICENSE = 'WTFPL'
PLUGIN_LICENSE_URL = 'http://www.wtfpl.net/'
PLUGIN_DESCRIPTION = '''Adds a timestamp function to tagger-script'''
PLUGIN_VERSION = "0.1"
PLUGIN_API_VERSIONS = ["1.0"]

from picard.script import register_script_function

def timestamp(parser):
	import datetime
	now = datetime.datetime.now()
	return now.strftime("%Y-%m-%d %H:%M")

register_script_function(timestamp)

and my taggerscript is then

$set(Dateadded,$if2(%Dateadded%,$timestamp()))

i don’t know why i have to write something in parenthesis in the “def timestamp()” but i guess this works now. maybe i should set check_argcount:false?

5 Likes

Great, that’s exactly what I had in mind. One thing to note is, that if you place this function in Options > Advanced > Scripting it will be executed when the data gets loaded from the server. If you place the function in the file naming script (e.g. to have the timestamp as part of the file name) then it will get executed when you hit save.

The first argument to any script function is a parser object, which gives you access to metadata and some internal stuff. Not needed here, but for correctness just call it parser:wink:

1 Like

Awesome! Thanks for this, I can finally do this: https://www.youtube.com/watch?v=AQvOnDlql5g

@ehrgeiz did you happen to actually test if your $if2 actually works for you? i.e. Is it preventing your old value from being overwritten? For me, it always overwrites the field, even if it already contains a value.

As far as I can tell, only the fields listed at https://picard.musicbrainz.org/docs/tags/ can be accessed using %fieldname% - so a custom field name always returns null and therefore $if2 will always return the 2nd argument.

Or have you done something to make %Dateadded% work for you?

1 Like

You are of course right, I just found out myself that the timestamp is overwritten :frowning:

maybe someone can tell me if it is possible to read out the tags from the file? I browsed to some plugins to find a reference I can lean on, but I haven’t found a plugin that reads the tags from the files itself.

Can’t help with a plugin sorry.

But I’m not sure why Picard itself doesn’t just parse all tags by default, kind of like foobar2000 does. Can’t see why that’d be a problem, but it hasn’t been implemented.

I was trying to see if I could write the current date/time to my files, and ran into this existing thread.

I tried copying the lines from the third post, and save it as timestamp.py.
But Picard will not load that as a plugin.

Perhaps because I am using Picard 2.x?

Does anybody have a working solution to write the current date/time to files?

Try changing:

PLUGIN_API_VERSIONS = ["1.0"]

to

PLUGIN_API_VERSIONS = ["1.0", "2.0"]
3 Likes

Ah yes, great. That works.

P.S.
This is very useful to check when your file(s) have been updated by Picard for the last time.
Perhaps it is a good candidate to include in Picard’s 2.x plugins list?

1 Like

It’s probably even a good candidate to include into Picard itself :smiley:

6 Likes