Script to check Hard drive space left.

Running FileBot from the console, Groovy / FileBot scripting, shell scripts, etc
Post Reply
raulm753
Posts: 13
Joined: 30 Apr 2012, 16:47

Script to check Hard drive space left.

Post by raulm753 » 03 Aug 2012, 06:00

Hi

I want to have a script that would check the amount of hard drive space left. if the hard drive space is less then a minimum (50 GB for example), then move the files to a different hard drive.
If possible I want like a list of paths to save movies to. Then the script would cycle through these paths to find hard drive that has enough space and moves the movie to that path.

thank you

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

Re: Script to check Hard drive space left.

Post by rednoah » 03 Aug 2012, 10:29

It's possible and not difficult if you know a bit of Java/Groovy.
:idea: Please read the FAQ and How to Request Help.

raulm753
Posts: 13
Joined: 30 Apr 2012, 16:47

Re: Script to check Hard drive space left.

Post by raulm753 » 03 Aug 2012, 20:01

Any pointers or example? Is groovy java? Can I write java code and the script will run it? I tried to find resources on groovy, but found nothing. I know some C, C++ and python, but i don't know anything about groovy.

raulm753
Posts: 13
Joined: 30 Apr 2012, 16:47

Re: Script to check Hard drive space left.

Post by raulm753 » 03 Aug 2012, 22:48

Found the function that i need to do this but now filebot is not detecting the video files wtf? this is the code

Code: Select all

if (ut_label == "TV") {
	println "TV Processing $ut_dir"

	ut_dir.getFolders{ !it.hasFile{ incomplete(it) } && it.hasFile{ it.isVideo() } }.each{ dir ->
		println "TV Processing $dir"
		def files = dir.listFiles{ it.isVideo() }

		// fetch subtitles
		def substv2 = getSubtitles(file:files)
		if (substv2) {
			files += substv2
		}
	
		// sort episodes in subfolders
		if ((new File(episodeDirList[0]).getUsableSpace()/1024/1024/1024) > MIN_SIZE) {
			rename(file:files, db:'TVRage', format:episodeFormatList[0])
		}
		else if ((new File(episodeDirList[1]).getUsableSpace()/1024/1024/1024) > MIN_SIZE) {
			rename(file:files, db:'TVRage', format:episodeFormatList[1])
		}
		else {
			println "WARNING: No space left!!!!"
		}
		//rename(file:files, db:'TVRage', format:episodeFormat)
	}

}

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

Re: Script to check Hard drive space left.

Post by rednoah » 04 Aug 2012, 03:29

Groovy can do anything you can do with Java but adds lots and lots of nice stuff.

Yeah, that one:
http://docs.oracle.com/javase/7/docs/ap ... pace%28%29

Add more printlns and see what happens. Are you passing ut_label in? If there is no errors logged to console, then you're script is just ignoring things for some reason.
:idea: Please read the FAQ and How to Request Help.

raulm753
Posts: 13
Joined: 30 Apr 2012, 16:47

Re: Script to check Hard drive space left.

Post by raulm753 » 05 Aug 2012, 18:22

Alright so this is the problem. I point Filebot with my script to a folder with TV shows, that Filebot has already processed. It wont process them, it will get to the point where is checking to see if the folder has any video file and exits. I then point the Filebot to a folder with movies, that Filebot has already processed. It will process the movie folder. So may there is a file or something in the TV shows folder that telling Filebot no video or incomplete.
legend of the seeker
Here is the whole script if anyone wants to use. It the utorrent script modified a little bit. If you have multiple harddrives, it can move the files to the drive that has more then a minimum size. I have not added the cleaner scrip yet, as I am afraid of it. Feel free to use it.

Code: Select all

// filebot -script "sorty.groovy" -non-strict -trust-script "-Xut_dir=%D" "-Xut_file=%F" "-Xut_label=%L" "-Xut_state=%S" "-Xut_kind=%K"
// PERSONALIZED SETTINGS
def episodeDirList   = ["G:/Media Files/Completed/TV","I:/Media Files/Completed/TV"]
def episodeFormatList = ["G:/Media Files/TV/{n}/Season {s}/{n} - {s00e00} - {t}","I:/Media Files/TV/{n}/Season {s}/{n} - {s00e00} - {t}"]
def movieDirList      = ["G:/Media Files/Completed/Movies","I:/Media Files/Completed/Movies"]
def movieFormatList   = ["G:/Media Files/Movies/{n} ({y})/{n} ({y})","I:/Media Files/Movies/{n} ({y})/{n} ({y})"]
def animeDirList      = ["G:/Media Files/Completed/Anime","I:/Media Files/Completed/Anime"]
def animeFormatList   = ["G:/Media Files/Anime/{n}/{n} - {e} - {t}","I:/Media Files/Anime/{n}/{n} - {e} - {t}"]
//Min size for harddrive
def MIN_SIZE = 80 

//Testing stuff
//def testarray = [12,34,56,78,89,90]
//print "TESt array=" 
//println testarray[0]
//testfile = new File(ut_dir)
//println "Testing stuff"
//println testfile.getUsableSpace()/1024/1024/1024

// XBMC ON LOCAL MACHINE 
def xbmc = [] // (use [] to not notify any XBMC instances about updates)

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

//subs variable
//def subs = 0

//println "State is $ut_state"

//System.console().readLine "press return"

if ((ut_label == "TV" || ut_label == "Movies" || ut_label == "Anime") && (ut_state == "11")) {
//if ((ut_label == "TV" || ut_label == "Movies") && (ut_state == "11")) {

//Remove Sample Video
if (!new File(ut_dir).hasFile{ incomplete(it) } ) {
	println "Deleting Sample Video Processing $ut_dir"
	def files = new File(ut_dir).listFiles{ it.isVideo() }
	// if name contains "sample" and filesize is less than 20 MB
	//def selection = args.getFiles{ it.name =~ "sample" && it.length() < 20 * 1024 * 1024}
	def selection = new File(ut_dir).getFiles{ (it.name =~ "sample" || it.name =~ "Sample") && it.length() < 150 * 1024 * 1024}
	selection.each{ println "delete $it" }

	// delete all
	selection*.delete()
}

// extract completed multi-volume rar files from subfolders
// extract all archives found in this folder
ut_dir.getFolders{ !it.hasFile{ incomplete(it) } && it.hasFile{ it =~ /[.]rar$/ } }.each{ dir ->
	// extract all archives found in this folder
	def paths = extract(folder:dir, output:ut_dir)
	
	// delete original archive volumes after successful extraction
	if (paths != null && !paths.isEmpty()) {
		dir.listFiles{ it =~ /[.]rar$|[.]r[\d]+$/ }*.delete()
	}
}


// extract completed multi-volume rar files
// extract all archives found in this folder
if (!new File(ut_dir).hasFile{ incomplete(it) } && new File(ut_dir).hasFile{ it =~ /[.]rar$/ }) {
	println "Extracting Video Processing $ut_dir"
	def paths = extract(folder:ut_dir, output:ut_dir)
	
	// delete original archive volumes after successful extraction
	if (paths != null && !paths.isEmpty()) {
		new File(ut_dir).listFiles{ it =~ /[.]rar$|[.]r[\d]+$/ }*.delete()
	}
}

//Remove Sample Video
if (!new File(ut_dir).hasFile{ incomplete(it) } ) {
	println "Deleting Sample Video Processing $ut_dir"
	def files = new File(ut_dir).listFiles{ it.isVideo() }
	// if name contains "sample" and filesize is less than 20 MB
	//def selection = args.getFiles{ it.name =~ "sample" && it.length() < 20 * 1024 * 1024}
	def selection = new File(ut_dir).getFiles{ (it.name =~ "sample" || it.name =~ "Sample") && it.length() < 150 * 1024 * 1024}
	selection.each{ println "delete $it" }

	// delete all
	selection*.delete()
}



//Fetch subtitles and sort into folders
 
//TV
if (ut_label == "TV") {
	println "TV Processing $ut_dir"

	ut_dir.getFolders{ !it.hasFile{ incomplete(it) } && it.hasFile{ it.isVideo() } }.each{ dir ->
		println "TV Processing $dir"
		def files = dir.listFiles{ it.isVideo() }

		// fetch subtitles
		def substv2 = getSubtitles(file:files)
		if (substv2) {
			files += substv2
		}
	
		// sort episodes in subfolders
		if ((new File(episodeDirList[0]).getUsableSpace()/1024/1024/1024) > MIN_SIZE) {
			rename(file:files, db:'TVRage', format:episodeFormatList[0])
		}
		else if ((new File(episodeDirList[1]).getUsableSpace()/1024/1024/1024) > MIN_SIZE) {
			rename(file:files, db:'TVRage', format:episodeFormatList[1])
		}
		else {
			println "WARNING: No space left!!!!"
		}
		//rename(file:files, db:'TVRage', format:episodeFormat)
	}

}

//Movies
if (ut_label == "Movies") {
	//println "Movie Processing $ut_dir"

	ut_dir.getFolders{ !it.hasFile{ incomplete(it) } && it.hasFile{ it.isVideo() } }.each{ dir ->
		println "\r\nMovies Processing $dir\r\n"
		def files = dir.listFiles{ it.isVideo() }
		
		// fetch subtitles
		def subsmovies1 = getSubtitles(file:files)
		if (subsmovies1) {
			files += subsmovies1
		}

		// sort episodes in subfolders
		if ((new File(movieDirList[0]).getUsableSpace()/1024/1024/1024) > MIN_SIZE) {
			rename(file:files, db:'TheMovieDB', format:movieFormatList[0])
		}
		else if ((new File(movieDirList[1]).getUsableSpace()/1024/1024/1024) > MIN_SIZE) {
			rename(file:files, db:'TheMovieDB', format:movieFormatList[1])
		}
		else {
			println "WARNING: No space left!!!!"
		}
		//rename(file:files, db:'TheMovieDB', format:movieFormat)
	}

}

//Anime
if (ut_label == "Anime") {
	println "Anime Processing $ut_dir"

	ut_dir.getFolders{ !it.hasFile{ incomplete(it) } && it.hasFile{ it.isVideo() } }.each{ dir ->
		println "Anime Processing $dir"
		def files = dir.listFiles{ it.isVideo() }

		// fetch subtitles
		def subsanime1 = getSubtitles(file:files)
		if (subsanime1) {
			files += subsanime1
		}
	
		// sort episodes in subfolders
		if ((new File(animeDirList[0]).getUsableSpace()/1024/1024/1024) > MIN_SIZE) {
			rename(file:files, db:'anidb', format:animeFormatList[0])
		}
		else if ((new File(animeDirList[1]).getUsableSpace()/1024/1024/1024) > MIN_SIZE) {
			rename(file:files, db:'anidb', format:animeFormatList[1])
		}
		else {
			println "WARNING: No space left!!!!"
		}
		//rename(file:files, db:'anidb', format:animeFormat)
	}
	
}


}

Post Reply