changed video token handeling

This commit is contained in:
stratuma 2024-05-24 20:18:25 +02:00
parent 4cb0c59ccf
commit 7772693134

View File

@ -453,6 +453,8 @@ export async function crunchyGetPlaylist(q: string, geo: string | undefined) {
data.geo = geo
playlist = data
deleteVideoToken(q, playlist.token)
} else {
const error = await response.text()
const errorJSON: {
@ -502,9 +504,7 @@ export async function crunchyGetPlaylist(q: string, geo: string | undefined) {
throw new Error(e as string)
}
if (isProxyActive) await deleteVideoToken(q, playlist.token)
decrementPlaylistCounter()
if (isProxyActive) {
for (const p of proxies) {
if (p.code !== login.country) {
await incrementPlaylistCounter()
@ -554,7 +554,7 @@ export async function crunchyGetPlaylist(q: string, geo: string | undefined) {
}
}
await deleteVideoToken(q, dataProx.token)
deleteVideoToken(q, dataProx.token)
} else {
decrementPlaylistCounter()
const error = await responseProx.text()
@ -577,7 +577,7 @@ export async function crunchyGetPlaylist(q: string, geo: string | undefined) {
if (errorJSON && errorJSON.activeStreams && errorJSON.activeStreams.length !== 0) {
for (const e of errorJSON.activeStreams) {
await deleteVideoToken(e.contentId, e.token)
deleteVideoToken(e.contentId, e.token)
}
server.logger.log({
@ -591,10 +591,7 @@ export async function crunchyGetPlaylist(q: string, geo: string | undefined) {
}
}
}
await incrementPlaylistCounter()
await activateVideoToken(q, playlist.token)
}
return { data: playlist, account_id: login.account_id }
}
@ -630,6 +627,7 @@ export async function removeVideoToken(content: string, token: string) {
return 'ok'
} else {
decrementPlaylistCounter()
const error = await response.text()
// messageBox('error', ['Cancel'], 2, 'Failed to delete Crunchyroll Video Token', 'Failed to delete Crunchyroll Video Token', error)
server.logger.log({
@ -675,6 +673,7 @@ export async function deleteVideoToken(content: string, token: string) {
return 'ok'
} else {
decrementPlaylistCounter()
const error = await response.text()
// messageBox('error', ['Cancel'], 2, 'Failed to delete Crunchyroll Video Token', 'Failed to delete Crunchyroll Video Token', error)
server.logger.log({
@ -702,6 +701,7 @@ export async function activateVideoToken(content: string, token: string) {
Authorization: `Bearer ${login.access_token}`
}
await incrementPlaylistCounter()
const response = await fetch(`https://cr-play-service.prd.crunchyrollsvc.com/v1/token/${content}/${token}/keepAlive?playhead=1`, {
method: 'PATCH',
headers: headers
@ -716,8 +716,6 @@ export async function activateVideoToken(content: string, token: string) {
section: 'tokenDeletionCrunchyrollFetch'
})
decrementPlaylistCounter()
return 'ok'
} else {
const error = await response.text()
@ -757,6 +755,8 @@ export async function crunchyGetPlaylistMPD(q: string, geo: string | undefined)
const contentID = match[1]
const playlistID = match[2]
await activateVideoToken(contentID, playlistID)
try {
const response = await fetch(q, {
method: 'GET',
@ -764,7 +764,7 @@ export async function crunchyGetPlaylistMPD(q: string, geo: string | undefined)
})
if (response.ok) {
await deleteVideoToken(contentID, playlistID)
deleteVideoToken(contentID, playlistID)
const raw = await response.text()
const parsed = mpdParse(raw)
@ -780,7 +780,6 @@ export async function crunchyGetPlaylistMPD(q: string, geo: string | undefined)
if (errorJSON.error === 'Invalid streaming token') {
decrementPlaylistCounter()
await incrementPlaylistCounter()
await activateVideoToken(contentID, playlistID)
return await crunchyGetPlaylistMPD(q, geo)
}
@ -881,11 +880,11 @@ export async function checkAccountMaxStreams() {
if (!data.items || data.items.length === 0) return 1
if (data.items.find((i) => i.benefit === 'concurrent_streams.4')) return 2
if (data.items.find((i) => i.benefit === 'concurrent_streams.4')) return 4
if (data.items.find((i) => i.benefit === 'concurrent_streams.1')) return 1
if (data.items.find((i) => i.benefit === 'concurrent_streams.6')) return 3
if (data.items.find((i) => i.benefit === 'concurrent_streams.6')) return 6
return 1
} else {