mirror of
https://github.com/FreeTubeApp/FreeTube
synced 2024-11-26 03:39:24 +01:00
Cleanup SponsorBlock video id hashing (#4384)
This commit is contained in:
parent
6af85b3726
commit
cb883f254f
@ -1,17 +1,17 @@
|
||||
import store from '../store/index'
|
||||
|
||||
async function getVideoHash(videoId) {
|
||||
const videoIdBuffer = new TextEncoder().encode(videoId)
|
||||
|
||||
const hashBuffer = await crypto.subtle.digest('SHA-256', videoIdBuffer)
|
||||
const hashArray = Array.from(new Uint8Array(hashBuffer))
|
||||
const hashArray = new Uint8Array(hashBuffer)
|
||||
|
||||
return hashArray
|
||||
.map(byte => byte.toString(16).padStart(2, '0'))
|
||||
.slice(0, 4)
|
||||
.join('')
|
||||
return hashArray[0].toString(16).padStart(2, '0') +
|
||||
hashArray[1].toString(16).padStart(2, '0')
|
||||
}
|
||||
|
||||
export async function sponsorBlockSkipSegments(videoId, categories) {
|
||||
const videoIdHashPrefix = (await getVideoHash(videoId)).substring(0, 4)
|
||||
const videoIdHashPrefix = await getVideoHash(videoId)
|
||||
const requestUrl = `${store.getters.getSponsorBlockUrl}/api/skipSegments/${videoIdHashPrefix}?categories=${JSON.stringify(categories)}`
|
||||
|
||||
try {
|
||||
@ -22,6 +22,11 @@ export async function sponsorBlockSkipSegments(videoId, categories) {
|
||||
return []
|
||||
}
|
||||
|
||||
// Sometimes the sponsor block server goes down or returns other errors
|
||||
if (!response.ok) {
|
||||
throw new Error(await response.text())
|
||||
}
|
||||
|
||||
const json = await response.json()
|
||||
return json
|
||||
.filter((result) => result.videoID === videoId)
|
||||
@ -33,7 +38,7 @@ export async function sponsorBlockSkipSegments(videoId, categories) {
|
||||
}
|
||||
|
||||
export async function deArrowData(videoId) {
|
||||
const videoIdHashPrefix = (await getVideoHash(videoId)).substring(0, 4)
|
||||
const videoIdHashPrefix = await getVideoHash(videoId)
|
||||
const requestUrl = `${store.getters.getSponsorBlockUrl}/api/branding/${videoIdHashPrefix}`
|
||||
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user