Get all sponsorblock segment types (testing) (#1021)

* Pull all sponsorblock segment types

* Respect segment skip on `segment.actionType`

* Lint with `prettier`

* Lint with `black`
This commit is contained in:
Atinoda 2025-08-11 09:06:12 +01:00 committed by GitHub
parent dc26354020
commit bcb216d862
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 4 deletions

View File

@ -48,11 +48,28 @@ class SponsorBlock:
def get_timestamps(self, youtube_id):
"""get timestamps from the API"""
url = f"{self.API}/skipSegments?videoID={youtube_id}"
url = f"{self.API}/skipSegments"
headers = {"User-Agent": self.user_agent}
categories = [
"sponsor",
"selfpromo",
"interaction",
"intro",
"outro",
"preview",
"music_offtopic",
"poi_highlight",
"filler",
]
params = {
"videoID": youtube_id,
"category": categories,
}
print(f"{youtube_id}: get sponsorblock timestamps")
try:
response = requests.get(url, headers=headers, timeout=10)
response = requests.get(
url, headers=headers, params=params, timeout=10
)
except (requests.ReadTimeout, requests.ConnectionError) as err:
print(f"{youtube_id}: sponsorblock API error: {str(err)}")
return False
@ -75,9 +92,17 @@ class SponsorBlock:
def _get_sponsor_dict(self, all_segments):
"""format and process response"""
_ = [i.pop("description", None) for i in all_segments]
has_unlocked = not any(i.get("locked") for i in all_segments)
# Set only sponsor to skip (retain legacy behaviour)
categories_skip = ["sponsor"]
for segment in all_segments:
segment_category = segment["category"]
if segment_category in categories_skip:
segment["actionType"] = "skip"
else:
segment["actionType"] = "none"
sponsor_dict = {
"last_refresh": self.last_refresh,
"has_unlocked": has_unlocked,

View File

@ -70,9 +70,11 @@ const handleTimeUpdate =
if (sponsorBlock && sponsorBlock.segments) {
sponsorBlock.segments.forEach((segment: SponsorBlockSegmentType) => {
const actionType = segment.actionType;
const doSkip = actionType == 'skip';
const [from, to] = segment.segment;
if (currentTime >= from && currentTime <= from + 0.3) {
if (doSkip && currentTime >= from && currentTime <= from + 0.3) {
videoTag.currentTarget.currentTime = to;
setSponsorSegmentSkipped?.((segments: SponsorSegmentsSkippedType) => {