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