Refresh only xattrs and/or access xattr writing method from groovy

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
FiletBot
Posts: 3
Joined: 04 Jan 2020, 18:35

Refresh only xattrs and/or access xattr writing method from groovy

Post by FiletBot »

Hello there!

Is the algorithm that writes xattrs to the file available as a method for groovy scripting? Or do I have to replicate it? I've searched everywhere including the docs but I can't find any definitive answer.

I simply want to refresh/refetch the extended attributes. From the internet, that is. So for example, a show was still running earlier but has now ended with no more seasons to come. Replace {'status': 'running'} with {'status': 'ended'}. Or, for example, I fetched metadata from TheMovieDB::TV but then I want fetch the metadata provided by TheTVDB (although this second example scenario is less important).

Just like fn:artwork.tvdb but only metadata such as xattrs and nfos. No artwork och file naming.

Is this possible without replicating it from scratch in groovy? For example, if in the future filebot includes some other xattr which I then have to hard code it in my groovy script. That would be rather annoying.

By the way, I have some programming skills but I have never used groovy before so bare with me. But I'm prepared for the learning curve.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Refresh only xattrs and/or access xattr writing method from groovy

Post by rednoah »

Updating xattr without renaming files would be rather tricky. There's no built-in solution for that.

I suppose you could learn from the xattr and miss scripts on how to read metadata and fetch fresh episode objects:
https://github.com/filebot/scripts

And then write xattr based on that. You can write xattr via the built-in extensions, but the Episode->JSON conversion might not be possible via public APIs.
:idea: Please read the FAQ and How to Request Help.
FiletBot
Posts: 3
Joined: 04 Jan 2020, 18:35

Re: Refresh only xattrs and/or access xattr writing method from groovy

Post by FiletBot »

Any chance such a method might be accessible via public APIs in a future update?

Can't figure out how to solve the conversion in any other way except for modifying the json produced by feeding JsonBuilder the Episode object. Though some, or at least certification key is null.

Does changes to the json occur often? I.e. restructure or key renaming.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Refresh only xattrs and/or access xattr writing method from groovy

Post by rednoah »

1.
I've added an extension method File.setMetadata() with r7026 which should take care of that.

e.g.

Code: Select all

def f = new File(...)
f.metadata = new Episode(...)

2.
There will be no breaking changes to the JSON Episode / Movie object structure.



EDIT:

I've added support for this use case to the xattr script via --action update:
https://github.com/filebot/scripts/comm ... fa60e3de9f
:idea: Please read the FAQ and How to Request Help.
FiletBot
Posts: 3
Joined: 04 Jan 2020, 18:35

Re: Refresh only xattrs and/or access xattr writing method from groovy

Post by FiletBot »

Awesome! Thank you.

How do I go about and change the provider? Can I perform a search based on metadata already provided from say TheMovieDB::TV to to TheTVDB, and by doing so switching Obj.seriesInfo from one to the other? Following my second example.

I've tried finding out how to do this, but with no success unfortunately. Is it possible?

EDIT: Another scenario affected by this is files without xattrs, of which only the fresh metadata is desirable because a second rename would be redundant, possibly cumbersomely so.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Refresh only xattrs and/or access xattr writing method from groovy

Post by rednoah »

You can change the provider, but then you'll have to write the Episode-equals-Episode logic yourself. If you stick to the same database, then you can just use the episode id, otherwise you'll have to match based on SxE numbers, episode title, etc. Whatever works best for your test cases.

If your files are already well-named, then you can probably take shortcuts, grab episode lists, match episodes, etc, in your own Groovy code quite easily, and then assign xattr metadata as shown in the examples above.

Processing files with FileBot as usual is probably easier though. You generally don't lose xattr selectively. If the file system doesn't support xattr, then you won't have any xattr for any files, and you might as well process all files again, into a new file system where xattr is supported.
:idea: Please read the FAQ and How to Request Help.
Post Reply