[HELP] Missing information leaving blank spaces in filename.

All about user-defined episode / movie / file name format expressions
Post Reply
Romtromon
Posts: 25
Joined: 16 Sep 2016, 09:51

[HELP] Missing information leaving blank spaces in filename.

Post by Romtromon »

Image

As you can see on the screenshot above if the group is missing I'm left with a set of empty square brackets and if the source is missing there's an unnecessary space after the bracket. Some of the schemes I've seen seem to use an & symbol to prevent this somehow if a certain piece of info is missing but I don't know how to, please help.

Also, notice that "Magi - The Kingdom of Magic" has 2 folders because some of the episodes have a different video codec, is there anyway to write the code so that it'd be one folder containing the two codecs in this format: "AVC-x264" instead of splitting into two folders?

Thanks in advance for any help!
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [HELP] Missing information leaving blank spaces in filename.

Post by rednoah »

That's all in your format, which you neglected to share here.

1.
Looking at your other thread, this format is gonna give you unnecessary spaces:

Code: Select all

({source} {vf} {vc} {ac})
This expression will handle undefined bindings correctly:

Code: Select all

{allOf{source}{vf}{vc}{ac}.join(' ')}

2.
FileBot can't know in advance what files you're processing. If you rename x264 today and AVC tomorrow then FileBot couldn't possibly know about AVC at the time of renaming x264.

If you process all your files in a single batch then it's not impossible:

Code: Select all

{model.vc.unique().join('-')}
:idea: Please read the FAQ and How to Request Help.
Romtromon
Posts: 25
Joined: 16 Sep 2016, 09:51

Re: [HELP] Missing information leaving blank spaces in filename.

Post by Romtromon »

Thank you very much that's exactly what I wanted for both cases. Sorry I forgot to include my format I'll include that here in-case someone else has the same question:

Code: Select all

I:/Anime/{primaryTitle.replace(': ',' - ')} [{n.findMatch(group) ? null : group}] ({source} {vf} {vc} {ac})/{primaryTitle.replaceAll(/(?<=\w)[\w\s]/, '').replace(': ', '-')} {absolute.pad(2)} - {t.replace(': ', ' - ')}
Romtromon
Posts: 25
Joined: 16 Sep 2016, 09:51

Re: [HELP] Missing information leaving blank spaces in filename.

Post by Romtromon »

rednoah wrote:That's all in your format, which you neglected to share here.

1.
Looking at your other thread, this format is gonna give you unnecessary spaces:

Code: Select all

({source} {vf} {vc} {ac})
This expression will handle undefined bindings correctly:

Code: Select all

{allOf{source}{vf}{vc}{ac}.join(' ')}

2.
FileBot can't know in advance what files you're processing. If you rename x264 today and AVC tomorrow then FileBot couldn't possibly know about AVC at the time of renaming x264.

If you process all your files in a single batch then it's not impossible:

Code: Select all

{model.vc.unique().join('-')}
So I tried combining the two things you taught me and came up with this:

Code: Select all

I:/Anime/{primaryTitle.replace(': ',' - ')} [{n.findMatch(group) ? null : group}] ({allOf{model.source.unique().join('-')}{model.vf.unique().join('-')}{model.vc.unique().join('-')}{model.ac.unique().join('-')}.join(' ')})/{primaryTitle.replaceAll(/(?<=\w)[\w\s]/, '').replace(': ', '-')} {any{absolute}{'S'+special}.pad(2)} - {t.replace(': ', ' - ')}
But as you can see below I get a 'null' within the brackets (maybe because I included the unique join thing as well?) and also, I can't take the same approach for when the group is missing cause I need to completely get rid of the square brackets.
Image
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [HELP] Missing information leaving blank spaces in filename.

Post by rednoah »

1.
You'll need to remove null from the List. Since the logic is the same for all the attributes you want you can further pull things together:

Code: Select all

{model.collect{ [it.source, it.vc, it.ac] }*.minus(null)*.unique()*.join('-').join(' ')}

2.
This should do for the group part:

Code: Select all

{model.group.unique()}
Assuming that all files have a group. If you get null values that's a hint for posting them: viewtopic.php?f=5&t=4 ;)
:idea: Please read the FAQ and How to Request Help.
Romtromon
Posts: 25
Joined: 16 Sep 2016, 09:51

Re: [HELP] Missing information leaving blank spaces in filename.

Post by Romtromon »

It seems we might've had some miscommunication and there seems to be a little hitch in my current format:

Code: Select all

I:/Anime/{primaryTitle.replace(': ',' - ')} {model.group.unique()} ({model.collect{ [it.source, it.vc, it.ac] }*.minus(null)*.unique()*.join('-').join(' ')})/{primaryTitle.replaceAll(/(?<=\w)[\w\s]/, '').replace(': ', '-')} {any{absolute}{'S'+special}.pad(2)} - {t.replace(': ', ' - ')}
And the output looks like this:
Image

Something seems to be wrong in this part:
rednoah wrote:1.
You'll need to remove null from the List. Since the logic is the same for all the attributes you want you can further pull things together:

Code: Select all

{model.collect{ [it.source, it.vc, it.ac] }*.minus(null)*.unique()*.join('-').join(' ')}
And with this part, what I wanted is for the square brackets to be gone altogether if the group information is missing but I'm getting a null with brackets and adding ".minus(null)" still left the square brackets behind:
rednoah wrote:2.
This should do for the group part:

Code: Select all

{model.group.unique()}
Assuming that all files have a group. If you get null values that's a hint for posting them: viewtopic.php?f=5&t=4 ;)
For one thing I'm not even sure how the square brackets come-in for the group with the format written like this. Please help me out.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [HELP] Missing information leaving blank spaces in filename.

Post by rednoah »

1.
Try this:

Code: Select all

{model.source.minus(null).unique().join('-')}
2.
The result of {model.group.unique()} is a List and the [a, b, c] is part of the default String representation of a List.

@see http://docs.groovy-lang.org/latest/html ... tml#_lists
:idea: Please read the FAQ and How to Request Help.
Romtromon
Posts: 25
Joined: 16 Sep 2016, 09:51

Re: [HELP] Missing information leaving blank spaces in filename.

Post by Romtromon »

rednoah wrote:1.
Try this:

Code: Select all

{model.source.minus(null).unique().join('-')}
Well it seems I'm right back where I started only with the multiple folder issue solved.
Current format:

Code: Select all

I:/Anime/{primaryTitle.replace(': ',' - ')} [{n.findMatch(group) ? null : group}] ({allOf{model.source.minus(null).unique().join('-')}{model.vf.minus(null).unique().join('-')}{model.vc.minus(null).unique().join('-')}{model.ac.minus(null).unique().join('-')}.join(' ')})/{primaryTitle.replaceAll(/(?<=\w)[\w\s]/, '').replace(': ', '-')} {any{absolute}{'S'+special}.pad(2)} - {t.replace(': ', ' - ')}
The problem as you can see below is that extra space before the 720p which is caused because the source is missing and I want to be rid of that. And the set of empty square brackets because the group is missing which I also want to get rid of when the group is missing.
Image

Thanks for all the help so far and please bear with me.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [HELP] Missing information leaving blank spaces in filename.

Post by rednoah »

1.
I'll think about adding some built-in helpers to make this use case easier.

In the meanwhile, this should do:

Code: Select all

{model.collect{ [it.source, it.vc, it.ac] }.transpose()*.minus(null)*.unique()*.join('-').join(' ')}

2.
Use this for your group expression:

Code: Select all

{"[$group]"}
@see viewtopic.php?f=5&t=1895
:idea: Please read the FAQ and How to Request Help.
Crankrune
Posts: 21
Joined: 20 Jul 2016, 11:35

Re: [HELP] Missing information leaving blank spaces in filename.

Post by Crankrune »

Tuned into this thread a bit late, but I have some advice. For the group binding, another fix is to just move the brackets inside and it'll only use them if group is defined.

Code: Select all

Old way: [{n.findMatch(group) ? null : group}]
New way: {[n.findMatch(group) ? null : group]} 
Another workaround for the whole AVC/x264 thing. Just replace the 'x264' part with whichever one you prefer.

Code: Select all

{vf =~ /AVC|x264/ ? 'x264' : vf}
Also, on your issue with the space because of source being undefined, I'm not quite sure what's going on. Why are you using "{model.source}" instead of just "{source}"? Maybe I just missed something, but it doesn't seem to help anything. If you use the regular source binding, that issue with the space won't happen.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [HELP] Missing information leaving blank spaces in filename.

Post by rednoah »

The OP wants x264 and AVC in the path if files with multiple video codecs are processed together. {model} gives you access to the rename context and all bindings for all matches in that context. So if you process a single file alone the format may come up with a different path compared to processing the same file alongside a bunch of other files.
:idea: Please read the FAQ and How to Request Help.
ChefGregS
Posts: 99
Joined: 30 Mar 2016, 11:14

Re: [HELP] Missing information leaving blank spaces in filename.

Post by ChefGregS »

Crankrune wrote: 21 Oct 2016, 20:47 Tuned into this thread a bit late, but I have some advice. For the group binding, another fix is to just move the brackets inside and it'll only use them if group is defined.

Code: Select all

Old way: [{n.findMatch(group) ? null : group}]
New way: {[n.findMatch(group) ? null : group]} 
I am also trying to get rid of [] when the fields are empty. I have to say, moving the [] inside of the { } was way too simple! :) Thanks for that!!!! Worked like a dream!
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [HELP] Missing information leaving blank spaces in filename.

Post by rednoah »

Do you wanna know why that works?

[0,1,2,3] is array syntax, so you return an Array / List object, and the default String representation kinda looks like the code. And if the code fails, no List object, and so no [...] in the output. ;)
:idea: Please read the FAQ and How to Request Help.
ChefGregS
Posts: 99
Joined: 30 Mar 2016, 11:14

Re: [HELP] Missing information leaving blank spaces in filename.

Post by ChefGregS »

rednoah wrote: 14 Mar 2018, 03:37 Do you wanna know why that works?

[0,1,2,3] is array syntax, so you return an Array / List object, and the default String representation kinda looks like the code. And if the code fails, no List object, and so no [...] in the output. ;)
Yeah...that one actually made sense to me. Took me back to when I did programming in the 80's in c and assembler. I'm starting to remember some. I have always LOVED boolean logic. Friend of mine was a master at it and taught me a lot. Have not thought about it in about 30 years!!
Post Reply