Use hash video for SponsorBlock
This commit is contained in:
1 parent
25b2ea7091
commit
386dfc1419
2 files changed
+19
-2
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
import "pkg:/source/roku_modules/rokurequests/Requests.brs"
|
import "pkg:/source/roku_modules/rokurequests/Requests.brs"
|
||||||
import "pkg:/source/utils/WebUtils.bs"
|
import "pkg:/source/utils/WebUtils.bs"
|
||||||
|
import "pkg:/source/utils/Crypto.bs"
|
||||||
|
|
||||||
namespace SponsorBlock
|
namespace SponsorBlock
|
||||||
const API_URL = "https://sponsor.ajay.app"
|
const API_URL = "https://sponsor.ajay.app"
|
||||||
@@ -11,11 +12,19 @@ namespace SponsorBlock
|
|||||||
|
|
||||||
categoriesJson = WebUtils.UrlEscape(FormatJson(categories))
|
categoriesJson = WebUtils.UrlEscape(FormatJson(categories))
|
||||||
actionTypesJson = WebUtils.UrlEscape(FormatJson(actionTypes))
|
actionTypesJson = WebUtils.UrlEscape(FormatJson(actionTypes))
|
||||||
url = `${SponsorBlock.API_URL}${SponsorBlock.SKIP_SEGMENT_ENDPOINT}?videoID=${videoId}&categories=${categoriesJson}&actionTypes=${actionTypesJson}`
|
|
||||||
|
' From SponsorBlock docs: It should be the first 4 - 32 characters (4 is recommended).
|
||||||
|
hashPrefix = GetSha256(videoId).Left(4)
|
||||||
|
url = `${SponsorBlock.API_URL}${SponsorBlock.SKIP_SEGMENT_ENDPOINT}/${hashPrefix}?categories=${categoriesJson}&actionTypes=${actionTypesJson}`
|
||||||
response = Requests().get(url)
|
response = Requests().get(url)
|
||||||
|
|
||||||
if response.statuscode = 200
|
if response.statuscode = 200
|
||||||
return response.json
|
results = response.json
|
||||||
|
for each item in results
|
||||||
|
if item.videoId = videoId
|
||||||
|
return item.segments
|
||||||
|
end if
|
||||||
|
end for
|
||||||
end if
|
end if
|
||||||
return invalid
|
return invalid
|
||||||
end function
|
end function
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
function GetSha256(input as string) as string
|
||||||
|
buffer = CreateObject("roByteArray")
|
||||||
|
buffer.FromAsciiString(input)
|
||||||
|
|
||||||
|
digest = CreateObject("roEVPDigest")
|
||||||
|
digest.Setup("sha256")
|
||||||
|
return digest.Process(buffer)
|
||||||
|
end function
|
||||||
Reference in new issue
Block a user