Some help with my script

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
saitoh183
Posts: 112
Joined: 02 Oct 2012, 16:59

Some help with my script

Post by saitoh183 »

Hi,

So i modified the sorty script to fit my setup and it seems to work fine..it renames, moves my files and updates XBMC. No the only thing missing is cleaning up any clutter left over in my download directory and delete the folder containing the clutter. I was looking at the Cleaner script but im unclear on how i can add it to my script and hardcode the directory i want it to check for clutter. What i would like is to ether ignore the clutter first, transfer the movie and then delete everything that is left including the directory or delete the clutter right away, transfer the movie and delete the folder. Here is my script if it can help:

Code: Select all

// PERSONALIZED SETTINGS
def movieDir      = "I:/test3"
def movieFormat   = "D:/Videos/Movies/{movie}/{movie}"

// XBMC ON LOCAL MACHINE 
def xbmc = ['htpc-saitoh'] // (use [] to not notify any XBMC instances about updates)
/*
 * Sort into folders
 */
movieDir.getFolders{ it.hasFile{ it.isVideo() } }.each{ dir ->
	println "Processing $dir"
	def files = dir.listFiles{ it.isVideo() }
	
	// sort movies 
	def paths = '/' + rename(file:files, db:'imdb', format:movieFormat) + '/'
	def Film = paths.split("\\\\")
	println Film + "this is Film Value"
	println Film[3] + "This is Film Array value"
	def fullpath = 'smb://SRV-saitoh/videos/Movies/' + Film[3]
	xbmc.each { host ->
	telnet(host, 9090) { writer, reader ->
		// API call for latest XBMC release
		def msg = '{"id":1,"jsonrpc":"2.0","method":"VideoLibrary.Scan","params":{"directory":"'+ fullpath +'/"}}'
		println(msg)		
		writer.println(msg)
		}
	}
}	
Thanks
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Some help with my script

Post by rednoah »

Why not simply have a batch script that'll call your script and then the cleaner?

Though you can call the cleaner directly from your script as well like this:

Code: Select all

include('fn:cleaner', [:], ['path/to/folder' as File])
:idea: Please read the FAQ and How to Request Help.
saitoh183
Posts: 112
Joined: 02 Oct 2012, 16:59

Re: Some help with my script

Post by saitoh183 »

rednoah wrote:Why not simply have a batch script that'll call your script and then the cleaner?

Though you can call the cleaner directly from your script as well like this:

Code: Select all

include('fn:cleaner', [:], ['path/to/folder' as File])
Humm interesting :)..if i add it to my script i would put it at the end i guess? Also what does the "as File" part do or mean?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Some help with my script

Post by rednoah »

Kinda like a better type cast. Don't you have that in the .NET world as well?
http://stackoverflow.com/questions/1275 ... conversion

Actually you can pass in Strings as well. I'll cast to File anyway:

Code: Select all

def include(String input, Map bindings = [:], Object... args) {
	// initialize default parameter
	bindings.args = (args as List).flatten().findResults{ it as File }
	
	// run given script and catch exceptions
	_guarded { _shell.runScript(input, new javax.script.SimpleBindings(bindings)) }
}
def include(input, bindings, args)
@input ... script uri like cmdline -script uri does
@bindings ... pass in variables like cmdline --def x=y does
@args ... file arguments like passing in extra (non-option) arguments via cmdline
:idea: Please read the FAQ and How to Request Help.
saitoh183
Posts: 112
Joined: 02 Oct 2012, 16:59

Re: Some help with my script

Post by saitoh183 »

Im fine with using just the Cleaner script as a include if it can do what i ask in the OP

***Edit***

Thanks for the help the include statement worked like a charm :)
saitoh183
Posts: 112
Joined: 02 Oct 2012, 16:59

Re: Some help with my script

Post by saitoh183 »

I lost my server, so i had to rewrite my script from this post. I noticed that the cleaner part of the script deletes the parent folder. How do I fix it?

def movieDir = "I:/test3"

Movies are put into I:/test3/test/movie.mkv

Once the cleaner is done, it deletes test3 folder.

Code: Select all

C:\Program Files (x86)\SABnzbd>filebot -script I:\Scripts\Filebot\movie_process.groovy -non-strict 
Processing I:\Download_area\Download_movies\Parker.2013.720p.BluRay.x264-iNFAMOUS
Rename movies using [IMDb]
[MOVE] Rename [I:\Download_area\Download_movies\Parker.2013.720p.BluRay.x264-iNFAMOUS\parker.2013.720p.bluray.x264-infamous.mkv] to [D:\Videos\Movies\Parker (2013)\Parker (2013).mkv]
Processed 1 files
Delete I:\Download_area\Download_movies\Parker.2013.720p.BluRay.x264-iNFAMOUS\parker.2013.720p.bluray.x264-infamous-proof.jpg
Delete I:\Download_area\Download_movies\Parker.2013.720p.BluRay.x264-iNFAMOUS\parker.2013.720p.bluray.x264-infamous.nfo
Delete I:\Download_area\Download_movies\Parker.2013.720p.BluRay.x264-iNFAMOUS\parker.2013.720p.bluray.x264-infamous.sfv
Delete I:\Download_area\Download_movies\Parker.2013.720p.BluRay.x264-iNFAMOUS
Delete I:\Download_area\Download_movies
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Some help with my script

Post by rednoah »

That's how it's supposed to work. Either modify cleaner.groovy or call it on subfolders.

On the cmdline this would probably work:

Code: Select all

filebot -script fn:cleaner I:/test3/*
In groovy code you have to call it per folder yourself.
:idea: Please read the FAQ and How to Request Help.
saitoh183
Posts: 112
Joined: 02 Oct 2012, 16:59

Re: Some help with my script

Post by saitoh183 »

Ok will try it out. But why would people what to delete there Parent folder as well. If people want to clean it would be the content of there folder without deleting the parent folder that they always use.

So i would have to put

Code: Select all

include('fn:cleaner', [:], [movieDir]'/*') 
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Some help with my script

Post by rednoah »

Changed the default behaviour to not delete the folders passed in via arguments. Commited with r1624.
:idea: Please read the FAQ and How to Request Help.
saitoh183
Posts: 112
Joined: 02 Oct 2012, 16:59

Re: Some help with my script

Post by saitoh183 »

Thanks, will the new commit be merged to http://filebot.net/scripts/ ?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Some help with my script

Post by rednoah »

Updated /scripts as well. Try again tomorrow and it should auto-update.
:idea: Please read the FAQ and How to Request Help.
saitoh183
Posts: 112
Joined: 02 Oct 2012, 16:59

Re: Some help with my script

Post by saitoh183 »

Hi rednoah,

My script is working great except it seems that the XBMC updating has stopped working.

this is what i have in my script:

Code: Select all

xbmc.each { host ->
   telnet(host, 9090) { writer, reader ->
      // API call for latest XBMC release
      def msg = '{"id":1,"jsonrpc":"2.0","method":"VideoLibrary.Scan","params":{"directory":"'+ fullpath +'/"}}'
and this is the output in the xbmc.log:

Code: Select all

15:57:54 T:11020   DEBUG: JSONRPC Server: New connection detected
15:57:54 T:11020    INFO: JSONRPC Server: New connection added
15:57:54 T:11020    INFO: JSONRPC Server: Disconnection detected
I tired via putty and i can communicate over 9090

Code: Select all

=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2013.05.15 16:43:42 =~=~=~=~=~=~=~=~=~=~=~=
{"jsonrpc": "2.0", "method": "JSONRPC.Version", "id": 1}
{"id":1,"jsonrpc":"2.0","result":{"version":{"major":6,"minor":0,"patch":3}}}
XBMC.log

Code: Select all

16:44:01 T:1720   DEBUG: JSONRPC Server: New connection detected
16:44:01 T:1720    INFO: JSONRPC Server: New connection added
16:44:01 T:1720   DEBUG: JSONRPC: Incoming request: {"jsonrpc": "2.0", "method": "JSONRPC.Version", "id": 1}
16:44:01 T:1720   DEBUG: JSONRPC: Calling jsonrpc.version
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Some help with my script

Post by rednoah »

So from log it seems it's not reading any incoming request? I assume after you do def msg = ... there'll be a writer.println(msg) later as well sending that call?

Just make a test script and play with telnet(host, 9090) { ... } and let me know what command to send to XBMC so it works.
:idea: Please read the FAQ and How to Request Help.
saitoh183
Posts: 112
Joined: 02 Oct 2012, 16:59

Re: Some help with my script

Post by saitoh183 »

rednoah wrote:So from log it seems it's not reading any incoming request? I assume after you do def msg = ... there'll be a writer.println(msg) later as well sending that call?

Just make a test script and play with telnet(host, 9090) { ... } and let me know what command to send to XBMC so it works.

i will hide in a corner now...I dont know why but it was commented out...writer.println(msg)...fail...i didnt notice till i turned on language in the editor to see what was commented out...
Post Reply