Rename folder if embedded or external subtitle found

Any questions? Need some help?
Post Reply
fvb
Posts: 12
Joined: 27 Mar 2017, 19:46

Rename folder if embedded or external subtitle found

Post by fvb »

I'm sorry for a real newbie question. I've searched the forum and tried in the GUI for two days now without success :(

I'd like to add 'SWESUB' to the movie's folder name if there is an embedded Swedish subtitle in the movie file or/and and external .srt file in the same folder as the movie file.

I've understood that i should use 'textLanguages' in some way but then I'm lost. Can anyone point me in the right direction on how to proceed?

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

Re: Rename folder if embedded or external subtitle found

Post by rednoah »

fvb wrote:add 'SWESUB' to the movie's folder name if there is an embedded Swedish subtitle
This one should be straight-forward:

Code: Select all

textLanguages =~ /swe/ ? 'SWESUB' : null
fvb wrote:external .srt file in the same folder as the movie file
This one is tricky:

Code: Select all

model.any{ id == it.id && it.lang =~ /swe/ } ? 'SWESUB' : null
@see viewtopic.php?f=5&t=2
:idea: Please read the FAQ and How to Request Help.
fvb
Posts: 12
Joined: 27 Mar 2017, 19:46

Re: Rename folder if embedded or external subtitle found

Post by fvb »

Thanks!

Great app and great support! I just bought a license =)

Cheers!
fvb
Posts: 12
Joined: 27 Mar 2017, 19:46

Re: Rename folder if embedded or external subtitle found

Post by fvb »

I'd like to take this one step further and add "ENGSUB" if there's an embedded or external English subtitle available. If there are both Swedish and English subtitles available, preferably only SWESUB should be written.

I have this working format tag now for SWESUB looking for embedded or external subtitles:

Code: Select all

{ any {model.any{ id == it.id && it.lang =~ /swe/ } ? '.SWESUB' : null}{textLanguages =~ /swe/ ? '.SWESUB' : null}}
I have no clue on how to proceed and I'm quite bad at scripting. Any hints or maybe someone has a somewhat working solution?

Tnx!
fvb
Posts: 12
Joined: 27 Mar 2017, 19:46

Re: Rename folder if embedded or external subtitle found

Post by fvb »

OK, it did some testing myself but without luck. This code adds ".ENGSUB" even if there aren't an English sub (but writes out ".SWESUB" if there's both an English and a Swedish sub so that part works).

Code: Select all

{ any {model.any{ id == it.id && it.lang =~ /swe/ } ? '.SWESUB' : { id == it.id && it.lang =~ /eng/ } ? '.ENGSUB' : null}{textLanguages =~ /swe/ ? '.SWESUB' : textLanguages =~ /eng/ ? '.ENGSUB' : null}}
Any hints on what to change?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Rename folder if embedded or external subtitle found

Post by rednoah »

Which of your conditions that trigger '.ENGSUB' is hit? You have two. I'd start by figuring out which condition is unexpectedly true.

May I ask? Why are you using the model binding? What is your thinking?
:idea: Please read the FAQ and How to Request Help.
fvb
Posts: 12
Joined: 27 Mar 2017, 19:46

Re: Rename folder if embedded or external subtitle found

Post by fvb »

Thanks @rednoah for logical reasoning. Test results for the different strings:

Code: Select all

{model.any{ id == it.id && it.lang =~ /swe/ } ? '.SWESUB' : { id == it.id && it.lang =~ /eng/ } ? '.ENGSUB' : null}
File with no embedded sub: ENGSUB
File with embedded eng sub: ENGSUB
File with embedded swe sub: ENGSUB
File with embedded swe + eng sub: ENGSUB
File with external eng sub: ENGSUB
File with external swe sub: SWESUB
File with external swe + eng sub: SWESUB

Code: Select all

{textLanguages =~ /swe/ ? '.SWESUB' : textLanguages =~ /eng/ ? '.ENGSUB' : null}
File with no embedded sub: - (nothing)
File with embedded eng sub: ENGSUB
File with embedded swe sub: SWESUB
File with embedded swe + eng sub: SWESUB
File with external eng sub: - (nothing)
File with external swe sub: - (nothing)
File with external swe + eng sub: - (nothing)

The first part of the code string with "model.any" is your work (the SWESUB part) =)
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Rename folder if embedded or external subtitle found

Post by rednoah »

0.
When you post:

Code: Select all

{model.any{ id == it.id && it.lang =~ /swe/ } ? '.SWESUB' : { id == it.id && it.lang =~ /eng/ } ? '.ENGSUB' : null}
You mean this right?

Code: Select all

{model.any{ id == it.id && it.lang =~ /swe/ } ? '.SWESUB' : model.any{ id == it.id && it.lang =~ /eng/ } ? '.ENGSUB' : null}
Because otherwise it's just an issue of not copy & pasting correctly?


1.
Does your test case not show that each of these expressions work as expected?

Code: Select all

File with no embedded sub: ENGSUB
Presumably, since the condition yields true, there are external English subtitles.


2.
I see. You'll need to combine the different expressions. Depending on what exactly you want.

This one is for checking sibling files, i.e. external subtitles:

Code: Select all

model.any{ id == it.id && it.lang =~ /swe/ }
This one is for checking embedded subtitles:

Code: Select all

textLanguages =~ /swe/
Note: {textLanguages} when applied to a subtitle file will yield the {textLanguages} value of the closest video file, so we don't have to use model.any() here.


Checking for either embedded subtitles OR sibling subtitle files that are Swedish:

Code: Select all

textLanguages =~ /swe/ || model.any{ id == it.id && it.lang =~ /swe/ } ? '. SWESUB' : null

Doing the above for Swedish, and if that's not the case then try English, and if that's not the case yield nothing:

Code: Select all

textLanguages =~ /swe/ || model.any{ id == it.id && it.lang =~ /swe/ } ? '. SWESUB' : textLanguages =~ /eng/ || model.any{ id == it.id && it.lang =~ /eng/ } ? '. ENGSUB' : null
:idea: Please read the FAQ and How to Request Help.
fvb
Posts: 12
Joined: 27 Mar 2017, 19:46

Re: Rename folder if embedded or external subtitle found

Post by fvb »

@rednoah, everything seems so easy when you explain =)

I'm a bit ashamed though.. I still must do something wrong, because I can't get this code to pick up any of the external subtitles:

Code: Select all

{ textLanguages =~ /swe/ || model.any{ id == it.id && it.lang =~ /swe/ } ? '.SWESUB' : textLanguages =~ /eng/ || model.any{ id == it.id && it.lang =~ /eng/ } ? '.ENGSUB' : null }
For embedded subtitles it works like a charm =)


EDIT: The code picks up external subtitles only when there is an internal one also
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Rename folder if embedded or external subtitle found

Post by rednoah »

Does this part work for picking up external subtitles?

Code: Select all

model.any{ id == it.id && it.lang =~ /swe/ }
Note that the external subtitle must be part of the file set that has been loaded into FileBot. If you just drop in the video file and not the subtitle file then {model} won't include the corresponding subtitle match.
:idea: Please read the FAQ and How to Request Help.
fvb
Posts: 12
Joined: 27 Mar 2017, 19:46

Re: Rename folder if embedded or external subtitle found

Post by fvb »

rednoah wrote: 09 May 2018, 11:15 Does this part work for picking up external subtitles?

Code: Select all

model.any{ id == it.id && it.lang =~ /swe/ }
Note that the external subtitle must be part of the file set that has been loaded into FileBot. If you just drop in the video file and not the subtitle file then {model} won't include the corresponding subtitle match.
Hi and thanks!

Yes, that code above identifies an external Swedish subtitle. This code finds the Swedish OR the English external subtitles:

Code: Select all

{ model.any{ id == it.id && it.lang =~ /swe/ } ? '.SWESUB' : model.any{ id == it.id && it.lang =~ /eng/ } ? '.ENGSUB' : null }
My file's names for testing this set up that I drag all at once into FileBot (example):
Casablanca.1942.mkv
Casablanca.1942.en.srt
Casablanca.1942.sv.srt

I've also tested naming with:
Casablanca.1942.swe.srt --but with the same result.
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Rename folder if embedded or external subtitle found

Post by rednoah »

I'm actually not quite sure what you want.

Here's what I get:
Image

:idea: I'm testing with a sample media file without embedded subtitles.


EDIT:

{textLanguages} will unwind the expression if there are no embedded subtitles at all, so maybe this will more more like the way you want:

Code: Select all

{ self.textLanguages =~ /swe/ || model.any{ id == it.id && it.lang =~ /swe/ } ? '.SWESUB' : self.textLanguages =~ /eng/ || model.any{ id == it.id && it.lang =~ /eng/ } ? '.ENGSUB' : null }
{self.textLanguages} will just yield null if {textLanguages} is undefined, instead of unwinding the entire expression.
:idea: Please read the FAQ and How to Request Help.
fvb
Posts: 12
Joined: 27 Mar 2017, 19:46

Re: Rename folder if embedded or external subtitle found

Post by fvb »

That was sweeet! =)

When dropping a folder with movies both having, and not having Swedish subtitles, all the movies get "SWESUB" suffix. Is this a normal behavior?
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Rename folder if embedded or external subtitle found

Post by rednoah »

I don't know. Should it be? This a custom format, the behaviour is whatever the code says it is. :lol:
:idea: Please read the FAQ and How to Request Help.
Post Reply