2026-02-15 17:44:53 +05:00
|
|
|
import { execSync } from 'node:child_process';
|
|
|
|
|
import { join } from 'node:path';
|
|
|
|
|
import { readdir, readFile, writeFile, rm } from 'node:fs/promises';
|
|
|
|
|
import { existsSync } from 'node:fs';
|
|
|
|
|
import { download } from 'molnia';
|
2025-03-26 13:19:45 +05:00
|
|
|
|
2025-08-23 23:49:07 +05:00
|
|
|
const downloadMobileApk = async () => {
|
2025-08-24 10:26:32 +05:00
|
|
|
const url = 'https://api.qqaoop.com/v11/apps/com.crunchyroll.crunchyroid/download?userId=1';
|
|
|
|
|
const filepath = join(process.cwd(), 'crunchyroll.apk');
|
2025-08-23 21:14:56 +05:00
|
|
|
await download(url, {
|
|
|
|
|
output: filepath,
|
|
|
|
|
onError: (error) => console.error(error),
|
|
|
|
|
});
|
|
|
|
|
return filepath;
|
2025-03-26 13:19:45 +05:00
|
|
|
};
|
|
|
|
|
|
2025-08-23 23:49:07 +05:00
|
|
|
const downloadTvApk = async () => {
|
2026-02-08 14:00:56 +05:00
|
|
|
const searchParams = new URLSearchParams();
|
|
|
|
|
searchParams.append('query', 'crunchyroll');
|
|
|
|
|
searchParams.append('cdn', 'web');
|
|
|
|
|
searchParams.append('q', 'bXlDUFU9YXJtNjQtdjhhLGFybWVhYmktdjdhLGFybWVhYmkmbGVhbmJhY2s9MA');
|
|
|
|
|
searchParams.append('aab', '1');
|
|
|
|
|
const searchUrl = `https://ws2-cache.aptoide.com/api/7/apps/search?${searchParams.toString()}`;
|
|
|
|
|
const searchResults = await fetch(searchUrl).then((r) => r.json());
|
|
|
|
|
const id = searchResults.datalist?.list?.[0]?.id;
|
|
|
|
|
if (!id) {
|
|
|
|
|
console.error('Unable to find ID for TV APK');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-08-23 23:49:07 +05:00
|
|
|
const source = 'https://webservices.aptoide.com/webservices/3/getApkInfo';
|
2025-11-04 19:48:37 +05:00
|
|
|
const body = new FormData();
|
2026-02-08 14:00:56 +05:00
|
|
|
body.append('identif', `id:${id}`);
|
2025-11-04 19:48:37 +05:00
|
|
|
body.append('mode', 'json');
|
|
|
|
|
const response = await fetch(source, { method: 'POST', body });
|
2025-08-23 23:49:07 +05:00
|
|
|
const json = await response.json();
|
|
|
|
|
const url = json.apk.path;
|
|
|
|
|
const filepath = join(process.cwd(), 'crunchyroll.apk');
|
|
|
|
|
await download(url, {
|
|
|
|
|
output: filepath,
|
|
|
|
|
onError: (error) => console.error(error),
|
|
|
|
|
});
|
|
|
|
|
return filepath;
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-26 13:19:45 +05:00
|
|
|
const decompileApk = (apkPath) => {
|
|
|
|
|
try {
|
|
|
|
|
execSync(`jadx ${apkPath}`, { stdio: 'inherit' });
|
2025-03-27 18:23:20 +05:00
|
|
|
} catch (error) {}
|
2025-08-23 23:49:07 +05:00
|
|
|
return apkPath.replace('.xapk', '').replace('.apk', '');
|
2025-03-26 13:19:45 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const findConfigurationImpl = async (sourcesDir) => {
|
|
|
|
|
const entries = await readdir(sourcesDir, { withFileTypes: true });
|
|
|
|
|
for (const entry of entries) {
|
|
|
|
|
if (!entry.isDirectory()) continue;
|
|
|
|
|
const moduleDir = join(sourcesDir, entry.name);
|
|
|
|
|
const moduleEntries = await readdir(moduleDir, { withFileTypes: true });
|
|
|
|
|
for (const moduleFile of moduleEntries) {
|
|
|
|
|
if (moduleFile.isDirectory()) continue;
|
|
|
|
|
const moduleFilePath = join(moduleDir, moduleFile.name);
|
|
|
|
|
const moduleContents = await readFile(moduleFilePath, 'utf8');
|
|
|
|
|
if (moduleContents.includes(' ConfigurationImpl.kt')) {
|
|
|
|
|
return moduleContents;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-23 23:49:07 +05:00
|
|
|
const parseCredentials = async (decompiledDir) => {
|
|
|
|
|
const sourcesDir = join(decompiledDir, 'sources');
|
|
|
|
|
const configurationImpl = await findConfigurationImpl(sourcesDir);
|
|
|
|
|
if (configurationImpl) {
|
|
|
|
|
const lines = configurationImpl.split('\n');
|
|
|
|
|
const startIndex = lines.findIndex((line) => line.includes('https://sso.crunchyroll.com'));
|
|
|
|
|
const endIndex = lines.findIndex((line) => line.includes('CR-AndroidMobile-SSAI-Prod'));
|
|
|
|
|
const results = lines
|
|
|
|
|
.slice(startIndex, endIndex)
|
|
|
|
|
.map((line) => line.replaceAll(';', ''))
|
|
|
|
|
.map((line) => line.replaceAll('"', ''))
|
|
|
|
|
.map((line) => line.split('= ')[1])
|
|
|
|
|
.map((line) => line.trim());
|
|
|
|
|
const [, , id, secret] = results;
|
|
|
|
|
if (id && secret) return { id, secret };
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-08 14:00:56 +05:00
|
|
|
const constantsPath = join(
|
|
|
|
|
decompiledDir,
|
|
|
|
|
'sources',
|
|
|
|
|
'com',
|
|
|
|
|
'crunchyroll',
|
|
|
|
|
'api',
|
|
|
|
|
'util',
|
|
|
|
|
'Constants.java',
|
|
|
|
|
);
|
2025-08-23 23:49:07 +05:00
|
|
|
const constants = await readFile(constantsPath, 'utf8');
|
|
|
|
|
return {
|
|
|
|
|
id: constants.split(' PROD_CLIENT_ID = "')[1].split('"')[0],
|
|
|
|
|
secret: constants.split(' PROD_CLIENT_SECRET = "')[1].split('"')[0],
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const parseVersion = async (decompiledDir) => {
|
|
|
|
|
const manifestJsonPath = join(decompiledDir, 'resources', 'manifest.json');
|
|
|
|
|
const manifestXmlPath = join(decompiledDir, 'resources', 'AndroidManifest.xml');
|
|
|
|
|
if (existsSync(manifestJsonPath)) {
|
2026-02-15 17:44:53 +05:00
|
|
|
const manifestContent = await readFile(manifestJsonPath, 'utf8');
|
|
|
|
|
const manifest = JSON.parse(manifestContent);
|
2025-08-23 23:49:07 +05:00
|
|
|
const version = `${manifest.version_name} (${manifest.version_code})`;
|
|
|
|
|
return version;
|
|
|
|
|
} else if (existsSync(manifestXmlPath)) {
|
|
|
|
|
const manifest = await readFile(manifestXmlPath, 'utf8');
|
|
|
|
|
const version = `${manifest.match(/versionName="([^"]+)"/)[1]} (${manifest.match(/versionCode="([^"]+)"/)[1]})`;
|
|
|
|
|
return version;
|
|
|
|
|
}
|
2025-03-26 13:19:45 +05:00
|
|
|
};
|
|
|
|
|
|
2025-08-26 12:21:50 +05:00
|
|
|
const extract = async ({ target = 'mobile', output, cleanup = false } = {}) => {
|
2025-08-23 23:49:07 +05:00
|
|
|
console.log('Downloading APK...');
|
|
|
|
|
const apkPath = target === 'tv' ? await downloadTvApk() : await downloadMobileApk();
|
2025-03-26 13:19:45 +05:00
|
|
|
|
2025-10-25 12:13:35 +05:00
|
|
|
if (!existsSync(apkPath)) {
|
2025-10-25 12:03:59 +05:00
|
|
|
console.error('Unable to find APK (possibly a download error)');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-26 13:19:45 +05:00
|
|
|
console.log('Decompiling APK...');
|
|
|
|
|
const decompiledDir = decompileApk(apkPath);
|
|
|
|
|
|
2025-08-23 23:49:07 +05:00
|
|
|
console.log('Parsing version...');
|
|
|
|
|
const version = await parseVersion(decompiledDir);
|
2025-03-26 13:19:45 +05:00
|
|
|
|
2025-08-23 23:49:07 +05:00
|
|
|
console.log('Parsing credentials...');
|
|
|
|
|
const { id, secret } = await parseCredentials(decompiledDir);
|
|
|
|
|
const encoded = Buffer.from(`${id}:${secret}`).toString('base64');
|
|
|
|
|
const authorization = `Basic ${encoded}`;
|
2025-03-26 13:19:45 +05:00
|
|
|
|
|
|
|
|
console.log(`Cleaning up files...`);
|
|
|
|
|
if (cleanup) await rm(apkPath, { recursive: true, force: true });
|
|
|
|
|
if (cleanup) await rm(decompiledDir, { recursive: true, force: true });
|
|
|
|
|
|
2025-08-23 21:14:56 +05:00
|
|
|
console.log(`Version: ${version}`);
|
2025-03-26 13:19:45 +05:00
|
|
|
console.log(`ID: ${id}`);
|
|
|
|
|
console.log(`Secret: ${secret}`);
|
|
|
|
|
console.log(`Encoded ID with secret: ${encoded}`);
|
2025-08-23 21:14:56 +05:00
|
|
|
console.log(`Authorization: ${authorization}`);
|
|
|
|
|
|
|
|
|
|
if (output) {
|
2026-02-08 14:00:56 +05:00
|
|
|
await writeFile(
|
|
|
|
|
output,
|
|
|
|
|
JSON.stringify({ version, id, secret, encoded, authorization }, null, 2),
|
|
|
|
|
);
|
2025-08-23 21:14:56 +05:00
|
|
|
}
|
2025-03-26 13:19:45 +05:00
|
|
|
|
2025-08-23 21:14:56 +05:00
|
|
|
return { version, id, secret, encoded, authorization };
|
2025-03-26 13:19:45 +05:00
|
|
|
};
|
2025-03-27 18:23:20 +05:00
|
|
|
|
2025-08-26 12:21:50 +05:00
|
|
|
const pull = async ({ target = 'mobile' } = {}) => {
|
|
|
|
|
const url = `https://raw.githubusercontent.com/vitalygashkov/crextractor/refs/heads/main/credentials.${target}.json`;
|
|
|
|
|
const credentials = await fetch(url).then((response) => response.json());
|
|
|
|
|
return credentials;
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-15 17:44:53 +05:00
|
|
|
export { extract, pull };
|