Question about movie cd/part numbering

Any questions? Need some help?
Post Reply
Chryses
Posts: 66
Joined: 26 Aug 2012, 19:11

Question about movie cd/part numbering

Post by Chryses »

Hi, I've integrated filebot on my nas, many many time ago, so maybe now with the natural evolution of the code, my "setting" are no more actual and can be "optimized" in other words maybe my code is deprecated!

I've only one question about the auto cd numbering function that filebot has.

Correct me if I wrong, but if I use

Code: Select all

{' CD'+pi}
Filebot recognise automatically the cd numbering and append the cd number. This happen when my file are something like
AAA.CD1.avi
AAA.CD2.avi

Now, for my own personal reason I call filebot automatically on every file that I download :D, so it's quite possible that I download the cd1 at one time and cd2 in a second time, it's also possible that jd2 download first cd2, etc. etc. This situation is also possible if I cron the timing of the execution of Filebot, but this's another and similar story!

Actually my simple solution is that

Code: Select all

{' - '+fn.match(/(?i)cd+[0-9]/).toUpperCase()}{' - '+fn.match(/(?i)cd +[0-9]/).toUpperCase()}
I simply search cd1 or cd 1, sorry I don't know how to make it on a single istance, I don't know very nothing about Groovy!
I've one the problem that sometimes some file are named partA or part1, but only few times.

My real and final question is:
Mine is still the "best" solution that I can use or I can use another and new way to make it more easy? For example if I use {' CD'+pi}, Filebot recognise cd1 part2 etc in different time? or I can only use this when I have the entire set of cd?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Question about movie cd/part numbering

Post by rednoah »

This is pretty much the same:

Code: Select all

{any{'CD'+pi}{fn.match(/CD\W*\d+/).upper()}}
Not much has changed. There's no good one-solution-fits-all way to do this.

The {pi} solution only works if you have all parts the the time of processing, and if you have the same movie multiple times then {pi} will increase just the same.

And then for the special cases you'll need to extend your format as well. This is where things get tricky and ambiguous, depending on what kinda files names you wanna be able to deal with.

Code: Select all

{'part1; part9; parta; partx'.lower().replaceAll(/part\W*(\w)/, { g, m -> m ==~ /\d/ ? m : m.charAt(0)-'a'.charAt(0)+1})}
:idea: Please read the FAQ and How to Request Help.
Chryses
Posts: 66
Joined: 26 Aug 2012, 19:11

Re: Question about movie cd/part numbering

Post by Chryses »

So, I think that is better to make only one string that search if filename contains some code and then substitute into cd1 etc etc.

I really don't how Groovy works, do you know if there is some kind of program that help to make the strings that I need?
For example your second code for me is like a cyrillic! Let me guess, you search part1 and part9 or you search from part1 to part9? Then you convert to lower and replace all, and from here for me is hard to read :lol:

So do you think that it possible to make only one string to try to catch the different pattern and replace with CD1...CDN? If exist a kind of program that help or a "guide" to the various functions that I can apply to do what I need to do?

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

Re: Question about movie cd/part numbering

Post by rednoah »

Here you go:

Code: Select all

{fn.replaceAll(/(?i:part|cd)[ ._]*(\w)/, { g, m -> 'CD'+(m ==~ /\d/ ? m : m.upper().charAt(0)-'A'.charAt(0)+1)})}
Or a more simplified version that doesn't deal with Part [A-Z] cause that makes things easier:

Code: Select all

{fn.replaceAll(/(?i:part|cd)[ ._]*([0-9])/, "CD$i")}
I would go the other way around though. There's lots of movies/episodes that have Part N in their name, but none that have CD N. ;)
:idea: Please read the FAQ and How to Request Help.
Chryses
Posts: 66
Joined: 26 Aug 2012, 19:11

Re: Question about movie cd/part numbering

Post by Chryses »

I think you've the Groovy code on you DNA!

Really? On "my side" there is more CDN or CD.N or CD N, for movie, instead of part or parte. For the tv shows, on my side, I've never see file that have CDN but, only for some season finale, there is more than one part, with the same name and (1) and (2) at the end or sometime with part1 part2 etc etc.

So, as you suggested, I think that the second one is more simple to use, because partA etc is a very rare case!

Correct me if I wrong, I see that the code search for part or cd and then add a possibility to have a space a . and a underline, so it's also included the "non space" for example part1 or cd1?

One curiosity I really don't understand the first code, this part

Code: Select all

*(\w)/, { g, m -> 'CD'+(m ==~ /\d/ ? m : m.upper().charAt(0)-'A'.charAt(0)+1)})}
I hope to understand to try to be indipendent :lol: :lol: :lol: :lol: :lol:
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Question about movie cd/part numbering

Post by rednoah »

I mean that If you change CD.N to Part.N it's not a problem, ever. But if you change movies like "Mockingjay, Part 1" and "Mockingjay, Part 2" to CD.N that's probably not what you want. ;)

@see http://www.imdb.com/title/tt1951265/

[ ._]* means any of these 3 characters, "0 times or more", so that includes "non space"
\w means word-characters => letters & numbers & underscore
\W means non-word-characters

@see https://docs.oracle.com/javase/8/docs/a ... ttern.html
:idea: Please read the FAQ and How to Request Help.
Chryses
Posts: 66
Joined: 26 Aug 2012, 19:11

Re: Question about movie cd/part numbering

Post by Chryses »

Ok, now I'm on it, I misunderstood what you meant. Right observation, like harry potter, yep, some movie have the 3rd act divided in 2 part! I give a try and I'll see what works better, I've only to check if kodi works well with the file splitted into 2 or more part and named with Part.N instead of CD.N, in this case the best way is to convert all CD in Part, tnx for suggestion!
Tnx for the links, I don't know that was a java code, I thought it was groovy, but make no difference for me, groovy=java=arabic code! But now I've some explanation about the regex!
Chryses
Posts: 66
Joined: 26 Aug 2012, 19:11

Re: Question about movie cd/part numbering

Post by Chryses »

Ops, I tried to modify my actual code from

Code: Select all

"movieFormat=$dest_dir/$film_path/{n} ({y}){' - '+fn.match(/(?i)cd+[0-9]/).toUpperCase()}{' - '+fn.match(/(?i)cd +[0-9]/).toUpperCase()}"
to

Code: Select all

"movieFormat=$dest_dir/$film_path/{n} ({y}){' - '+fn.replaceAll(/(?i:part|cd)[ ._-]*([0-9])/, \"CD$i\")}"
But fn.replaceall works different, now for example I've this result

The name of the file is

Code: Select all

Il.Pianeta.Delle.Scimmie.2014.DTS.ITA.ENG.1080p.BluRay.x264-BLUWORLD.mkv
And with the new movieformat the name now is

Code: Select all

Apes Revolution - Il pianeta delle scimmie (2014) - Apes.Revolution-Il.Pianeta.Delle.Scimmie.2014.DTS.ITA.ENG.1080p.BluRay.x264-BLUWORLD.mkv
So fn.replaceall seems that append the original name to the new file name

I think that I mess up something ;)
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Question about movie cd/part numbering

Post by rednoah »

fn = original filename
fn.replaceAll() => modified original filename

If you only want the CD.N part then you'll need to add a String.match() to select the piece of the modified filename you want.

Code: Select all

fn.replaceAll(...).match(...)
:idea: Please read the FAQ and How to Request Help.
Chryses
Posts: 66
Joined: 26 Aug 2012, 19:11

Re: Question about movie cd/part numbering

Post by Chryses »

Ok, so I tried this, but don't works like expected

Code: Select all

movieFormat=$dest_dir/$film_path/{n} ({y}){' - '+fn.replaceAll(/(?i:part|cd)[ ._-]*([0-9])/, \"CD$i\").match(/(?i)cd+[0-9]/).toUpperCase()}
don't add the " - CD1.ext" at the end

Code: Select all

Auto-detect movie from context: [/share/CACHEDEV1_DATA/Multimedia/Film/Horror in the attic (2001) - CD1.avi]
[TEST] Rename [/share/CACHEDEV1_DATA/Multimedia/Film/Horror in the attic (2001) - CD1.avi] to [/share/CACHEDEV1_DATA/Multimedia/Film/Horror in the attic (2001).avi]
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Question about movie cd/part numbering

Post by rednoah »

1.
Use the Format Editor for testing.

e.g.

Code: Select all

{'Horror in the attic (2001) - CD1'.replaceAll(/(?i:part|cd)[ ._-]*([0-9])/, "CD$i").match(/CD[0-9]/)}
Results: Works as expected.

2.
Once we know it works, and only then, do we continue to the next step. We find out it doesn't work? How can it be? Oh! The shell is replacing $i with empty! The format you're passing in is actually slightly different from the format you think you're passing in once you look at it closely. ;)
:idea: Please read the FAQ and How to Request Help.
Chryses
Posts: 66
Joined: 26 Aug 2012, 19:11

Re: Question about movie cd/part numbering

Post by Chryses »

Find the error is always the best part, usually I debug my script that is bash or other script, not groovy or java, I'm totally without knowledge to this language but I found that I forget to escape the $ :D :D :D

Only one question, what is right between this 2 code:

Code: Select all

{' - '+fn.replaceAll(/(?i:part|cd)[ ._-]*([0-9])/, \"CD\$i\").match(/CD[0-9]/)}
or

Code: Select all

{' - '+fn.replaceAll(/(?i:part|cd)[ ._-]*([0-9])/, \"CD\$i\").match(/(?i)cd+[0-9]/).toUpperCase()}
I saw strange behavior making some "experiment", let me explain

On bash side for example filebot recognize correctly Horror in the attic (2001), on windows gui don't, propose me "The attic expeditions (2001)", this happens on various movie, just to inform you.

And if I use one of the string above on windows gui, with multiple file, the things come funny, because the replace and substitution make this
Image
As you can see, CD5 and CD6, only because is the 5 and 6 file, so this method works only for one file at time, right?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Question about movie cd/part numbering

Post by rednoah »

1.
String.match() is CASE_INSENSITIVE by default.

2.
/cd+/ is just wrong. It matches cd, cdd, cdddddddd, etc

3.
{pi} can't work if you do 1 file at a time, and you will get odd results if (FileBot thinks that) you have the same movie multiple times.

The fn.match() approach can't not work, regardless of what match FileBot came up with, as long as the filename is already tagged correctly.

4.
So you're reporting a mismatch?
Manual wrote:Include file paths as text when reporting mismatches

EDIT:


You fell into the $ trap again! :D

{i} is a format binding => index; so the String value of the Groovy String "$i" is "1" or whatever row index.

This is the correct way of doing it:

Code: Select all

{'cd.2'.replaceAll(/cd.(\d)/, 'CD$1')}
Reference Group 1 via $1 and make sure to pass a simple String literal with '...' so you don't have to worry about the $ being interpreted by Groovy.
:idea: Please read the FAQ and How to Request Help.
Post Reply