Need some help with scripting

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
Kaero
Posts: 7
Joined: 29 May 2012, 00:09

Need some help with scripting

Post by Kaero »

I've been using Filebot for quite some time to name and organize my anime and tv shows. I recently built myself a HTPC and am looking into making everything as automated as possible so that new episodes are just there in XBMC for me to watch. I don't know how to do scripting or anything so some assistance or a nudge in the right direction :) First I'll explain my set up:

I have two programs (MALUpdater and TorrentEpisodeDownloader) that automatically download new episodes of my shows and place them in two folders:
MALU puts Anime in E:\Download\Anime
TED puts TV Shows in E:\Download\TV Shows

What I want to do is, once the anime finishes downloading to have it given this file name scheme using the aniDB.net scraper:
E:\Video\Anime\Anime Title\Series.Name.S01.E##.Episode.Title.ext
(S01 is static and doesn't change as I use absolute ordering and XBMC requires a season in order for it to detect my anime)

And TV shows are like this using the TVDB scraper:
E:\Video\TV Shows\Series Name\Series Name - @x## - Episode Title.ext (@ = season | ## = episode | ex. 3x15)

What I wish to accomplish is once Utorrent finishes downloading an episode, for it to be renamed and moved to it's proper directory as specified above and for XBMC to detect and add to it's library.

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

Re: Need some help with scripting

Post by rednoah »

The sorty.groovy scripting is doing something like that as one-off script. The there is housekeeping.groovy that'll show you how to monitor folders / run the script every once in a while on given folders. If you need help with utorrent integration the utorrent-postprocess.groovy script can serve as a template.

How does utorrent know if torrent is an anime or tv show torrent? Things need to be customised for your usecase but it should be straight-forward. Mostly copy and paste from the examples.
:idea: Please read the FAQ and How to Request Help.
Kaero
Posts: 7
Joined: 29 May 2012, 00:09

Re: Need some help with scripting

Post by Kaero »

Well, The programs I am using decides where the download ends up, rather than Utorrent. MALUpdater downloads files to E:\Download\Anime and TED downloads files to E:\Download\TV Shows. I'm poking around through some of the scripts now and this is all blowing right past me. I mainly want the script to run from utorrent after a torrent finishes so that it doesn't try and change and move half-downloaded files. If that's not a problem then having the script automatically run every X minutes would work too.

I downloaded Groovy and am fiddling around with some of the example scripts; maybe I'll be able to patch something together if I'm lucky.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Need some help with scripting

Post by rednoah »

You don't need Groovy expect for prototyping some code. FileBot can run groovy scripts out of the box.

Having utorrent kick off filebot is no problem. But since TED is only downloading torrents when utorrent finishes downloading a file how will the script know its anime or tv show? Is it labelled in utorrent?
:idea: Please read the FAQ and How to Request Help.
Kaero
Posts: 7
Joined: 29 May 2012, 00:09

Re: Need some help with scripting

Post by Kaero »

I just assumed that I could set in a script that the files downloaded to the TV Show downloads folder were to use one name format and go to one directory and the files in the Anime downloads folder would use another name format and go to another directory. I modified the sorty.groovy script some to see if I could get it to work but I'm not sure what went awry. I'm doing all the modifications and test running in the Groovy program since it works nice to organize the code.

This is the script I tried executing
http://pastebin.com/sYJaj8y9

and this is the error I got
http://pastebin.com/3cs83DX1
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Need some help with scripting

Post by rednoah »

Yep, that's why the Groovy console only helps you so far. The FileBot scripting environment predefines all the filebot specific stuff as well as lots of extra stuff useful things for these kinds of purposes. Bascally groovy is the language but you still need to run the script with filebot -script.

The predefined stuff can be found in:
ScriptShell.lib.groovy (its in the jar)
:idea: Please read the FAQ and How to Request Help.
Kaero
Posts: 7
Joined: 29 May 2012, 00:09

Re: Need some help with scripting

Post by Kaero »

Yeah, I realized that now. I went into CMD and typed in filebot -script 'myscript.groovy' and it tells me that java is not recognized as an internal or external command which leads me to believe that the java I installed isn't enough to do what I need to do. When I ran just "filebot" in CMD on my laptop, it opened up the filebot program so I'm probably missing something that I am currently trying to figure out what

edit: New computer, guess I didn't add java as an environment variable. Ran the script testing it with an episode of One Piece and it looked to be working until it failed to match file to episode data.

I added -non-strict to the end of the CMD command and it successfully named and moved my One Piece episode. Also worked with a TV episode of Burn Notice.

Thought I was having problems with movie detection but I just had the script looking at the wrong folder.

Thanks so much for the help thus far! Got a working script that throws my files all where they need to be, just gotta set it to be done automatically. Not sure if I want to have it executed through Utorrent after each download finishes or if having it done at a set interval would be best...
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Need some help with scripting

Post by rednoah »

Best solution is probably to kick it off from utorrent and only process the newly downloaded files. The utorrent integration script can serve as an example for that.
:idea: Please read the FAQ and How to Request Help.
Kaero
Posts: 7
Joined: 29 May 2012, 00:09

Re: Need some help with scripting

Post by Kaero »

Hey, back again. I had it working for like a day but now the script just won't execute at all for some reason, it was working fine earlier today.

I run this in the CMD:
filebot -script "C:\Script\XBMC Script.groovy" -non-strict

and I get this back:
Done ?<?????>?

Doesn't even do anything anymore and I haven't modified it at all... any idea whats happening?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Need some help with scripting

Post by rednoah »

It's just not doing anything it seems. There are no errors so the script seems to run and finish normally. Maybe there is nothing to do? Add some println statements for debugging to see what happens and doesn't happen.

There is no file arguments? That's what args variable is for. With that call args would be empty. But if you specify input in your script that nevermind this.
:idea: Please read the FAQ and How to Request Help.
Kaero
Posts: 7
Joined: 29 May 2012, 00:09

Re: Need some help with scripting

Post by Kaero »

I'm not sure what happened. Seems to be working fine again.

One last thing, having a small bit of trouble with Utorrent. It seems that Filebot can't rename and move files if the torrent is still active and seeding in Utorrent. Utorrent doesn't really offer any way of completely stopping a torrent once it's completed so I've just set it to stop seeding the torrent once it reaches 1% which works sometimes, but I think that sometimes the script does it's thing before the torrent can be marked as finished.

Is there any more reliable way of having torrents stop after they complete? Or even some bit of code I could add to the script or the file line that get's it to start on a delay? Like, to wait 10 seconds after the torrent finishes before running?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Need some help with scripting

Post by rednoah »

You can make the script sleep for a few seconds but the best way is using --action copy.
:idea: Please read the FAQ and How to Request Help.
Kaero
Posts: 7
Joined: 29 May 2012, 00:09

Re: Need some help with scripting

Post by Kaero »

And I would just add that to what I have Utorrent running after a torrent? so...

filebot -script "C:\Script\XBMC Script.groovy" -non-strict --action copy

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

Re: Need some help with scripting

Post by rednoah »

Yep that'll work.
:idea: Please read the FAQ and How to Request Help.
Post Reply