Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(local): implement support for SponsorBlock and DeArrow #7195

Merged
merged 3 commits into from
Mar 16, 2025

Conversation

FineFindus
Copy link
Contributor

Implements support for SponsorBlock and DeArrow when using the full local mode.

Please note that I was unable to confirm that DeArrow works correctly, as neither the local nor the Piped API worked, so I'm assuming it is an external failure.

Closes: #7193

According to the SponsorBlock API documentation categories and
actionTypes are string arrays.
Allows users to use SponsorBlock when using full local mode.

Closes: libre-tube#7193
.toHexString()

return RetrofitInstance.externalApi.getSegments(
hashedId.substring(0..4),
Copy link
Member

Choose a reason for hiding this comment

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

substring(0..4) would be hashedId[0]...hashedId[4] (5 chars), while below you used substring(0, 4) which excludes hashedId[4]. Probably a typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just me being used to Rust Ranges :)

): SegmentData {
// use hashed video id for privacy
// https://wiki.sponsor.ajay.app/w/API_Docs#GET_/api/skipSegments/:sha256HashPrefix
val hashedId = MessageDigest.getInstance("SHA-256")
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer moving the hashing function to a helper method since its implementation details are unrelated to the logic of this method, it could even make sense to create an extension function String.sha256sum().

value.copy(
thumbnails = value.thumbnails.map { thumbnail ->
thumbnail.takeIf { it.original } ?: thumbnail.copy(
thumbnail = "https://dearrow-thumb.ajay.app/api/v1/getThumbnail?videoID=$videoId&time=${thumbnail.timestamp}"
Copy link
Member

Choose a reason for hiding this comment

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

Please put the base url to a constant.

val hashedId = digest
.digest(videoId.toByteArray())
.toHexString()
RetrofitInstance.externalApi.getDeArrowContent(
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should use runCatching here because if one chunk of data fails to load (for whatever reasons, e.g. ratelimits), we could still display the results from the other requests.

Copy link
Member

@Bnyro Bnyro left a comment

Choose a reason for hiding this comment

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

Thank you!

@Bnyro Bnyro merged commit 69c4ab8 into libre-tube:master Mar 16, 2025
2 checks passed
@FineFindus FineFindus deleted the feat/local-sb branch March 16, 2025 16:04
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.

Sponsor Block is not working in "FULL LOCAL MODE"
2 participants