animebook / animebook.github.io

In-browser video player for learning Japanese with subtitles
https://animebook.github.io
MIT License
268 stars 30 forks source link

Fixing Most Kitsunekko Subs #12

Closed sihue closed 3 years ago

sihue commented 3 years ago

This issue is related to #6. Therein, a number of problems were mentioned that called into question usefulness of such a feature. The least significant of which, I think, is that of different file formats. In my view, it is perfectly acceptable to offer only one file format (e.g. .srt) and even to only export the lines that are seen in animebook. (Get what you see.) I've implemented a naive downlowd option which grabs all captions. Try it here: index-dl.txt (rename to .html, shortcut is Crtl + Alt + d)

But the another, more significant, problem is that subtitles can have more than one mistimed section. Subtitles on kitsunekko may look something like this: |--a-----b-c---d-e-----f--| (kitsunekko/TV) |-(-a---)--(b-c-)--(d-e---)--(f-)-| ((..) correctly timed sections) |-a---b-c-d-e---f-| (correct timings) (letters are subtitles, dashes op/ed/ad/speech breaks).

In this case (by far the most common) it would be useful to only offset the selected caption and the ones after it. Something like this apparently exists in PotPlayer where you can fetch all remaining lines and retime them such that the next line starts now (shortcut Crtl + Alt + >). What makes this feature so powerful is that it is fast and safe. You only ever change captions you haven't encounterd yet, as the once before have all been correct (you would have changed them otherwise). This means the scenario of hanving inadvertently changed the beginning upon reaching the end (as described in #6) would never manifest. In my experience, using seperate programs is slow and distracting. In the case of scripts, it may even be inaccurate.

Basically it should work like this: moveRemainingCaptionsToHere: function () {  var i = 0;  var last = this.captions.length - 1;  while (i < last && this.captions[i].endTime < this.currentTime)   i++;  if (i === last)   return;  var diff = this.captions[i].startTime - this.currentTime;  while (i <= last) {   this.captions[i].startTime -= diff;   this.captions[i].endTime -= diff;   i++;  }  return; } Using this code sort of works, but it obviously breaks other parts of the site, most notably the sidebar and displaying of subtitles. Downloading with the above method and dragging it in once more works, but that is not a very elegant hack. You can play around with it here: index-test.txt (rename to .html, shortcut is Crtl + Alt + v)

The interface of animebook suggests a somewhat more flexible but also more complicated solution that works like Offset Mode. You would select the caption that is supposed to end at the current position and only move the remaining captions alongside it. 3 cases: i.) current time is before startTime of selected caption ii.) current time is inbetween startTime and endTime iii.) current time is after endTime

i.) If the selected caption is not the next, there will be overlapping captions that require handling. Most probably, the inbetween-lines would be unwanted. ii.) Caption moves toward the beginning by a bit. There could be an overlap. iii.) The simplest case, as you can't really break anything by moving the captions toward the end.

The main issue, of course, is that the offset functionality is already implemented, and while you could reuse most functionality by simply skipping the first indices, the changes would touch many different parts of the code. To make all changes traceable, you'd probably need an array with one offset per caption, just to give an example. For any given line the offset would then be the offsets that came before, the global offset would be the first in the array.

I can't really say how much work would be required overall, but for the simple job it is supposed to provide, it seems a bit much. Just to be complete, though, here are two scenarios where it would be useful to be able to select a caption other than the next: 1) There is a big gap in the subtitles (ad break) and the next caption is a music note/noise desctiption/ad transcription/etc. 2) You moved the captions a bit too far to the front and want to fix that.

A smaller scale solution to 1) would be to delete/hide single captions and then only download the seen captions. With that, even subs like the following would be fixable: |-g-a--g-g--b-c---d-e-----f--| (g = garbage) |-a---b-c-d-e---f-| (correct timings) As for 2), maybe a simple 1-step-undo would already be enough.

I think there is a use for this feature that is specific enough to the target audience of animebook to be included in the project. At the same time, it probably doesn't warrant any drastic changes. At least mimicking the feature of PotPlayer would be nice, though. Nobody should have to use a bloated piece of software, if all they want to do is fixing their subtitles while watching anime. :)

Looking forward to your feedback.

soamsy commented 3 years ago

Sorry for the late response. I like the idea, and I've been working on a way to make the PotPlayer-like workflow work with the web app. It's basically what you're suggesting, but I want to take advantage of the sidebar to show where to offsets are being applied and offer the user a way to edit them. Best way to see it is in a demo, https://streamable.com/3g4l8d Note: I'm still tweaking and testing it, but this is the direction I'm planning on going with it.

I admittedly didn't think you could do something like this when I closed the previous case. I don't mind making a few concessions on the other arguments I had there if generalized re-timing can be done.

I also don't really like ctrl or alt hotkeys, since the browser or extensions might conflict with them, so I'm going to change the download hotkey to 'Shift D' instead. This seems intuitive enough to me without being easy to accidentally hit.

sihue commented 3 years ago

Looks great! Being able to edit the value after the fact, in particular, is appreciated.

On the hotkeys, I have no attachment whatsoever, so please change them freely. In general, the download function could be cleaned up just a tad. For now, the index starts at 0 when the default for srt seems to be 1 and garbage lines up front can underflow to 23:59.xx because of the date format used. The srt-format appears to handle both just fine, though.

soamsy commented 3 years ago

Thanks for the heads up. I cleaned up the download function.

This is also deployed now if you want to try it out. Let me know if you something about it that's broken.

sihue commented 3 years ago

Thanks for your effort. Works great so far.