Skip to content

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

@CreamyCookie

Description

@CreamyCookie

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})$

Activity

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[/+] on Nov 10, 2020
bitingsock

bitingsock commented on Feb 14, 2021

@bitingsock
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

CreamyCookie commented on Feb 14, 2021

@CreamyCookie
Author

@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

bitingsock commented on Feb 14, 2021

@bitingsock
Contributor

Cool, I'll try to implement this.

bitingsock

bitingsock commented on Feb 21, 2021

@bitingsock
Contributor

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

CreamyCookie commented on Feb 21, 2021

@CreamyCookie
Author

@bitingsock Thanks a lot! =)

CreamyCookie

CreamyCookie commented on Feb 27, 2021

@CreamyCookie
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

bitingsock commented on Feb 27, 2021

@bitingsock
Contributor

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

CreamyCookie commented on Feb 28, 2021

@CreamyCookie
Author

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @CreamyCookie@bitingsock

        Issue actions

          speed-transition.lua: Ignore subtitles that match a regex pattern · Issue #20 · zenyd/mpv-scripts