Board index Scripting and Automation HELP - Filebot Groovy Script How To?

HELP - Filebot Groovy Script How To?

Running FileBot from the console, Groovy / FileBot scripting, shell scripts, etc

rednoah User avatar
The Source

Posts: 2081
Location: 北京

The syntax error is in the format expression. Which causes rename() to fail and return null.
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

rednoah User avatar
The Source

Posts: 2081
Location: 北京

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) }
}
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image


Posts: 169
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-
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-
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')

rednoah User avatar
The Source

Posts: 2081
Location: 北京

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:
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.
format:'''...'''
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image


Posts: 11
thanks rednoah, i'll come back when i've learnt a little more.... cheers


Posts: 169
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.

rednoah User avatar
The Source

Posts: 2081
Location: 北京

Change this from
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
input += new File(ut_dir).getFiles() // multi-file torrent


Actually you could just change the call from
"-Xut_kind=%K"
to
"-Xut_kind=multi"
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image


Posts: 169
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,[path to the folder with the video that was just moved and renamed])

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.

rednoah User avatar
The Source

Posts: 2081
Location: 北京

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
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image


rednoah User avatar
The Source

Posts: 2081
Location: 北京

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.
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

rednoah User avatar
The Source

Posts: 2081
Location: 北京

This should help you get there:
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()
}
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image


Posts: 11
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

rednoah User avatar
The Source

Posts: 2081
Location: 北京

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.
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image


Posts: 11
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

rednoah User avatar
The Source

Posts: 2081
Location: 北京

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.
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image


Posts: 11
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)

rednoah User avatar
The Source

Posts: 2081
Location: 北京

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.
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

Previous

Return to Scripting and Automation