Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

speed-transition.lua: Ignore subtitles that match a regex pattern #20

Open
CreamyCookie opened this issue Nov 10, 2020 · 8 comments
Open

Comments

@CreamyCookie
Copy link

CreamyCookie commented Nov 10, 2020

First of all, thanks for the speed-transition.lua script! It's really useful.

I don't know how easy it is to achieve, but I'd love if the script could ignore subtitles that are shorter than a certain length, since very short subtitles can be read quickly even at high speeds, and often they just contain something like ♪♫ when music is played.

I think regex might be useful for that, so that one could also ignore subtitles where the whole text is enclosed in square brackets, which are often used to describe sounds.

Pattern that could be used:

^([🎵🎶]+.*[🎵🎶]+|[ 🎵🎶]+|\[.*\]|.{0,3})$
@CreamyCookie CreamyCookie changed the title speed-transition.lua: Ignore subtitles with text shorter than a configurable amount. speed-transition.lua: Ignore subtitles that match a regex pattern Nov 10, 2020
@bitingsock
Copy link
Contributor

I currently have a feature similar to this in a pending pull request. It is much simpler though. It is just a table of characters that if exist at all in the subtitle, it will will ignore that line.

@CreamyCookie
Copy link
Author

CreamyCookie commented Feb 14, 2021

@bitingsock Thanks a lot! This is great.

In case it might be of use, I've converted my above regex into Lua patterns. I didn't know Lua had no regex included, since I have basically no Lua experience. I've also added two characters from your change:

ignoredCharacters = "#♯♩♪♬♫🎵🎶"

-- Test strings:
s = "     [ loud noise ] " 
--s = " How are you doing?  "
--s = "  ♫ la deda ♪     "
--s = "  why     "
--s =  " ♯🎵#  "
--s =  " Hey, it's just a ♪ character!   "

local st = s:gsub("^%s*(.-)%s*$", "%1") -- trim string
local ign = ignoredCharacters
local isLikelyAudioSub = st:len() < 4 or st:find("^%[.*%]$") or 
    st:find("^[" .. ign .. "]+.*[" .. ign .. "]+$") or 
    st:find("^[ " .. ign .. "]+$")

print(isLikelyAudioSub)

@bitingsock
Copy link
Contributor

Cool, I'll try to implement this.

@bitingsock
Copy link
Contributor

bitingsock commented Feb 21, 2021

I got the pattern match working: https://github.com/bitingsock/mpv-scripts/blob/patch-4/speed-transition.lua
Waiting for pull approval, but you can use that one in the meantime.

@CreamyCookie
Copy link
Author

@bitingsock Thanks a lot! =)

@CreamyCookie
Copy link
Author

@bitingsock Just noticed something, and I think this was also the case previously.

When using subtitles that cannot easily be converted to text (e.g. image based ones), the script doesn't work at all.

I'm not sure what the cause is, but sub-stepping seems to work. You can step from one subtitle to the next. (Of course the match filter can't work without the actual text)

@bitingsock
Copy link
Contributor

bitingsock commented Feb 27, 2021

Correct, it has always only worked on Text bases subs. However, there may be some way to make a way using pure sub-stepping based on properties that are already triggering the functions. I'll have to think about that.

@CreamyCookie
Copy link
Author

CreamyCookie commented Feb 28, 2021

That would be really awesome!

Not sure how useful, but one thing I've tried is to make speed_transition get triggered by a sub-start property change (instead of sub-text, whose value is then manually requested).

However, it seems that with image-based subtitles both sub-start and sub-text only trigger once, and then never again, which might be why it doesn't work.

Either I'm missing something, or this is a bug in mpv.


Just found this plugin of yours (which inspired the speed-transition one), and it seems like it would avoid that problem by calling a function periodically (not tried).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants