Skip to content

feat: add SponsorBlock segments as chapters to downloaded YouTube videos - #129

Open
Anderinfera wants to merge 1 commit into
InfinityLoop1308:devfrom
Anderinfera:feat/sponsorblock-download-chapters
Open

Anderinfera wants to merge 1 commit into
InfinityLoop1308:devfrom
Anderinfera:feat/sponsorblock-download-chapters

Conversation

@Anderinfera

@Anderinfera Anderinfera commented Nov 21, 2026 •

Copy link
Copy Markdown

Downloaded YouTube videos lose the SponsorBlock information, so a sponsor or intro can't be found or skipped in another player.

New switch in Settings -> SponsorBlock, "Add chapters to downloads" (off by default, disabled when SponsorBlock is off).
When it is on, a finished MP4 or WebM download from YouTube gets a chapter for each SponsorBlock segment, e.g. [SponsorBlock] sponsor, and the rest of the video becomes plain "Video" chapters. Overlapping segments are split into separate chapters.

How it works:

  • After the download (and its post-processing) is finished, the segments are fetched from the same SponsorBlock API the player uses. Only the first 4 characters of the video id's SHA-256 hash are sent.
  • FFmpeg copies the streams into a new file with the chapters, without encoding again.
  • The new file replaces the download only after it has the expected number of chapters, the same duration (±1 s) and identical streams (an FFmpeg hash per stream matches the original). Any failure before that leaves the download unchanged. No segments, or no network, means no chapters.
  • If the app is killed while the download is being replaced, the replacement is finished from the temporary file when the download is resumed.

Validation:

  • ./gradlew assembleDebug builds against PipePipeExtractor e9818f8e.
  • Checked on a phone: with the switch off a download has no chapters, with it on the downloaded video shows the SponsorBlock chapters in another player.

New switch in Settings > SponsorBlock, "Add chapters to downloads" (off by
default). When it is on, a finished MP4 or WebM download from YouTube gets
chapters for its SponsorBlock segments, without encoding the video again.
Overlapping segments are split, the rest of the video becomes plain
"Video" chapters.

The download is only replaced once the new file's streams, duration and
chapters check out. Any failure before that leaves the download as it was.
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

Successfully merging this pull request may close these issues.

1 participant