From b749f22ae9a4f235fd35ceaba3e4dfac2d8da8e9 Mon Sep 17 00:00:00 2001 From: stratuma Date: Wed, 22 May 2024 11:28:15 +0200 Subject: [PATCH] added switch endpoint fix --- .../routes/crunchyroll/crunchyroll.service.ts | 63 ++++++++++++++++--- 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/src/api/routes/crunchyroll/crunchyroll.service.ts b/src/api/routes/crunchyroll/crunchyroll.service.ts index edf7c80..1f1db17 100644 --- a/src/api/routes/crunchyroll/crunchyroll.service.ts +++ b/src/api/routes/crunchyroll/crunchyroll.service.ts @@ -16,6 +16,17 @@ const crErrors = [ // Crunchyroll Login Handler export async function crunchyLogin(user: string, passw: string, geo: string) { + + var endpoint = await settings.get('CREndpoint') + const drmL3blob = await settings.get('l3blob') + const drmL3key = await settings.get('l3key') + + if (!drmL3blob || !drmL3key) { + await settings.set('CREndpoint', 1) + endpoint = 1 + } + + const cachedData: | { access_token: string @@ -27,7 +38,7 @@ export async function crunchyLogin(user: string, passw: string, geo: string) { account_id: string profile_id: string } - | undefined = server.CacheController.get(`crtoken-${geo}`) + | undefined = server.CacheController.get(`crtoken-${geo}-${endpoint}`) if (!cachedData) { if (geo === 'LOCAL') { @@ -35,7 +46,7 @@ export async function crunchyLogin(user: string, passw: string, geo: string) { if (!data) return - server.CacheController.set(`crtoken-${geo}`, data, data.expires_in - 30) + server.CacheController.set(`crtoken-${geo}-${endpoint}`, data, data.expires_in - 30) return data } @@ -45,7 +56,7 @@ export async function crunchyLogin(user: string, passw: string, geo: string) { if (!data) return - server.CacheController.set(`crtoken-${geo}`, data, data.expires_in - 30) + server.CacheController.set(`crtoken-${geo}-${endpoint}`, data, data.expires_in - 30) return data } @@ -114,6 +125,23 @@ async function crunchyLoginFetchProxy(user: string, passw: string, geo: string) } } + if (endpoint === 1) { + headers = { + Authorization: 'Basic dC1rZGdwMmg4YzNqdWI4Zm4wZnE6eWZMRGZNZnJZdktYaDRKWFMxTEVJMmNDcXUxdjVXYW4=', + 'Content-Type': 'application/x-www-form-urlencoded', + 'User-Agent': 'Crunchyroll/1.8.0 Nintendo Switch/12.3.12.0 UE4/4.27' + } + + body = { + username: user, + password: passw, + grant_type: 'password', + scope: 'offline_access', + device_name: 'RMX2170', + device_type: 'realme RMX2170' + } + } + if (!headers || !body) return try { @@ -183,6 +211,23 @@ async function crunchyLoginFetch(user: string, passw: string) { } } + if (endpoint === 1) { + headers = { + Authorization: 'Basic dC1rZGdwMmg4YzNqdWI4Zm4wZnE6eWZMRGZNZnJZdktYaDRKWFMxTEVJMmNDcXUxdjVXYW4=', + 'Content-Type': 'application/x-www-form-urlencoded', + 'User-Agent': 'Crunchyroll/1.8.0 Nintendo Switch/12.3.12.0 UE4/4.27' + } + + body = { + username: user, + password: passw, + grant_type: 'password', + scope: 'offline_access', + device_name: 'RMX2170', + device_type: 'realme RMX2170' + } + } + if (!headers || !body) return try { @@ -328,7 +373,8 @@ export async function crunchyGetPlaylist(q: string, geo: string | undefined) { const headersLoc = { 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', } var playlist: VideoPlaylist @@ -379,7 +425,8 @@ export async function crunchyGetPlaylist(q: string, geo: string | undefined) { const headers = { 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', } const response = await fetch( @@ -434,7 +481,8 @@ export async function deleteVideoToken(content: string, token: string) { if (!login) return 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 { @@ -473,7 +521,8 @@ export async function crunchyGetPlaylistMPD(q: string, geo: string | undefined) if (!login) return 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 {