Release Group information out of Foldername

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
cheesemaker
Posts: 49
Joined: 03 Sep 2012, 10:52

Release Group information out of Foldername

Post by cheesemaker »

Hello there,

To sort in my downloaded media files, I use the "sortivo.groovy" script. Here's the code:

Code: Select all

// filebot -script fn:sortivo <folder> --output path/to/folder [-non-strict]

// process only media files
def input = args.getFiles{ it.isVideo() || it.isSubtitle() }

// ignore clutter files
input = input.findAll{ !(it.path =~ /\b(?i:sample|trailer|extras|deleted.scenes|music.video|scrapbook)\b/) }

// print input fileset
input.each{ println "Input: $it" }

/*
 * Move/Rename a mix of episodes and movies that are all in the same folder.
 */
def groups = input.groupBy{ f ->
	def tvs = detectSeriesName(f)
	def mov = (parseEpisodeNumber(f) || parseDate(f)) ? null : detectMovie(f, false) // skip movie detection if we can already tell it's an episode
	println "$f.name [series: $tvs, movie: $mov]"
	
	// DECIDE EPISODE VS MOVIE (IF NOT CLEAR)
	if (tvs && mov) {
		def norm = { s -> s.lower().space(' ') }
		def fn = norm(f.nameWithoutExtension)
		def sn = norm(tvs)
		def mn = norm(mov.name)
		
		// S00E00 | 2012.07.21 | One Piece 217 | Firefly - Serenity | [Taken 1, Taken 2, Taken 3, Taken 4, ..., Taken 10]
		if (parseEpisodeNumber(fn, true) || parseDate(fn) || (fn =~ sn && parseEpisodeNumber(fn.after(sn), false)) || fn.after(sn) =~ / - .+/ || f.dir.listFiles{ it.isVideo() && norm(it.name) =~ sn && it.name =~ /\b\d{1,3}\b/}.size() >= 10) {
			println "Exclude Movie: $mov"
			mov = null
		} else if ((detectMovie(f, true) && fn =~ /(19|20)\d{2}/) || (fn =~ mn && !(fn.after(mn) =~ /\b\d{1,3}\b/))) {
			println "Exclude Series: $tvs"
			tvs = null
		}
	}
	
	return [tvs:tvs, mov:mov]
}

groups.each{ group, files ->
	// EPISODE MODE
	if (group.tvs && !group.mov) {
		rename(file:files, format:'/media/Mediathek/Serien/{n}/{episode.special ? "Special" : "Season "+s}/{n} - {episode.special ? "S00E"+special.pad(2) : s00e00} - {t}', db:'TheTVDB')
	}
	
	// MOVIE MODE
	if (group.mov && !group.tvs) {
		rename(file:files, format:"/media/Mediathek/Filme/{n.upperInitial().space('.')}.{y}/{n.upperInitial().space('.')}.{y}.{ac}.{vc}-{group}", db:'TheMovieDB')
	}
}
The problem is, I want to have the name of the releasegroup in the filename. For Example "Tuerkisch.fuer.Anfaenger.2012.DTS.1080p.BluRay.x264-DETAiLS". But my file structure looks like this:

Code: Select all

[Tuerkisch.fuer.Anfaenger.2012.German.1080p.BluRay.x264-DETAiLS
        ├── d-tfanfaenger-1080p.nfo
        ├── d-tfanfaenger-1080p.mkv
        ├── d-tfanfaenger-1080p.sfv
        ├── Sample
        │   └── d-tfanfaenger-1080p-sample.mkv
        └── Subs
            ├── d-tfanfaenger-1080p-subs.rar
            └── d-tfanfaenger-1080p-subs.sfv
And when I run the script, it won't recognize the release-group because it doesn't refer to the containing foldername, only the file which name is "d-tfanfaenger-1080p.mkv" - which doesn't contain any release group. So the output will be something like this: Tuerkisch.fuer.Anfaenger.2012.DTS.1080p.BluRay.x264-..mkv

Has anybody an idea how to manage this with filebot?
My Solutions - but I don't know how to manage this:
1. Teach sortivo.groovy to take the releasename out of the containing folder
2. Before running script, rename all files to foldername.ext (With bash? But how?)

Code: Select all

[Tuerkisch.fuer.Anfaenger.2012.German.1080p.BluRay.x264-DETAiLS
        ├── Tuerkisch.fuer.Anfaenger.2012.German.1080p.BluRay.x264-DETAiLS.nfo
        ├── Tuerkisch.fuer.Anfaenger.2012.German.1080p.BluRay.x264-DETAiLS.mkv
        ├── Tuerkisch.fuer.Anfaenger.2012.German.1080p.BluRay.x264-DETAiLS.sfv
        ├── Sample
        │   └── Tuerkisch.fuer.Anfaenger.2012.German.1080p.BluRay.x264-DETAiLS.mkv
        └── Subs
            ├── Tuerkisch.fuer.Anfaenger.2012.German.1080p.BluRay.x264-DETAiLS.rar
            └── Tuerkisch.fuer.Anfaenger.2012.German.1080p.BluRay.x264-DETAiLS.sfv
I thank you for your help!
User avatar
rednoah
The Source
Posts: 22995
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Release Group information out of Foldername

Post by rednoah »

{group} evaluates to the last match found in both foldername and filename. Tested with Tuerkisch.fuer.Anfaenger.2012.German.1080p.BluRay.x264-DETAiLS/d-tfanfaenger-1080p.mkv and it works.

fyi if you were gonna batch rename files, you'd use filebot/groovy for that :P
:idea: Please read the FAQ and How to Request Help.
Post Reply