appending subtitles with .sdh postfix based on text inside the subtitle file
Posted: 09 Mar 2023, 18:35
Hi
I have subtitles that are badly named (e.g 2_English.srt; 3_English.srt). Some are SDH, some are not. I want to rename them so the '.sdh' postfix is appended after the '.eng' so that Plex doesn't throw an "Unknown" flag on them. I use the GUI, no AMC.
After scouring the forums and cannibalising code here and there, I've done this:
This is supposed to look for text in brackets and if it gets more than 2 hits, it puts the .sdh postfix. I ripped the regex from one of rednoah's posts in another similar thread. I tried to simplify it so it just looks for a '[' (so 'match(/\[/)') but that didn't work. Also, I'm not sure why to use 'size', I tried 'count' but that also didn't work.
Anyway, the code aboves works but since 'match' does not return a true/false boolean, 'else' is never triggered. Now I can technically live with that since the .eng postfix will be put there anyway by the emby/plex/whatever expression but I want to do it right. I think I need to use the groovy match or find operator ('=~' and '==~') but I can't figure out how to do it.
I tried the below, and while it does put .sdh on some subtitles, it's not correct or reliable.
I know 0 groovy and regex, and I've been bashing my head against this task all day, my brain is completely fried at this point. I know I'm probably missing something extremely basic and silly, like I'm not escaping characters correctly or something like that, but I'm really stuck.
Also, I found out this expression String.matchBrackets() in the help page but I couldn't get it to work either.
Any help would be really appreciated
I have subtitles that are badly named (e.g 2_English.srt; 3_English.srt). Some are SDH, some are not. I want to rename them so the '.sdh' postfix is appended after the '.eng' so that Plex doesn't throw an "Unknown" flag on them. I use the GUI, no AMC.
After scouring the forums and cannibalising code here and there, I've done this:
Code: Select all
{drive}/series/{~emby.derive{' '+allOf{vf}{vcf}{ac}}} {if (ext == 'srt' && file.text.match(/(?m)^\[.+\]$/).size() > 2) '.sdh' else '.eng'}
This is supposed to look for text in brackets and if it gets more than 2 hits, it puts the .sdh postfix. I ripped the regex from one of rednoah's posts in another similar thread. I tried to simplify it so it just looks for a '[' (so 'match(/\[/)') but that didn't work. Also, I'm not sure why to use 'size', I tried 'count' but that also didn't work.
Anyway, the code aboves works but since 'match' does not return a true/false boolean, 'else' is never triggered. Now I can technically live with that since the .eng postfix will be put there anyway by the emby/plex/whatever expression but I want to do it right. I think I need to use the groovy match or find operator ('=~' and '==~') but I can't figure out how to do it.
I tried the below, and while it does put .sdh on some subtitles, it's not correct or reliable.
Code: Select all
{drive}/series/{~emby.derive{' '+allOf{vf}{vcf}{ac}}} {if (ext == 'srt' && file.text=~(/(?m)^\[.+\]$/).size() > 2) '.sdh' else '.eng'}
I know 0 groovy and regex, and I've been bashing my head against this task all day, my brain is completely fried at this point. I know I'm probably missing something extremely basic and silly, like I'm not escaping characters correctly or something like that, but I'm really stuck.
Also, I found out this expression String.matchBrackets() in the help page but I couldn't get it to work either.
Any help would be really appreciated
