feat: add sponsorblock integration

Add the -S option to the fast forward command.
This commit is contained in:
2025-01-22 14:46:58 -05:00
parent 3ca58a4c19
commit 640e750e3d
4 changed files with 53 additions and 3 deletions

21
sponsorblock.py Normal file
View File

@@ -0,0 +1,21 @@
import hashlib
import requests
from state import sponsorblock_cache
def get_segments(videoId: str):
if videoId in sponsorblock_cache:
return sponsorblock_cache[videoId]
hashPrefix = hashlib.sha256(videoId.encode()).hexdigest()[:4]
response = requests.get(
f'https://sponsor.ajay.app/api/skipSegments/{hashPrefix}?categories=["music_offtopic"]'
)
print(response.text)
if response.status_code == 200 and (
results := list(filter(lambda v: videoId == v["videoID"], response.json()))
):
sponsorblock_cache[videoId] = results[0]
return results[0]