Page 1 of 1

Find out how many inputs are taken by Filebot and carry out different functions

Posted: 30 Jul 2017, 16:36
by Arion
I currently use a self-made notification system to notify me about the files processed by Filebot.

The only con of the system is that for every input file taken by filebot, it generates a separate message, unlike the default notification system provided by FileBot where all the processed files are bundled together in a HTML file and sent to the user. This is done by running a script with the

Code: Select all

--def exec="@file/path"
hook.

I was wondering if, by shell scripting (BASH and PowerShell) it was possible to determine how many inputs filebot took, and if it happens to be more than one/two/five it will carry out a different set of instructions, like bundle the notification messages into a single message (I'll take care of that problem)

I only need to know what condition I should use to know how many inputs filebot took, and if it's more than a specified number, run a second script.

Re: Find out how many inputs are taken by Filebot and carry out different functions

Posted: 30 Jul 2017, 16:51
by rednoah
--def exec is not suitable for this kind of task.

What you wanna do is call filebot, collect the output, run grep | wc -l to count the number of lines that contain certain keywords, and then proceed accordingly. That's pretty much the kind of task that bash was designed to do well.

Re: Find out how many inputs are taken by Filebot and carry out different functions

Posted: 05 Aug 2017, 16:05
by Arion
Can you guide me on how I can write the names of the files Filebot processes (in {s00e00} - n - t or {n} - {y} format) to a text file after filebot is done processing them? Especially when it renames more than 1 file.

Also, can I use the --def exec hook more than once to run two or multiple programs?

Re: Find out how many inputs are taken by Filebot and carry out different functions

Posted: 05 Aug 2017, 16:32
by rednoah
You can use the --def exec hook with a custom script to write text these kinds of text files. If you want to call multiple commands, then you can just do that just like on the command-line, and any script can of course call an arbitrary number of other scripts.

e.g.

Code: Select all

--def exec="echo {quote n} {s00e00} {quote t}"

Re: Find out how many inputs are taken by Filebot and carry out different functions

Posted: 09 Aug 2017, 17:56
by Arion
I'm sorry but I have a minor query.

Using your solution above, the program prints
Sherlock
-
S01E01
-
A Study in Pink
Sherlock
-
S01E02
-
The Blind Banker
Sherlock
-
S01E03
-
The Great Game
As you can see, it prints each word on a new line. I'd like all of it to be condensed to a single line. Can you offer any guidance or point me in the general direction? Thanks!

Re: Find out how many inputs are taken by Filebot and carry out different functions

Posted: 09 Aug 2017, 17:59
by rednoah
Does echo print each argument on a new line? And where do the dashes come from?

:idea: This is just an example. It shows that you can do anything you can do with PowerShell commands.

Re: Find out how many inputs are taken by Filebot and carry out different functions

Posted: 11 Aug 2017, 12:05
by Arion
I'm using

Code: Select all

echo {quote n} - {s00e00} - {t}
which gives that output with the dashes.

Upon trying

Code: Select all

echo "{quote {n} {s00e00} {t}}" | Out-File TestFile.txt -append
to write the names to a text file, I still get the same
Sherlock
S01E01
A Study in Pink
Sherlock
S01E02
The Blind Banker
Sherlock
S01E03
The Great Game
Ideally, I'd like it all to be printed onto a single line like:
Sherlock S01E01 A Study in Pink
Sherlock S01E02 The Blind Banker
Sherlock S01E03 The Great Game
and I'd like to separate them by a dash as well, if possible.

Re: Find out how many inputs are taken by Filebot and carry out different functions

Posted: 12 Aug 2017, 05:30
by Arion
But I guess it's not possible? the `quote` function is either glitchy or I dunno how to use it, I believe it's the latter.

Re: Find out how many inputs are taken by Filebot and carry out different functions

Posted: 12 Aug 2017, 06:41
by Arion
I tried this:

Code: Select all

echo "{quote ("$n") (${any{episode; s00e00 + ' - ' + t}{movie}})}" | Out-File TestFile.txt -append
But keep getting this error:
The string is missing the terminator: ".
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
Searching for this error hasn't yielded useful results yet.

Re: Find out how many inputs are taken by Filebot and carry out different functions

Posted: 12 Aug 2017, 11:13
by rednoah
What is the exact command that is executed? Have you tried copy & pasting that command into PowerShell so you can fix it?

Re: Find out how many inputs are taken by Filebot and carry out different functions

Posted: 12 Aug 2017, 15:53
by Arion
I've tried this:

Code: Select all

echo "{quote ("$n") (${any{episode; s00e00 + ' - ' + t}{movie}})}" | Out-File TestFile.txt -append
with the error given above.
I can't really put this into powershell manually and try to fix it since it'll be treated as a single string and print as it is.

When I try

Code: Select all

echo "{quote n} {s00e00} {quote t}" | Out-File TestFile.txt
it works, but every thing in curly brackets {} is printed on a single line.

I thought the keyword quote can wrap them into a single line, so I tried

Code: Select all

echo "{quote n s00e00 t}" | Out-File TestFile.txt
still get the same error stated above.

Re: Find out how many inputs are taken by Filebot and carry out different functions

Posted: 12 Aug 2017, 16:22
by rednoah
This is the not the command that is executed. Have a look at the amc.log file and see what commands are actually executed.

e.g. command template used to generate actual commands:

Code: Select all

echo {quote n}
e.g. actual command generated for an episode of Firefly:

Code: Select all

echo "Firefly"

Re: Find out how many inputs are taken by Filebot and carry out different functions

Posted: 12 Aug 2017, 18:30
by Arion
Oh yeah, the logs say this:
Execute: echo "" | Out-File TestFile.txt -append
for:

Code: Select all

echo "{quote ("$n") (${any{episode; s00e00 + ' - ' + t}{movie}})}" | Out-File TestFile.txt -append
which is because of the error. nothing is being parsed into the powershell.

Re: Find out how many inputs are taken by Filebot and carry out different functions

Posted: 13 Aug 2017, 04:11
by Arion
Hey, just wanted to let you know I figured it out by a series of trial and errors:

This works:

Code: Select all

echo "{quote("$n - ${any{episode; s00e00 + ' - ' + t}{movie}}")}" | Out-File TestFile.txt -append

Re: Find out how many inputs are taken by Filebot and carry out different functions

Posted: 13 Aug 2017, 04:51
by rednoah
1.
{quote object} should be doing pretty much the same with a lot less code. ;)

If you need your text file to be machine-readable, then {quote json} would be the way to go.


2.
So you're using the command-line to try format expressions?
Using the format editor GUI will make prototyping format expressions 100x faster.

Re: Find out how many inputs are taken by Filebot and carry out different functions

Posted: 14 Aug 2017, 12:40
by Arion
So you're using the command-line to try format expressions?
No, actually I'm trying to write these names to the file so that if there are more than 1 files processed by Filebot, it'll write all the filenames into a single message and fwd it to me.

Regarding that... I was wondering, is there a way I can call a python script at the very end when filebot is TOTALLY DONE with all file processing?

The way I want it is... I finish writing episode names to the text file, and then call a python script.

Re: Find out how many inputs are taken by Filebot and carry out different functions

Posted: 14 Aug 2017, 13:00
by rednoah
1.
I see. So you're not using the GUI at all then? That's a very ineffective way of doing things then. I wouldn't recommend it. You're just making things unnecessarily difficult on yourself. ;)

I'd do it in this order:
  • Open PowerShell and write a test command (and test it until it works)
  • Open FileBot Format Editor, copy test command, replace values with variables (and test it until it give you the commands you want)
  • Copy command template (i.e. format expression for commands) into your filebot amc command-line call

2.

Code: Select all

# call filebot
filebot ...

# call python script after filebot is completely and totally done
python ...