Script Troubleshooting

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
edvahass
Posts: 11
Joined: 09 Apr 2012, 12:48

Script Troubleshooting

Post by edvahass »

I'm attempting to make FileBot search a folder on my Mac with both TV shows and Movies, find subtitles and rename them, and then move them into separate folders for shows and movies and delete the old files. I've already created an automator script that copies all finished utorrent files into this folder so that it can keep seeding even though I rename the files (old files remain in another folder). This is my script.

Code: Select all

//// filebot -script "path to local script" -trust-script <folder/with/files> [-non-strict]

// PERSONALIZED SETTINGS
def episodeFormat = "/Users/myname/Movies/Movies/TV/{n}{'/Season '+s}/{episode}"
def movieFormat   = "/Users/myname/Movies/Movies/Movies/{movie}/{movie}"


def groups = args.getFiles().groupBy{
	def tvs = detectSeriesName(it)
	def mov = detectMovie(it, false)
	println "$it.name [series: $tvs, movie: $mov]"
	
	// DECIDE EPISODE VS MOVIE (IF NOT CLEAR)
	if (tvs && mov) {
		if (it.name =~ "(?i:$tvs - .+)" || parseEpisodeNumber(it.name) || parseDate(it.name)) {
			println "Exclude Movie: $mov"
			mov = null
		} else if (detectMovie(it, true)) {
			println "Exclude Series: $tvs"
			tvs = null
		}
	}
	return [tvs:tvs, mov:mov]
}

groups.each{ group, files ->
	// EPISODE MODE
	if (group.tvs && !group.mov) {
	
		// fetch subtitles
		files += getSubtitles(file:files)
		
		// sort subs and episodes
		return rename(file:files, db:'TVRage', format:'format:episodeFormat')
	}
	// MOVIE MODE
	if (group.mov && !group.tvs) {
	
		// fetch subtitles
		files += getSubtitles(file:files)
		
		// sort subs and movies
		return rename(file:files, db:'TheMovieDB', format: 'format:movieFormat')
	}
}
Now when I execute the script in Terminal I get the following errors:

Code: Select all

Apr 09, 2012 2:43:32 PM com.dmurph.tracking.JGoogleAnalyticsTracker dispatchRequest
SEVERE: Error making tracking request
java.net.UnknownHostException: www.google-analytics.com
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
	at java.net.Socket.connect(Socket.java:578)
	at java.net.Socket.connect(Socket.java:527)
	at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:378)
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:473)
	at sun.net.www.http.HttpClient.<init>(HttpClient.java:203)
	at sun.net.www.http.HttpClient.New(HttpClient.java:290)
	at sun.net.www.http.HttpClient.New(HttpClient.java:306)
	at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:997)
	at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:976)
	at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:851)
	at com.dmurph.tracking.JGoogleAnalyticsTracker.dispatchRequest(Unknown Source)
	at com.dmurph.tracking.JGoogleAnalyticsTracker.access$100(Unknown Source)
	at com.dmurph.tracking.JGoogleAnalyticsTracker$2.run(Unknown Source)

Apr 09, 2012 2:43:32 PM com.dmurph.tracking.JGoogleAnalyticsTracker dispatchRequest
SEVERE: Error making tracking request
java.net.UnknownHostException: www.google-analytics.com
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
	at java.net.Socket.connect(Socket.java:578)
	at java.net.Socket.connect(Socket.java:527)
	at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:378)
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:473)
	at sun.net.www.http.HttpClient.<init>(HttpClient.java:203)
	at sun.net.www.http.HttpClient.New(HttpClient.java:290)
	at sun.net.www.http.HttpClient.New(HttpClient.java:306)
	at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:997)
	at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:976)
	at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:851)
	at com.dmurph.tracking.JGoogleAnalyticsTracker.dispatchRequest(Unknown Source)
	at com.dmurph.tracking.JGoogleAnalyticsTracker.access$100(Unknown Source)
	at com.dmurph.tracking.JGoogleAnalyticsTracker$2.run(Unknown Source)
I'm not a very experienced coder, and I'd be fantastic if someone could help me out with this.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Script Troubleshooting

Post by rednoah »

That's just logging, use -no-analytics if it bothers you. Apart from that it should work though.
: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: Script Troubleshooting

Post by rednoah »

Actually there is a copy&paste problem:

format: 'format:movieFormat'

Should be format:movieFormat or format:'{movie}'
: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: Script Troubleshooting

Post by rednoah »

edvahass wrote:I've already created an automator script that copies all finished utorrent files into this folder so that it can keep seeding even though I rename the files (old files remain in another folder).
This option might be useful to you:
--action move | copy | keeplink | symlink | hardlink
:idea: Please read the FAQ and How to Request Help.
edvahass
Posts: 11
Joined: 09 Apr 2012, 12:48

Re: Script Troubleshooting

Post by edvahass »

So instead of having two separate versions of the file I can symlink? Utorrent has to keep the old filenames, is this possible?
edvahass
Posts: 11
Joined: 09 Apr 2012, 12:48

Re: Script Troubleshooting

Post by edvahass »

Still no luck on the script. It neither moves files nor names them. Just to make sure I've understood this right:
in
//// filebot -script "path to local script" -trust-script <folder/with/files> [-non-strict]
the <folder/with/files> is the location of where the files i want to name are located (the location of where the script should run?)

EDIT: if I cd into the directory with my movies, all it does is create a file named [-non-strict].
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Script Troubleshooting

Post by rednoah »

You run it like this:

Code: Select all

filebot -script "D:/path/to/my/script.groovy" -trust-script -non-strict "D:/input/folder"
--action copy|keeplink|symlink|hardlink all allow you to keep seeding. keeplink moves the files but then puts a symbolic link at the old location. symlink puts a symbolic link to the new location and doesn't touch the original. hardlink is like the same physical file existing in two folders.
:idea: Please read the FAQ and How to Request Help.
edvahass
Posts: 11
Joined: 09 Apr 2012, 12:48

Re: Script Troubleshooting

Post by edvahass »

It runs! I was just running the script wrong. However, when I try --action hardlink it everything seems fine, until:

Code: Select all

Auto-detected query: [Futurama]
Fetching episode data for [Futurama]
Exception: Unsupported Operation: move, createLink
Done ?(?????)?
--action copy works, but not --action keeplink|symlink|hardlink. They all return either
Exception: Unsupported Operation: move, createLink
or
Exception: Unsupported Operation: move, createSymbolicLink
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Script Troubleshooting

Post by rednoah »

You'll need Java 7 for that. Also on Windows you may need to run it with priviledges to allow the process to create symbolic and hard links.
:idea: Please read the FAQ and How to Request Help.
edvahass
Posts: 11
Joined: 09 Apr 2012, 12:48

Re: Script Troubleshooting

Post by edvahass »

I just found that out, thanks. Java 6 is the only version officially available for mac, so I had to use this: http://code.google.com/p/openjdk-osx-build/
It's an OpenJDK port for Mac OS X, since apple seems a bit slow on the hardware front.
Also if anyone is interested here is my finished script:

Code: Select all

//// filebot -script "/path/to/script.groovy" -trust-script -non-strict --action hardlink /path/to/folder/with/files/

// PERSONALIZED SETTINGS
def episodeFormat = "/path/to/where/the/episodes/should/go/{n}{'/Season '+s}/{episode}"
def movieFormat   = "/path/to/where/the/movies/should/go/{movie}/{movie}"
def namingDir     = "/path/to/folder/with/files/again/"
// ignore chunk, part, par and hidden files
def incomplete(f) { f.name =~ /[.]incomplete|[.]chunk|[.]par$|[.]dat$/ || f.isHidden() }

// extract completed multi-volume rar files
[namingDir].getFolders{ !it.hasFile{ incomplete(it) } && it.hasFile{ it =~ /[.]rar$/ } }.each{ dir ->
	// extract all archives found in this folder
	def paths = extract(folder:dir)
}

def groups = args.getFiles().groupBy{
	def tvs = detectSeriesName(it)
	def mov = detectMovie(it, false)
	println "$it.name [series: $tvs, movie: $mov]"
	
	// DECIDE EPISODE VS MOVIE (IF NOT CLEAR)
	if (tvs && mov) {
		if (it.name =~ "(?i:$tvs - .+)" || parseEpisodeNumber(it.name) || parseDate(it.name)) {
			println "Exclude Movie: $mov"
			mov = null
		} else if (detectMovie(it, true)) {
			println "Exclude Series: $tvs"
			tvs = null
		}
	}
	return [tvs:tvs, mov:mov]
}

groups.each{ group, files ->
	// EPISODE MODE
	if (group.tvs && !group.mov) {
	
		// fetch subtitles
		files += getSubtitles(file:files)
		
		// sort subs and episodes
		return rename(file:files, db:'TVRage', format:episodeFormat)
	}

	// MOVIE MODE
	if (group.mov && !group.tvs) {
	
		// sort subs and movies
		return rename(file:files, db:'TheMovieDB', format:movieFormat)
	}
}

1. Unrar any archives
2. Decide if TV show or movie
3. Fetch subs, rename and hardlink to specified folders (I couldn't seem to get sub fetching to work for movies, it crashed the script so I removed it.)

Thanks for the help, this is immensely useful to me. Hardlinks are fantastic (and this software is amazing! I even learnt some things from it ;D)
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Script Troubleshooting

Post by rednoah »

Cool! Nice to see people actually grabbing stuff from my examples and putting it together for their needs. :)

About subs, I guess this might be the problem:
getSubtitles() can't crash the script, but then if that call fails there is no return value so files += null fails of course.

Grab subtitles like this:
def subs = getSubtitles()
if (subs) files += subs

What's the output when fetching subs crashes the script?
:idea: Please read the FAQ and How to Request Help.
edvahass
Posts: 11
Joined: 09 Apr 2012, 12:48

Re: Script Troubleshooting

Post by edvahass »

Well it renames the TV shows correctly but returns this on the movie:

Code: Select all

Looking up subtitles by filehash via OpenSubtitles
Looking up subtitles by filehash via Sublight
Exception: Failed to auto-detect query
NullPointerException: null
Done ヾ(@⌒ー⌒@)ノ
That's when I use this to fetch the subtitles:

Code: Select all

      files += getSubtitles(file:files)
If i replace that with what you said

Code: Select all

def subs = getSubtitles()
if (subs) files += subs
Then it returns this

Code: Select all

NullPointerException: java.lang.NullPointerException
java.lang.NullPointerException
	at Script2._defaults(Script2.groovy:259)
	at Script2$_defaults.callCurrent(Unknown Source)
	at Script2$_defaults.callCurrent(Unknown Source)
	at Script2.getSubtitles(Script2.groovy:194)
	at Script3$_run_closure4.doCall(Script3.groovy:49)
	at Script3.run(Script3.groovy:34)
	at net.sourceforge.filebot.cli.ScriptShell.evaluate(Unknown Source)
	at net.sourceforge.filebot.cli.ScriptShell.run(Unknown Source)
	at net.sourceforge.filebot.cli.ScriptShell.run(Unknown Source)
	at net.sourceforge.filebot.cli.ArgumentProcessor.process(Unknown Source)
	at net.sourceforge.filebot.Main.main(Unknown Source)
Failure (°_°)
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Script Troubleshooting

Post by rednoah »

That was just a sample, you still have to pass the file parameter.

getSubtitles(file:files)
:idea: Please read the FAQ and How to Request Help.
edvahass
Posts: 11
Joined: 09 Apr 2012, 12:48

Re: Script Troubleshooting

Post by edvahass »

I still don't understand quite how to implement this. I'm not very good at codes.

By the way, thanks for your patience ;)
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Script Troubleshooting

Post by rednoah »

def subs = getSubtitles(file:files)
if (subs) files += subs
:idea: Please read the FAQ and How to Request Help.
edvahass
Posts: 11
Joined: 09 Apr 2012, 12:48

Re: Script Troubleshooting

Post by edvahass »

That did it! Thanks for your help. :D
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Script Troubleshooting

Post by rednoah »

Please test your script for a while and see if it works without any unexpected problems. If it runs fine please what you're using so other can just copy & paste.
:idea: Please read the FAQ and How to Request Help.
edvahass
Posts: 11
Joined: 09 Apr 2012, 12:48

Re: Script Troubleshooting

Post by edvahass »

Here it is:

Code: Select all

//// filebot -script "path/to/script.groovy" -trust-script -non-strict --action hardlink path/to/files 

// PERSONALIZED SETTINGS
def episodeFormat = "path/to/where/the/episodes/should/go/{n}{'/Season '+s}/{episode}"
def movieFormat   = "path/to/where/the/movies/should/go/{movie}/{movie}"

// ignore chunk, part, par and hidden files
def incomplete(f) { f.name =~ /[.]incomplete|[.]chunk|[.]par$|[.]dat$/ || f.isHidden() }

// extract completed multi-volume rar files
args.getFolders{ !it.hasFile{ incomplete(it) } && it.hasFile{ it =~ /[.]rar$/ } }.each{ dir ->
	// extract all archives found in this folder
	def paths = extract(folder:dir)
}

def groups = args.getFiles().groupBy{
	def tvs = detectSeriesName(it)
	def mov = detectMovie(it, false)
	println "$it.name [series: $tvs, movie: $mov]"
	
	// DECIDE EPISODE VS MOVIE (IF NOT CLEAR)
	if (tvs && mov) {
		if (it.name =~ "(?i:$tvs - .+)" || parseEpisodeNumber(it.name) || parseDate(it.name)) {
			println "Exclude Movie: $mov"
			mov = null
		} else if (detectMovie(it, true)) {
			println "Exclude Series: $tvs"
			tvs = null
		}
	}
	return [tvs:tvs, mov:mov]
}

groups.each{ group, files ->
	// EPISODE MODE
	if (group.tvs && !group.mov) {
	
		// fetch subtitles
		def subs = getSubtitles(file:files)
		if (subs) files += subs
		
		// sort subs and episodes
		return rename(file:files, db:'TVRage', format:episodeFormat)
	}

	// MOVIE MODE
	if (group.mov && !group.tvs) {
	
    	// fetch subtitles
		def subs = getSubtitles(file:files)
		if (subs) files += subs

		// sort subs and movies
		return rename(file:files, db:'TheMovieDB', format:movieFormat)
	}
}
verysofttoiletpaper
Posts: 141
Joined: 05 Jul 2012, 09:44

Re: Script Troubleshooting

Post by verysofttoiletpaper »

Any updates to this script?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Script Troubleshooting

Post by rednoah »

This thread is pretty much obsolete since the new µTorrent Integration script is doing that and more:
http://filebot.sourceforge.net/forums/v ... 4&t=5#p802
:idea: Please read the FAQ and How to Request Help.
Post Reply