Skip to content

Commit 7f01735

Browse files
committed
* oldsubs is broken
* update url to fonts * rewrite some code
1 parent b201285 commit 7f01735

File tree

3 files changed

+48
-26
lines changed

3 files changed

+48
-26
lines changed

crunchy.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,10 @@ async function getMedia(mMeta){
785785
console.log('[WARN] No streams found!');
786786
}
787787

788+
if(argv.nullstream){
789+
hlsStream = '';
790+
}
791+
788792
// download stream
789793
if(hlsStream == '' && !isClip){
790794
console.log('[ERROR] No available full raw stream! Session expired?');
@@ -932,9 +936,14 @@ async function getMedia(mMeta){
932936
}
933937
}
934938

935-
// always get old subs
939+
// get old subs
936940
getOldSubs = argv.oldsubs;
937941

942+
// oldsubs warning
943+
if(getOldSubs){
944+
console.log('[WARN] oldsubs cli option is broken, see issue #2 at github');
945+
}
946+
938947
// download subs
939948
sxList = [];
940949
if(!argv.skipsubs && argv.dlsubs != 'none'){
@@ -982,7 +991,7 @@ async function getMedia(mMeta){
982991
let subsTt = subsListXml[s].attribs.title;
983992
let subsXmlApi = await getData(`${api.subs_file}${subsId}`,{useProxy:true});
984993
if(subsXmlApi.ok){
985-
let subXml = crunchySubs.decrypt(subsListXml[s].attribs.id,subsXmlApi.res.body);
994+
let subXml = crunchySubs.decrypt(null, subsXmlApi.res.body);
986995
if(subXml.ok){
987996
let subsParsed = crunchySubs.parse(subsListXml[s].attribs,subXml.data);
988997
let sLang = subsParsed.langCode.match(/(\w{2}) - (\w{2})/);
@@ -1005,6 +1014,10 @@ async function getMedia(mMeta){
10051014
console.log(`[INFO] Download skipped: ${subsParsed.file}`);
10061015
}
10071016
}
1017+
else{
1018+
console.log(`[WARN] Failed decode subtitles #${subsId} ${subsTt}`);
1019+
console.log(subXml.data);
1020+
}
10081021
}
10091022
else{
10101023
console.log(`[WARN] Failed to download subtitles #${subsId} ${subsTt}`);

modules/module.crunchySubs.js

+32-23
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,28 @@ const shlp = require('sei-helper');
44
const xhtml2js = shlp.xhtml2js;
55

66
// decrypt
7-
function createString(args) {
8-
let a = args[2];
9-
let b = args[3];
10-
let res = '';
11-
for (let i = 0; i < args[0]; i++) {
12-
b += a;
13-
a = b - a;
14-
res += String.fromCharCode(b % args[1] + 33);
7+
function generateKeyAux(count, modulo, start){
8+
// Generate String: $&).6CXzPHw=2N_+isZK
9+
let res = start;
10+
for (let i of Array(count).keys()){
11+
res.push(res[res.length-1] + res[res.length-2]);
1512
}
13+
res.splice(0, 2)
14+
res = res.map(x => x % modulo + 33);
15+
res = String.fromCharCode(...res);
1616
return res;
1717
}
18-
function generateKey(mediaid) {
19-
let eq1 = Math.floor(Math.sqrt(6.9) * Math.pow(2, 25));
20-
let eq2 = (mediaid ^ eq1) ^ (mediaid ^ eq1) >> 3 ^ (eq1 ^ mediaid) * 32;
21-
if (eq2 < 0) {
22-
eq2 += 0x100000000;
23-
}
24-
let finalHash = crypto.createHash('sha1').update(createString([20, 97, 1, 2]) + eq2.toString(), 'utf8').digest();
25-
let res = Buffer.alloc(32);
26-
finalHash.copy(res);
27-
return res;
18+
function generateKey(id) {
19+
const hashMagicConst = Math.floor(Math.sqrt(6.9) * Math.pow(2, 25)); // 0x0540E9FA
20+
const hashMagicBaseNum = hashMagicConst ^ id;
21+
const hashMagicNumber = hashMagicBaseNum ^ hashMagicBaseNum >> 3 ^ hashMagicBaseNum * 32;
22+
const finalHashMagicNumber = hashMagicNumber < 0 ? hashMagicNumber + 0x100000000 : hashMagicNumber;
23+
const keyAux = generateKeyAux(20, 97, [1, 2]);
24+
const keyText = keyAux + finalHashMagicNumber;
25+
const keyHash = crypto.createHash('sha1').update(keyText, 'utf8').digest();
26+
const finalKey = Buffer.alloc(32);
27+
keyHash.copy(finalKey);
28+
return finalKey;
2829
}
2930
function doDecrypt(_id, _iv, _data) {
3031
let key = generateKey(_id);
@@ -33,19 +34,27 @@ function doDecrypt(_id, _iv, _data) {
3334
dec.setAutoPadding();
3435
let decrypted = dec.update(_data, 'base64');
3536
decrypted = Buffer.concat([decrypted, dec.final()]);
36-
return zlib.unzipSync(decrypted).toString('utf8');
37+
try{
38+
const zlibData = zlib.unzipSync(decrypted).toString('utf8');
39+
return { ok: true, data: zlibData };
40+
}
41+
catch(err){
42+
return { ok: false, data: err };
43+
}
3744
}
3845
function decrypt(id, data) {
3946
let err = data.match(/<error>(.*)<\/error>/);
4047
if (err) {
41-
return { ok: false, data: `[ERROR] Unknown error, data:\n${err}` };
48+
return { ok: false, data: err };
4249
}
43-
let res = data.match(/<iv>(.*)<\/iv>.*<data>(.*)<\/data>/);
50+
let res = data.match(/id='(.*)'.*<iv>(.*)<\/iv>.*<data>(.*)<\/data>/);
4451
if (!res) {
45-
return { ok: false, data: `[ERROR] Unknown error, data:\n${data}` };
52+
return { ok: false, data: data };
4653
}
47-
return { ok: true, data: doDecrypt(id, res[1], res[2]) };
54+
id = id ? id : res[1];
55+
return doDecrypt(id, res[2], res[3]);
4856
}
57+
4958
// parse
5059
function parse(meta, src){
5160
// pre default

modules/module.fontsData.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// fonts src
2-
const root = 'https://static.crunchyroll.com/vilos/assets/fonts/';
2+
const root = 'https://static.crunchyroll.com/vilos-v2/web/vilos/assets/libass-fonts/';
33

44
// file list
55
const fonts = {

0 commit comments

Comments
 (0)