HELP - Filebot Groovy Script How To?

Running FileBot from the console, Groovy scripting, shell scripts, etc
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: HELP - Filebot Groovy Script How To?

Post by rednoah »

The syntax error is in the format expression. Which causes rename() to fail and return null.
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: HELP - Filebot Groovy Script How To?

Post by rednoah »

About calling other XMBC API functions just telnet like I do in the examples. The folders/files you can collect after each rename call.

Something like this (pseudo code):
def changes = []
...
def dest = rename(...)
changes += dest
...
telnet(xmbc) { out ->
changes.mapByFolder().keySet().each{ out.println(update it) }
}
:idea: Please read the FAQ and How to Request Help.
part timer
Posts: 181
Joined: 09 May 2012, 23:35

Re: HELP - Filebot Groovy Script How To?

Post by part timer »

Well I've looked again and I see every { has a } but maybe there is spacing or some other thing that I don't know about causing it to think they don't all have pairs.

Could you take a look? I realize some of it may seem unnecessary, but this is the format I'm going for. Thanks in advance.

Here are my two formats:

Episode format-

Code: Select all

rename(file:files, format:'TV Shows/{(n =~ /^[Tt]he / ? n[4..-1]+", The" : n =~ /^[Aa] / ? n[2..-1]+", A" : n).replace(":",' -').upperInitial().lowerTrail()}{" [startdate.format("yyyy")]"}/{(n =~ /^[Tt]he / ? n[4..-1]+", The" : n =~ /^[Aa] / ? n[2..-1]+", A" : n).replace(":",' -').upperInitial().lowerTrail()} {episode.special ? "Specials" : "Season "+s}/{episode.special ? "s00e"+special.pad(2) : s00e00} {t.upperInitial().lowerTrail().replacePart(", Part $1")}/{episode.special ? "s00e"+special.pad(2) : s00e00} {t.upperInitial().lowerTrail().replacePart(", Part $1")}{"  [$airdate.year]"}{"  [$vf]"}{"  [$vc]"}{"  [$ac]"}{"  [$group]"}', db:'TheTVDB')
Movie format-

Code: Select all

rename(file:files, format:'Movies/{(n =~ /^[Tt]he / ? n[4..-1]+", The" : n =~ /^[Aa] / ? n[2..-1]+", A" : n).replace(":",' -')}{"  [$y]"}{"  [Rated $certification]"}{"  [Voted $rating]"}/{(n =~ /^[Tt]he / ? n[4..-1]+", The" : n =~ /^[Aa] / ? n[2..-1]+", A" : n).replace(":",' -')}{"  [$vf]"}{"  [$sdhd]"}{"  [$source]"}{"  [$vc]"}{"  [$ac]"}{"  [$group]"}{"  [CD$pi]"}', db:'TheMovieDB')
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: HELP - Filebot Groovy Script How To?

Post by rednoah »

I'm gonna help you out with the episode format here. It's riddled with mistakes. Did you ever think of testing that expression in the Format Editor in the GUI? Step by step test each {} block and you will get it done easily. Try to do all at once in the script and you will never get it right, I wouldn't be able to.

Here is the fixed format:

Code: Select all

TV Shows/{(n =~ /^[Tt]he / ? n[4..-1]+", The" : n =~ /^[Aa] / ? n[2..-1]+", A" : n).replace(":",' -').upperInitial().lowerTrail()}{" [$startdate.year]"}/{(n =~ /^[Tt]he / ? n[4..-1]+", The" : n =~ /^[Aa] / ? n[2..-1]+", A" : n).replace(":",' -').upperInitial().lowerTrail()} {episode.special ? "Specials" : "Season "+s}/{episode.special ? "s00e"+special.pad(2) : s00e00} {t.upperInitial().lowerTrail().replacePart(/, Part $1/)}/{episode.special ? "s00e"+special.pad(2) : s00e00}{t.upperInitial().lowerTrail().replacePart(/, Part $1/)}{" [$airdate.year]"}{" [$vf]"} {" [$vc]"}{" [$ac]"}{" [$group]"}
And I told you to use '''...''' syntax to avoid escaping problems and just paste a working format unchanged.

Code: Select all

format:'''...'''
:idea: Please read the FAQ and How to Request Help.
Savvy
Posts: 16
Joined: 07 May 2012, 07:42

Re: HELP - Filebot Groovy Script How To?

Post by Savvy »

thanks rednoah, i'll come back when i've learnt a little more.... cheers
part timer
Posts: 181
Joined: 09 May 2012, 23:35

Re: HELP - Filebot Groovy Script How To?

Post by part timer »

More playing around with this and more error messages.

I finally got this working with tv shows, mainly because they were single torrent files. The version of uTorrent I'm using doesn't support the "-Xut_kind=%K" parameter. Any time I have a torrent with more than one file I get error messages. How could I edit the start of the utorrent script to simply use whatever files are in the directory that is passed through "-Xut_dir=%D" instead of it trying to figure out if it's single or multi? I have tried so many different things, but haven't been able to find one that works.

Thank you so much in advance.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: HELP - Filebot Groovy Script How To?

Post by rednoah »

Change this from

Code: Select all

if (ut_kind == "multi") {
	input += new File(ut_dir).getFiles() // multi-file torrent
} else {
	input += new File(ut_dir, ut_file) // single-file torrent
}
To

Code: Select all

input += new File(ut_dir).getFiles() // multi-file torrent
Actually you could just change the call from

Code: Select all

"-Xut_kind=%K"
to

Code: Select all

"-Xut_kind=multi"
:idea: Please read the FAQ and How to Request Help.
part timer
Posts: 181
Joined: 09 May 2012, 23:35

Re: HELP - Filebot Groovy Script How To?

Post by part timer »

That really seemed simple after hours of trying so many different things.

I'm really bad at coding obviously. So how do I change the xbmc command from what it is now to:
UpdateLibrary(video,) Because I really can't make sense of what you typed as a first response to it. I'm sorry, I wish I could read it and understand it.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: HELP - Filebot Groovy Script How To?

Post by rednoah »

Can you point me to the API documentation of that UpdateLibrary call? I can't find any docs on that. I think you refer to a function that an xbmc skin can use but that's completely different from the socket api for external programs.

For the JSON-RPC API there is only this function: http://wiki.xbmc.org/index.php?title=JS ... brary.Scan
:idea: Please read the FAQ and How to Request Help.
part timer
Posts: 181
Joined: 09 May 2012, 23:35

Re: HELP - Filebot Groovy Script How To?

Post by part timer »

User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: HELP - Filebot Groovy Script How To?

Post by rednoah »

One way is using doing executebuiltin via the depricated HTTP API that'll be faded out next release. The other is using new stuff that's not even in Eden yet. So I'm not gonna do anything offical for this at this point.

I'm sure you can get it working. Just do some testing with println to get a feeling for the code. For the http api you can use new URL(...).get() to make the call. And all the output paths you get from rename(...) anyway.
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: HELP - Filebot Groovy Script How To?

Post by rednoah »

This should help you get there:

Code: Select all

def files = []
files += rename(folder:args[0])

files*.dir.unique().each{
	def url = new URL("http", "host", "/xbmcCmds/xbmcHttp?command=ExecBuiltIn(UpdateLibrary(video, ${it.path}))")
	println url
	println url.get()
}
:idea: Please read the FAQ and How to Request Help.
Savvy
Posts: 16
Joined: 07 May 2012, 07:42

Re: HELP - Filebot Groovy Script How To?

Post by Savvy »

The Utorrent code is working perfectly Thank you rednoah.

Could you possibly help with another noob Q?
I'm saving the groovy script file to desktop names 'art.groovy', open it in the groovy console and copied in the code:

filebot -script "http://filebot.sf.net/scripts/artwork.tvdb.groovy" -trust-script G:\media\TV Shows

When i execute 'sort.groovy' a cmd window flashes and closes instantly. When checking the script in groovy console i get the following error:


1 compilation error:

expecting EOF, found 'http://filebot.sf.net/scripts/artwork.tvdb.groovy' at line: 1, column: 17


Could you please help?

Thanks
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: HELP - Filebot Groovy Script How To?

Post by rednoah »

What you refer to as "code" is a cmdline call. A call for filebot to run the given script. You seem to be confused between Windows batch script and groovy script. It's like this. Windows cmd runs batch scripts which may run filebot which my run filebot groovy scripts.

For basic usage you don't need to download anything. FileBot can run script given via remote URL like in the example you have given.
:idea: Please read the FAQ and How to Request Help.
Savvy
Posts: 16
Joined: 07 May 2012, 07:42

Re: HELP - Filebot Groovy Script How To?

Post by Savvy »

cool, that makes sense, when i run that command in cmd console it runs fine... So to have a desktop shortcut or setup a scheduled task, all i've done is rename the 'art.groovy' file to 'art.bat' and it works fine. :)

but what about in the scenario where there is no command line, like that of the 'sort download folder' script?

http://filebot.sf.net/scripts/sorty.groovy
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: HELP - Filebot Groovy Script How To?

Post by rednoah »

It's the same. Just didn't add a comment for example usage.

filebot -script "/path/to/script.groovy"

sorty.groovy you probably wanna download and adjust to your needs.
:idea: Please read the FAQ and How to Request Help.
Savvy
Posts: 16
Joined: 07 May 2012, 07:42

Re: HELP - Filebot Groovy Script How To?

Post by Savvy »

all makes sense now... more errors though :(

CMD processes the sorty command renames, downloads subs - but then gets:

at Script2.telnet(Script2.groovy:80)
at Script2.telnet(Script2.groovy)
at Script3$_run_closure7.doCall(Script3.groovy:56)
at Script3.run(Script3.groovy:55)
at net.sourceforge.filebot.cli.ScriptShell$1.run(Unknown Source)
at net.sourceforge.filebot.cli.ScriptShell.evaluate(Unknown Source)
at net.sourceforge.filebot.cli.ScriptShell.runScript(Unknown Source)
at net.sourceforge.filebot.cli.ArgumentProcessor.process(Unknown Source)

at net.sourceforge.filebot.Main.main(Unknown Source)
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: HELP - Filebot Groovy Script How To?

Post by rednoah »

You didn't copy the exception message. From the stack trace I can tell its the code for Notifying XBMC. Just delete the telnet call if you don't need it.
:idea: Please read the FAQ and How to Request Help.
RBCC
Posts: 118
Joined: 17 May 2016, 02:23

Re: HELP - Filebot Groovy Script How To?

Post by RBCC »

Can I use groovy code in the gui ?
RBCC
Posts: 118
Joined: 17 May 2016, 02:23

Re: HELP - Filebot Groovy Script How To?

Post by RBCC »

How do I search through a file and find the string, that is needed in the filename? John
RBCC
Posts: 118
Joined: 17 May 2016, 02:23

Re: HELP - Filebot Groovy Script How To?

Post by RBCC »

How do I open a file in groovy,? Code please.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: HELP - Filebot Groovy Script How To?

Post by rednoah »

Yes, you can read files using standard Groovy code within your format code.

FileBot adds additional convenience methods for reading text files into a List<String> or Map<String, String> as follows:

Code: Select all

def list = readLines('/path')

Code: Select all

def map = csv('/path')
:idea: Please read the FAQ and How to Request Help.
Post Reply