Writing xattr

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
devster
Posts: 417
Joined: 06 Jun 2017, 22:56

Writing xattr

Post by devster »

Is there a script to write xattr to a file without otherwise touching it or renaming it?

The use case would be to handle episodes not appropriately recognized, for example:

Code: Select all

show.s003e01.mkv => Specials - S00E01
show.s01e03.mkv => S01E02
show.s01e03.real.mkv => S01E03
and other fringe cases like so.

The best use I can find is to combine it with the -list command.
I may have missed something but the following invocation:

Code: Select all

filebot -list -rename --action test --filter 'whatever' filename.mkv
requires the file to be renamed, and --format '{fn}' skips the rename since the original already exists.
I only work in black and sometimes very, very dark grey. (Batman)
User avatar
rednoah
The Source
Posts: 22990
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Writing xattr

Post by rednoah »

Setting some xattr as a preliminary step to help with matching later seems cumbersome.

Why not use -rename --filter? IMHO, it's a much better option and the command-line call should be quite elegant and readable code-wise.

@see viewtopic.php?f=3&t=2127

e.g. force a specific match:

Code: Select all

$ filebot -list -rename a.mkv --db TheTVDB --q Firefly --filter "s00e00 == /S00E01/"
Apply filter [s00e00 == /S00E01/] on [18] items
Include [Firefly - Special 1 - Serenity]
[MOVE] from [a.mkv] to [Firefly - Special 1 - Serenity.mkv]
Processed 1 files
:idea: Please read the FAQ and How to Request Help.
devster
Posts: 417
Joined: 06 Jun 2017, 22:56

Re: Writing xattr

Post by devster »

If I understand correctly the -rename command requires changing the name of the file before applying xattr and, for example I'm unable to combine the -list command with the AMC script which makes it a bit more difficult to use for me with complex rename formats.
In my case using the following:

Code: Select all

/usr/local/bin/filebot -script fn:amc --action test --output /out --conflict skip -non-strict --log-file amc.log --def artwork=y --def ut_dir=/dir ut_kind=multi ut_title=title ut_label=N/A --def [email protected] --def [email protected] --def [email protected]
works quite alright, however when I try to do:

Code: Select all

filebot -list -rename a.mkv --db TheTVDB --q Firefly --filter "s00e00 == /S00E01/" --format @seriesFormat.groovy
it throws a syntax-related error (the format works fine in the GUI too).
Also if multiple rename cycle update the xattr that stores the original filename, part of the information could be lost.

I agree that the -list command is the solution for matching, for example in this case:

Code: Select all

show.s01e03.mkv => S01E02
show.s01e04.mkv => S01E04
it could force the episodes to match, however the requirement on the rename action I feel is unnecessary.
The matching could happen, information stored in the xattr and the file processed using AMC as any other file without a chance for mismatch.
I only work in black and sometimes very, very dark grey. (Batman)
User avatar
rednoah
The Source
Posts: 22990
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Writing xattr

Post by rednoah »

1.
You can use --filter in the amc script:

Code: Select all

filebot -script fn:amc a.mkv --filter "s00e00 == /S00E01/" ...

2.
Note that @syntax works for both command-line arguments as well as --def options and each usage comes with different semantics.

e.g.

Code: Select all

filebot @args.txt
@args.txt

Code: Select all

-list
--q
Firefly
--format
{plex}
(line separated list of command-line arguments)

You can pass your complex format as --format argument, but I'm not sure if bash has a very elegant way for allowing you to do that. This comes to mind:

Code: Select all

FORMAT=`cat format.groovy`
filebot --format "$FORMAT" ...

3.
I don't see the use case at all. I'll need better example situations and use cases before I consider any kind of implementation of "magic xattr values" that force certain matches.

:idea: Note that --db xattr kinda already does that, reading the metadata object from the xattr and using that as the match for any given file.
:idea: Please read the FAQ and How to Request Help.
devster
Posts: 417
Joined: 06 Jun 2017, 22:56

Re: Writing xattr

Post by devster »

I can confirm that your snippet to pass it as a variable in the shell works, I can't figure out why using the @ syntax throws:

Code: Select all

SyntaxError: missing token: }
javax.script.ScriptException: SyntaxError: missing token: }
	at net.filebot.format.ExpressionFormat.compile(ExpressionFormat.java:112)
	at net.filebot.format.ExpressionFormat.<init>(ExpressionFormat.java:43)
	at net.filebot.format.ExpressionFileFormat.<init>(ExpressionFileFormat.java:13)
	at net.filebot.cli.ArgumentBean.getExpressionFileFormat(ArgumentBean.java:239)
	at net.filebot.cli.ArgumentProcessor.runCommand(ArgumentProcessor.java:60)
	at net.filebot.cli.ArgumentProcessor.run(ArgumentProcessor.java:26)
	at net.filebot.Main.main(Main.java:111)

Failure (°_°)
while AMC and bash seem to work. It probably has a blank line in the middle of the file though.

Regarding number 3 I'm not referring to FileBot itself, but rather, if possible, a script similar to the current xattr.groovy that writes xattr instead of reading them, allowing a second run to automatically prefer them as matches. However I agree that the use case is quite miniscule.
I only work in black and sometimes very, very dark grey. (Batman)
User avatar
rednoah
The Source
Posts: 22990
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Writing xattr

Post by rednoah »

Your script probably has multiple lines, so you can't use the @syntax when you're passing command-line arguments.

This is a perfectly valid Format Expression:

Code: Select all

{
    plex
}
But it is not a valid list of separated command-line arguments.


In this case,

Code: Select all

filebot --format @format.groovy
is equivalent to

Code: Select all

filebot --format "{" "    plex" "}"
which doesn't make sense, because you're only passing "{" as --format option, and that's clearly not a valid expression because the { is never closed with an } and thus you get that error message.


:idea: Note that FileBot will always emphasize the filename over the xattr. The latter is used, but if it's in conflict with the filename then the filename rules. This is a design decision to avoid "magic behaviour" because normal user can't see xattr and thus wouldn't think of them affecting behaviour is something doesn't work as expected.
:idea: Please read the FAQ and How to Request Help.
Post Reply