Conversation
a96890e to
928ad11
Compare
|
Extracting a subtitle file from a video can take a few seconds and requires resources, so until now we didn't want to implement it in mpvacious. Plus, it requires writing a lot of code. Before settling on this solution, let's try a proven method. In our sub-transition script we look ahead by changing for secondary subs, use the |
|
Implemented the |
89c24f9 to
eea9b58
Compare
|
I think I should try using this for a few days before it becomes reviewable |
|
I think I have to make it handle backwards subtitle overlaps as well, because sometimes I jump into the middle of a primary cue and mpvacious doesn't see a backward secondary cue |
|
Simply rewinding back and forth is enough for mpvacious to memorize subtitle lines. shift+h and shift+l are mentioned in README as aliases for seek back and seek forward. |
Okay, I'll roll back the change |
6ddc4f8 to
81ca880
Compare
|
Removed the backwards seek |
sub-step is a pretty clever hack that can be applied in both directions if you actually need it. My comment was more about whether this is something the users might need or not. You can probably edit scan_secondary_forward() to include direction as a parameter, so you don't have to duplicate much code. Also, consider splitting this PR into smaller ones if possible. Please comment when this PR is ready. |
81ca880 to
9cd020f
Compare
9cd020f to
4b6ea3a
Compare
|
bump |
|
bump @tatsumoto-ren |
|
@kuator I'm trying to understand what's going on, but honestly, it's not smooth. There are some strong hints that this PR was mostly not written by a human. It makes it difficult to review. I'll try to figure it out and maybe come up with some solutions. |
| -- it's okay to print them on the screen. | ||
| osd:submenu("Secondary text"):newline() | ||
| for idx, s_line in ipairs(subs_observer.recorded_secondary_subs()) do | ||
| for idx, s_line in ipairs(subs_observer.get_selected_secondary_subs()) do |
There was a problem hiding this comment.
get_selected_secondary_subs() is not a getter. It can mutate secondary-sub-delay, run many sub-step commands, and insert subtitles. Every menu update triggers scan. This is likely very expensive.
A function named get_* should normally be read-only.
| logger = logger or require('mp.msg') | ||
| local scanning = false | ||
|
|
||
| local function scan(observed, window, initial_delay, normalized_delay, direction) |
There was a problem hiding this comment.
this function is longer than 21 lines, lacks a docstring, has ambiguous name, and its parameters are vaguely named. Also, it takes more than 4 parameters. usually, if a function takes more than 4 parameters, it should be refactored. Maybe some parameters need to be turned into structs.
- observed is an observed secondary sub_list.
- window is a combined primary subtitle.
| mp_api = mp_api or require('mp') | ||
| logger = logger or require('mp.msg') |
There was a problem hiding this comment.
Imports inside functions do not match the project's convention.
Prefer:
local mp = require('mp')
local msg = require('mp.msg')
then default to mp / msg inside new.
| } | ||
| end | ||
|
|
||
| local function run_scan_case(case) |
There was a problem hiding this comment.
This function is specifically for testing only. If so, it should be separated from production code visually.
------------------------------------------------------------
-- tests
local function run_scan_case(case)
...
end| Copyright: Ajatt-Tools and contributors; https://github.com/Ajatt-Tools | ||
| License: GNU GPL, version 3 or later; http://www.gnu.org/licenses/gpl.html | ||
|
|
||
| Secondary scanner discovers subtitle cues outside the currently visible event. |
There was a problem hiding this comment.
Honestly, I don't know what cue means. It is the wrong term here. We already have Subtitle, sub, dialogs, and sub_list. Introducing cue creates a second vocabulary for the same thing.
Subtitle.cues → source_subtitles
cue_index → subtitle_index
current_cue() → current_subtitle()
cues → subtitles
"collect N cues" → "collect N subtitle events"
"a cue is accepted" → "a subtitle event is accepted"
|
some suggestions:
|
|
Okay, I'll try to understand what's happening and maybe there's a way to split this merge request |
|
There's also an option of not merging this mr, I can just keep it in my fork since I understand that any extra code is a maintenance burden |
|
You could probably ask an LLM chatbot to refactor the code. These days they can write code better than humans if you direct them properly, but they can also write shitty code that is unreadable and full of issues. |
Why
The subtitle observer only knows secondary cues that mpv has already displayed. If the selected primary subtitle window extends beyond the current playback position, later secondary cues that overlap that window are missing from both the card and its OSD preview.
What changed
sub-step 1 secondaryinstead of parsing or extracting the subtitle track.secondary-sub-delayandaudio-delay.secondary-sub-delayafter lookahead, including when stepping fails.This performs no file I/O and launches no subprocess. For embedded tracks, lookahead is naturally limited to cues inside mpv's subtitle prefetch range.
Verification
luajit tests/run.lua