refactor: use aiohttp for requests

This commit is contained in:
2025-01-22 14:49:29 -05:00
parent 640e750e3d
commit 8ef4c85bd8
3 changed files with 15 additions and 10 deletions

View File

@@ -1,21 +1,23 @@
import hashlib
import requests
import aiohttp
from state import sponsorblock_cache
def get_segments(videoId: str):
async def get_segments(videoId: str):
if videoId in sponsorblock_cache:
return sponsorblock_cache[videoId]
hashPrefix = hashlib.sha256(videoId.encode()).hexdigest()[:4]
response = requests.get(
session = aiohttp.ClientSession()
response = await session.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()))
if response.status == 200 and (
results := list(
filter(lambda v: videoId == v["videoID"], await response.json())
)
):
sponsorblock_cache[videoId] = results[0]
return results[0]