Skip to content

Commit

Permalink
fix(YouTube - SponsorBlock): Do not auto skip end segments more than …
Browse files Browse the repository at this point in the history
…once if using a slow playback speed
  • Loading branch information
LisoUseInAIKyrios committed Dec 25, 2023
1 parent 5ae2312 commit 88b3ca4
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -510,15 +510,18 @@ private static void skipSegment(@NonNull SponsorSegment segmentToSkip, boolean u
SponsorBlockViewController.hideSkipHighlightButton();
SponsorBlockViewController.hideSkipSegmentButton();

// If trying to seek to end of the video, YouTube can seek just before of the actual end.
// (especially if the video does not end on a whole second boundary).
// This causes additional segment skip attempts, even though it cannot seek any closer to the desired time.
// Check for and ignore repeated skip attempts of the same segment over a small time period.
final long now = System.currentTimeMillis();
final long minimumMillisecondsBetweenSkippingSameSegment = 500;
if ((lastSegmentSkipped == segmentToSkip) && (now - lastSegmentSkippedTime < minimumMillisecondsBetweenSkippingSameSegment)) {
LogHelper.printDebug(() -> "Ignoring skip segment request (already skipped as close as possible): " + segmentToSkip);
return;
if (lastSegmentSkipped == segmentToSkip) {
// If trying to seek to end of the video, YouTube can seek just before of the actual end.
// (especially if the video does not end on a whole second boundary).
// This causes additional segment skip attempts, even though it cannot seek any closer to the desired time.
// Check for and ignore repeated skip attempts of the same segment over a small time period.
final long minTimeBetweenSkippingSameSegment = Math.max(500,
(long) (500 / VideoInformation.getPlaybackSpeed()));
if (now - lastSegmentSkippedTime < minTimeBetweenSkippingSameSegment) {
LogHelper.printDebug(() -> "Ignoring skip segment request (already skipped as close as possible): " + segmentToSkip);
return;
}
}

LogHelper.printDebug(() -> "Skipping segment: " + segmentToSkip);
Expand Down

4 comments on commit 88b3ca4

@johnconner122
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It still skips outro-segments multiple times, even on normal speed.

@LisoUseInAIKyrios
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's caused by the newly added 250ms offset fix in VideoInformation, where it's moving the skip time back to before the current playback time. I'll make a fix shortly.

@LisoUseInAIKyrios
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In one of the recent YT updates the video time hook can now be called with a time that is slightly behind the previous playback time:

revanced: SegmentPlaybackController: setVideoTime: 281993
revanced: SegmentPlaybackController: setVideoTime: 281600
revanced: SegmentPlaybackController: setVideoTime: 282408
revanced: SegmentPlaybackController: setVideoTime: 283409

I just made a change and I think any issues with repeated skip attempts should be fixed.

@oSumAtrIX
Copy link
Member

@oSumAtrIX oSumAtrIX commented on 88b3ca4 Dec 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current time can be hooked where SponsorBlock is being injected. This place draws the seekbar and specifically the code responsible for drawing the knob (current time) can be used. Alternatively the current time text view can be traced back to the method that calls it with the current time. It'll be important to see if these timers work when YouTube is minimized and similar though

Please sign in to comment.