fixed video token deletion

This commit is contained in:
stratuma 2024-05-22 13:46:41 +02:00
parent b749f22ae9
commit c010bbc826

View File

@ -16,7 +16,6 @@ const crErrors = [
// Crunchyroll Login Handler // Crunchyroll Login Handler
export async function crunchyLogin(user: string, passw: string, geo: string) { export async function crunchyLogin(user: string, passw: string, geo: string) {
var endpoint = await settings.get('CREndpoint') var endpoint = await settings.get('CREndpoint')
const drmL3blob = await settings.get('l3blob') const drmL3blob = await settings.get('l3blob')
const drmL3key = await settings.get('l3key') const drmL3key = await settings.get('l3key')
@ -26,7 +25,6 @@ export async function crunchyLogin(user: string, passw: string, geo: string) {
endpoint = 1 endpoint = 1
} }
const cachedData: const cachedData:
| { | {
access_token: string access_token: string
@ -129,7 +127,7 @@ async function crunchyLoginFetchProxy(user: string, passw: string, geo: string)
headers = { headers = {
Authorization: 'Basic dC1rZGdwMmg4YzNqdWI4Zm4wZnE6eWZMRGZNZnJZdktYaDRKWFMxTEVJMmNDcXUxdjVXYW4=', Authorization: 'Basic dC1rZGdwMmg4YzNqdWI4Zm4wZnE6eWZMRGZNZnJZdktYaDRKWFMxTEVJMmNDcXUxdjVXYW4=',
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'Crunchyroll/1.8.0 Nintendo Switch/12.3.12.0 UE4/4.27' 'User-Agent': 'Crunchyroll/3.46.2 Android/13 okhttp/4.12.0'
} }
body = { body = {
@ -194,38 +192,19 @@ async function crunchyLoginFetch(user: string, passw: string) {
endpoint = 1 endpoint = 1
} }
if (endpoint !== 1 && drmL3blob && drmL3key) { headers = {
headers = { Authorization: 'Basic dC1rZGdwMmg4YzNqdWI4Zm4wZnE6eWZMRGZNZnJZdktYaDRKWFMxTEVJMmNDcXUxdjVXYW4=',
Authorization: 'Basic dm52cHJyN21ubW1la2Uyd2xwNTM6V19IdWlNekxUS1JqSnlKZTBHRlFYZXFoTldDREdUM2M=', 'Content-Type': 'application/x-www-form-urlencoded',
'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'Crunchyroll/3.46.2 Android/13 okhttp/4.12.0'
'User-Agent': 'Crunchyroll/4.51.0 (bundle_identifier:com.crunchyroll.iphone; build_number:3634220.454824296) iOS/17.4.1 Gravity/4.51.0'
}
body = {
username: user,
password: passw,
grant_type: 'password',
scope: 'offline_access',
device_name: 'iPhone',
device_type: 'iPhone 13'
}
} }
if (endpoint === 1) { body = {
headers = { username: user,
Authorization: 'Basic dC1rZGdwMmg4YzNqdWI4Zm4wZnE6eWZMRGZNZnJZdktYaDRKWFMxTEVJMmNDcXUxdjVXYW4=', password: passw,
'Content-Type': 'application/x-www-form-urlencoded', grant_type: 'password',
'User-Agent': 'Crunchyroll/1.8.0 Nintendo Switch/12.3.12.0 UE4/4.27' scope: 'offline_access',
} device_name: 'RMX2170',
device_type: 'realme RMX2170'
body = {
username: user,
password: passw,
grant_type: 'password',
scope: 'offline_access',
device_name: 'RMX2170',
device_type: 'realme RMX2170'
}
} }
if (!headers || !body) return if (!headers || !body) return
@ -374,7 +353,8 @@ export async function crunchyGetPlaylist(q: string, geo: string | undefined) {
const headersLoc = { const headersLoc = {
Authorization: `Bearer ${login.access_token}`, Authorization: `Bearer ${login.access_token}`,
'X-Cr-Disable-Drm': 'true', 'X-Cr-Disable-Drm': 'true',
'User-Agent': 'Crunchyroll/1.8.0 Nintendo Switch/12.3.12.0 UE4/4.27', 'x-cr-stream-limits': 'true',
'User-Agent': 'Crunchyroll/1.8.0 Nintendo Switch/12.3.12.0 UE4/4.27'
} }
var playlist: VideoPlaylist var playlist: VideoPlaylist
@ -402,11 +382,36 @@ export async function crunchyGetPlaylist(q: string, geo: string | undefined) {
playlist = data playlist = data
} else { } else {
const error = await response.text() const error = await response.text()
const errorJSON: {
activeStreams: {
accountId: string,
active: boolean,
assetId: string,
clientId: string,
contentId: string,
country: string,
createdTimestamp: string,
deviceSubtype: string,
deviceType: string,
episodeIdentity: string,
id: string,
token: string
}[]
} = await JSON.parse(error)
if (errorJSON && errorJSON.activeStreams && errorJSON.activeStreams.length !== 0) {
for (const e of errorJSON.activeStreams) {
await deleteVideoToken(e.contentId, e.token)
}
return await crunchyGetPlaylist(q, geo)
}
messageBox('error', ['Cancel'], 2, 'Failed to get Crunchyroll Video Playlist', 'Failed to get Crunchyroll Video Playlist', error) messageBox('error', ['Cancel'], 2, 'Failed to get Crunchyroll Video Playlist', 'Failed to get Crunchyroll Video Playlist', error)
server.logger.log({ server.logger.log({
level: 'error', level: 'error',
message: 'Failed to get Crunchyroll Video Playlist', message: 'Failed to get Crunchyroll Video Playlist',
error: error, error: errorJSON,
timestamp: new Date().toISOString(), timestamp: new Date().toISOString(),
section: 'playlistCrunchyrollFetch' section: 'playlistCrunchyrollFetch'
}) })
@ -426,7 +431,7 @@ export async function crunchyGetPlaylist(q: string, geo: string | undefined) {
const headers = { const headers = {
Authorization: `Bearer ${logindata.access_token}`, Authorization: `Bearer ${logindata.access_token}`,
'X-Cr-Disable-Drm': 'true', 'X-Cr-Disable-Drm': 'true',
'User-Agent': 'Crunchyroll/1.8.0 Nintendo Switch/12.3.12.0 UE4/4.27', 'User-Agent': 'Crunchyroll/1.8.0 Nintendo Switch/12.3.12.0 UE4/4.27'
} }
const response = await fetch( const response = await fetch(
@ -481,32 +486,34 @@ export async function deleteVideoToken(content: string, token: string) {
if (!login) return if (!login) return
const headers = { const headers = {
Authorization: `Bearer ${login.access_token}`, Authorization: `Bearer ${login.access_token}`
'User-Agent': 'Crunchyroll/1.8.0 Nintendo Switch/12.3.12.0 UE4/4.27',
} }
try { const response = await fetch(`https://cr-play-service.prd.crunchyrollsvc.com/v1/token/${content}/${token}/inactive`, {
const response = await fetch(`https://cr-play-service.prd.crunchyrollsvc.com/v1/token/${content}/${token}`, { method: 'PATCH',
method: 'DELETE', headers: headers
headers: headers })
})
if (response.ok) { if (response.ok) {
return 'ok' server.logger.log({
} else { level: 'info',
const error = await response.text() message: 'Deleted Video Token',
messageBox('error', ['Cancel'], 2, 'Failed to delete Crunchyroll Video Token', 'Failed to delete Crunchyroll Video Token', error) token: token,
server.logger.log({ timestamp: new Date().toISOString(),
level: 'error', section: 'tokenDeletionCrunchyrollFetch'
message: 'Failed to delete Crunchyroll Video Token', })
error: error, return 'ok'
timestamp: new Date().toISOString(), } else {
section: 'tokenDeletionCrunchyrollFetch' const error = await response.text()
}) // messageBox('error', ['Cancel'], 2, 'Failed to delete Crunchyroll Video Token', 'Failed to delete Crunchyroll Video Token', error)
throw new Error(await response.text()) server.logger.log({
} level: 'error',
} catch (e) { message: 'Failed to delete Crunchyroll Video Token',
throw new Error(e as string) token: token,
error: error,
timestamp: new Date().toISOString(),
section: 'tokenDeletionCrunchyrollFetch'
})
} }
} }
@ -522,7 +529,7 @@ export async function crunchyGetPlaylistMPD(q: string, geo: string | undefined)
const headers = { const headers = {
Authorization: `Bearer ${login.access_token}`, Authorization: `Bearer ${login.access_token}`,
'User-Agent': 'Crunchyroll/1.8.0 Nintendo Switch/12.3.12.0 UE4/4.27', 'User-Agent': 'Crunchyroll/1.8.0 Nintendo Switch/12.3.12.0 UE4/4.27'
} }
try { try {