Page 1 of 1

Creating folder structure from first letter in movie/tv

Posted: 14 Apr 2014, 19:12
by HtRabbit
I have been using the following code in the GUI to Create folder structure from first letter in movie/tv

Code: Select all

t:\new\TV\{n =~ /^(?i)[a-z]/ ? n.replaceFirst(/^(?i)(The|A)\s(.+)/, /$2, $1/).getAt(0) : '0-9'}\{n.replaceAll(/[(]/,"[").replaceAll(/[)]/,"]")}\Season {s}\{n.replaceAll(/[(]/,"[").replaceAll(/[)]/,"]")} - {s00e00} - {t.replaceAll(/[(]/,"[").replaceAll(/[)]/,"]")}
remove the word 'The' and trailing space
get the first character
if it is a letter use it
else - put it in a folder '0-9'

the script has been working fine for the most part except every once and a while it wants to create a '1' or a '4' folder etc...
it seems to happen if there is a 'The ' striped away.
Image

I would also like to know where i can get some documentation on the commands/syntax available for the GUI as i have been guessing at the code and don't really know the parameters for the commands.
:P thanx in advance.

Re: Creating folder structure from first letter in movie/tv

Posted: 15 Apr 2014, 04:48
by rednoah
1.
All the code is standard Groovy code, and all the extra variables can be inspected by clicking (x)= button in the Format Editor window.

2.
n =~ /^(?i)[a-z]/ means if there is any letter in the name then, since The 4400 contains a letter it'll use the charAt(0) code.

I would do this:

Code: Select all

{n0 = n.sortName().charAt(0); n0.isDigit() ? '0-9' : n0}

Re: Creating folder structure from first letter in movie/tv

Posted: 15 Apr 2014, 19:08
by HtRabbit
rednoah wrote:1.
All the code is standard Groovy code, and all the extra variables can be inspected by clicking (x)= button in the Format Editor window.

2.
n =~ /^(?i)[a-z]/ means if there is any letter in the name then, since The 4400 contains a letter it'll use the charAt(0) code.

I would do this:

Code: Select all

{n0 = n.sortName().charAt(0); n0.isDigit() ? '0-9' : n0}
:D This is Awesome! :D
Thank-you

so i end up with for TV

Code: Select all

t:\new\TV\{n0 = n.sortName().charAt(0); n0.isDigit() ? '0-9' : n0}\{n.replaceAll(/[(]/,"[").replaceAll(/[)]/,"]")replaceAll(/[`´‘’ʻ:]/,"")}\Season {s}\{n.replaceAll(/[(]/,"[").replaceAll(/[)]/,"]").replaceAll(/[`´‘’ʻ:]/,"")} - {s00e00} - {t.replaceAll(/[(]/,"[").replaceAll(/[)]/,"]").replaceAll(/[`´‘’ʻ:]/,"")}{if (ext =~ /watched/)'.'+fn.match(/\.(avi|mkv|mp4|mov)$/)}{if (ext =~ /jpg/)'.'+fn.match(/(banner|videoimage|wide|fanart)$/)}
And for Movies

Code: Select all

t:\new\Movies\{n0 = n.sortName().charAt(0); n0.isDigit() ? '0-9' : n0}\{n} [{y}]\{n} [{y}] [ID IMDB tt{imdb.imdbid}]{fn.contains('trl') || fn.contains('Trailer')|| fn.contains('trailer') ? '.'+'[Trailer-'+ resolution +']':""}{if (ext =~ /watched/)'.'+fn.match(/\.(avi|mkv|mp4|mov)$/)}{if (ext =~ /jpg/)'.'+fn.match(/(banner|videoimage|wide|fanart)$/)}
Thank-you

did i mention

:D This is Awesome! :D

Re: Creating folder structure from first letter in movie/tv

Posted: 26 Jan 2016, 09:54
by asc3nti0n
I want a folder structure having the single-letter beginning, but prefer to browse by collection, when collection exists.
I'm using Infuse Pro on tvOS, and browsing the NAS via SMB is slow enough without my old structure being folderless (all 2500 movies, in a single folder "Movies").
I'm using MacOS to run filebot, way quicker than Filebot trying to run on the QNAP CLI.

I'm using (different/similar versions used in CLI and GUI each work, CLI shown):

Code: Select all

"movieFormat=/Volumes/Multimedia/Movies/{n00 = n.sortName().charAt(0); n00.isDigit() ? '0-9' : n00}/{collection+'/'}{n} ({y}) {'['pi+'of'+pn']'} _{certification}_ star-{rating}"
Two problems:
A) The "Fast and the Furious" collection is spread out under "0-9", "T" and "F" folders, then Collection
b) "The" exists in the resultant of either/both of {n} and {collection}.

How do I modify the statement which simply selects the first letter of the Movie name:

Code: Select all

{n00 = n.sortName().charAt(0); n00.isDigit() ? '0-9' : n00}
Such that the outputs from each of following results in the Quoted output:

Fast & Furious (2009) _PG-13_ star-6.3.avi
F/The\ Fast\ and\ the\ Furious\ Collection/Fast & Furious (2009) _PG-13_ star-6.3.avi
2 Fast 2 Furious (2003) _PG-13_ star-6.1.avi
F/The\ Fast\ and\ the\ Furious\ Collection/2\ Fast\ 2\ Furious\ \(2003\)\ _PG-13_\ star-6.1.avi
The Fast and the Furious Tokyo Drift (2006) _PG-13_ CD1 star-6.1.avi
F/The\ Fast\ and\ the\ Furious\ Collection/The Fast and the Furious Tokyo Drift (2006) _PG-13_ CD1 star-6.1.avi
The Curious Case of Benjamin Button (2008) _PG-13_ star-6.9.avi
C/The Curious Case of Benjamin Button (2008) _PG-13_ star-6.9.avi
Inglourious Basterds (2009) _R_ star-7.4.avi
I/Inglourious Basterds (2009) _R_ star-7.4.avi
I imagine that the single-letter n00 statement can decide if {collection}=null, choose {n}, but remove the "The" from the resultant as well has me getting syntax errors all over the place. And trolling everyone's wonderful Movies filename expressions while interesting, finding the ones that have single-letter folder structures is hard.

Re: Creating folder structure from first letter in movie/tv

Posted: 26 Jan 2016, 10:45
by rednoah
Probably like this:

Code: Select all

{def n0 = any{collection}{n}.sortName().charAt(0); n0.isDigit() ? '0-9' : n0}
@see viewtopic.php?f=5&t=1895

Re: Creating folder structure from first letter in movie/tv

Posted: 26 Jan 2016, 11:30
by rednoah
r3464 adds {az} binding as well as String.sortInitial() function.

Re: Creating folder structure from first letter in movie/tv

Posted: 26 Jan 2016, 12:22
by Ztrust
I use a rather lenghty format to sort into ABCD folders instead

Code: Select all

n.replaceFirst(/^(?i)(The)\s(.+)/, /$2, $1/)[0] =~ /^(?i)[q-t]/ ? 'Movies/QRST' : n.replaceFirst(/^(?i)(The)\s(.+)/, /$2, $1/)[0] =~ /^(?i)[u-å]/ ? 'Movies/UVWYXZ' : '#'}
but never managed to get the collection to sort to the collection name!
can this be modified to ABCD/EFGH folders ? its somewhat shorter and collection sorts the right way
Ztrust

Re: Creating folder structure from first letter in movie/tv

Posted: 26 Jan 2016, 16:27
by rednoah
Replace n with any{collection}{n} as shown in my example above.

Re: Creating folder structure from first letter in movie/tv

Posted: 27 Jan 2016, 10:54
by Ztrust
will give it another go thank you

Re: Creating folder structure from first letter in movie/tv

Posted: 02 Feb 2016, 09:10
by asc3nti0n
rednoah wrote:Probably like this:

Code: Select all

{def n0 = any{collection}{n}.sortName().charAt(0); n0.isDigit() ? '0-9' : n0}
Works a treat (of course) I hadn't noticed the 'any' switch statement in use anywhere around the samples in the forums, Thanks! It had to be simple, and it is. isn't it wonderful when code just shows you what its good at.

Re: Creating folder structure from first letter in movie/tv

Posted: 25 Apr 2021, 14:56
by Karpik
Just dropping by to say 'thanks' for previous answers that helped me find the solution. <3