added video token activation and invalidation

This commit is contained in:
stratuma 2024-05-24 01:46:46 +02:00
parent 1db7b8f6ff
commit 0e9e3080f1
3 changed files with 106 additions and 9 deletions

View File

@ -131,11 +131,11 @@
<div class="text-xs">Dubs: {{ p.dub.map((t) => t.name).join(', ') }}</div>
<div class="text-xs mr-20">Subs: {{ p.sub.length !== 0 ? p.sub.map((t) => t.name).join(', ') : '-' }}</div>
<div class="absolute flex flex-col ml-auto gap-0.5 right-0 bottom-0">
<div v-if="p.totaldownloaded && p.status === 'downloading'" class="text-xs ml-auto"
<div v-if="p.totaldownloaded && p.status === 'downloading' || p.totaldownloaded && p.status === 'downloading video'" class="text-xs ml-auto"
>{{ (p.totaldownloaded / Math.pow(1024, 2)).toFixed(2) }} MB</div
>
<div v-if="p.partsleft && p.status === 'downloading'" class="text-xs ml-auto">{{ p.partsdownloaded }}/{{ p.partsleft }}</div>
<div v-if="p.downloadspeed && p.status === 'downloading'" class="text-xs ml-auto">{{ p.downloadspeed }} MB/s</div>
<div v-if="p.partsleft && p.status === 'downloading' || p.totaldownloaded && p.status === 'downloading video'" class="text-xs ml-auto">{{ p.partsdownloaded }}/{{ p.partsleft }}</div>
<div v-if="p.downloadspeed && p.status === 'downloading' || p.totaldownloaded && p.status === 'downloading video'" class="text-xs ml-auto">{{ p.downloadspeed }} MB/s</div>
</div>
<button @click="openFolder(p.installDir)" v-if="p.status === 'completed'" class="ml-auto h-9 w-9 hover:bg-[#ffffff2c] rounded-xl transition-all">
<Icon name="ph:folder-open" class="h-5 w-5 text-white" />

View File

@ -503,8 +503,15 @@ export async function crunchyGetPlaylist(q: string, geo: string | undefined) {
}
if (isProxyActive)
await deactivateVideoToken(q, playlist.token)
decrementPlaylistCounter()
for (const p of proxies) {
if (p.code !== login.country) {
await incrementPlaylistCounter()
const logindata = await crunchyLogin(account.username, account.password, p.code)
if (!logindata) return
@ -515,8 +522,6 @@ export async function crunchyGetPlaylist(q: string, geo: string | undefined) {
'User-Agent': 'Crunchyroll/1.8.0 Nintendo Switch/12.3.12.0 UE4/4.27'
}
await incrementPlaylistCounter()
const responseProx = await fetch(
`https://cr-play-service.prd.crunchyrollsvc.com/v1/${q}${
endpoints.find((e) => e.id === endpoint) ? endpoints.find((e) => e.id === endpoint)?.url : '/console/switch/play'
@ -590,6 +595,9 @@ export async function crunchyGetPlaylist(q: string, geo: string | undefined) {
}
}
await incrementPlaylistCounter()
await activateVideoToken(q, playlist.token)
return { data: playlist, account_id: login.account_id }
}
@ -638,6 +646,96 @@ export async function deleteVideoToken(content: string, token: string) {
}
}
// Crunchyroll Deactivate Video Token Fetch
export async function deactivateVideoToken(content: string, token: string) {
const account = await loggedInCheck('CR')
if (!account) return
const login = await crunchyLogin(account.username, account.password, 'LOCAL')
if (!login) return
const headers = {
Authorization: `Bearer ${login.access_token}`
}
const response = await fetch(`https://cr-play-service.prd.crunchyrollsvc.com/v1/token/${content}/${token}/inactive`, {
method: 'PATCH',
headers: headers
})
if (response.ok) {
server.logger.log({
level: 'info',
message: 'Disabled Video Token',
token: token,
timestamp: new Date().toISOString(),
section: 'tokenDeletionCrunchyrollFetch'
})
decrementPlaylistCounter()
return 'ok'
} else {
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({
level: 'error',
message: 'Failed to disable Crunchyroll Video Token',
token: token,
error: error,
timestamp: new Date().toISOString(),
section: 'tokenDisabelingCrunchyrollFetch'
})
}
}
// Crunchyroll Activate Video Token Fetch
export async function activateVideoToken(content: string, token: string) {
const account = await loggedInCheck('CR')
if (!account) return
const login = await crunchyLogin(account.username, account.password, 'LOCAL')
if (!login) return
const headers = {
Authorization: `Bearer ${login.access_token}`
}
const response = await fetch(`https://cr-play-service.prd.crunchyrollsvc.com/v1/token/${content}/${token}/keepAlive?playhead=1`, {
method: 'PATCH',
headers: headers
})
if (response.ok) {
server.logger.log({
level: 'info',
message: 'Activated Video Token',
token: token,
timestamp: new Date().toISOString(),
section: 'tokenDeletionCrunchyrollFetch'
})
decrementPlaylistCounter()
return 'ok'
} else {
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({
level: 'error',
message: 'Failed to activate Crunchyroll Video Token',
token: token,
error: error,
timestamp: new Date().toISOString(),
section: 'tokenActivationCrunchyrollFetch'
})
}
}
// Crunchyroll MPD Fetch
export async function crunchyGetPlaylistMPD(q: string, geo: string | undefined) {
const account = await loggedInCheck('CR')

View File

@ -79,7 +79,6 @@ async function fetchAndPipe(url: string, stream: fs.WriteStream, index: number,
const response = await fetch(url)
// Check if fetch was successful
if (!response.ok) {
if (dn) {
dn.status = 'failed'
@ -97,7 +96,6 @@ async function fetchAndPipe(url: string, stream: fs.WriteStream, index: number,
const body = response.body
// Check if the body exists and is readable
if (!body) {
if (dn) {
dn.status = 'failed'
@ -140,13 +138,14 @@ async function fetchAndPipe(url: string, stream: fs.WriteStream, index: number,
} catch (error) {
server.logger.log({
level: 'error',
message: 'Error while downloading an Audio Fragment',
message: 'Error while downloading an Audio Fragment, retrying',
fragment: index,
error: error,
timestamp: new Date().toISOString(),
section: 'audiofragmentCrunchyrollFetch'
})
throw error
console.error(`Retrying fragment ${index} due to error:`, error)
await new Promise(resolve => setTimeout(resolve, 1000))
}
}