Advertisement
Guest User

animeheaven

a guest
Dec 11th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const got = require('got');
  2. const querystring = require('querystring');
  3.  
  4. const ANIME_NAME = 'A Certain Magical Index'; // This is case-sensitive and must be exact
  5. const ANIME_EPISODE = 2;
  6. const ENCRYPTION_KEY = 'ysdgetcfc'; // Seems to be static? It works for all the series I've tried
  7.  
  8. const QUERY = querystring.stringify({
  9.     a: ANIME_NAME,
  10.     e: ANIME_EPISODE
  11. });
  12.  
  13. const STREAM_1_REGEX = /var soienfu="(.*)";/;
  14. const STREAM_2_REGEX = /var iusfdb="(.*)";/;
  15. const STREAM_3_REGEX = /var ufbjhse="(.*)";/;
  16.  
  17. // https://stackoverflow.com/a/4209150
  18. String.prototype.decodeEscapeSequence = function() {
  19.     return this.replace(/\\x([0-9A-Fa-f]{2})/g, function() {
  20.         return String.fromCharCode(parseInt(arguments[1], 16));
  21.     });
  22. };
  23.  
  24. (async () => {
  25.     const streams = {};
  26.  
  27.     console.log(`Searching for streams for ${ANIME_NAME}, episode ${ANIME_EPISODE}...`);
  28.  
  29.     const response = await got(`http://animeheaven.eu/watch.php?${QUERY}`);
  30.     const body = response.body;
  31.  
  32.     let STREAM_REGEX_DATA = STREAM_1_REGEX.exec(body);
  33.     if (STREAM_REGEX_DATA) {
  34.         let encoded = STREAM_REGEX_DATA[1].decodeEscapeSequence();
  35.         encoded = encoded.replace(/\|/g, "0");
  36.         const encrypted = base64Decode(encoded);
  37.         streams.stream_1 = decrypt(ENCRYPTION_KEY, encrypted);
  38.     }
  39.  
  40.     STREAM_REGEX_DATA = STREAM_2_REGEX.exec(body);
  41.     if (STREAM_REGEX_DATA) {
  42.         let encoded = STREAM_REGEX_DATA[1].decodeEscapeSequence();
  43.         encoded = encoded.replace(/\|/g, "0");
  44.         const encrypted = base64Decode(encoded);
  45.         streams.stream_2 = decrypt(ENCRYPTION_KEY, encrypted);
  46.     }
  47.  
  48.     STREAM_REGEX_DATA = STREAM_3_REGEX.exec(body);
  49.     if (STREAM_REGEX_DATA) {
  50.         let encoded = STREAM_REGEX_DATA[1].decodeEscapeSequence();
  51.         encoded = encoded.replace(/\|/g, "0");
  52.         const encrypted = base64Decode(encoded);
  53.         streams.stream_3 = decrypt(ENCRYPTION_KEY, encrypted);
  54.     }
  55.  
  56.     console.log(streams);
  57. })();
  58.  
  59. function base64Decode(base64) {
  60.     return Buffer.from(base64, 'base64').toString('binary');
  61. }
  62.  
  63. function decrypt(key, crypted) {
  64.     const unknown_3 = [];
  65.     let j = 0;
  66.     let unknown_1;
  67.     let unknown_2 = '';
  68.  
  69.     for (let i = 0; i < 256; i++) {
  70.         unknown_3[i] = i;
  71.     }
  72.     for (i = 0; i < 256; i++) {
  73.         j = (j + unknown_3[i] + key.charCodeAt(i % key.length)) % 256;
  74.         unknown_1 = unknown_3[i];
  75.         unknown_3[i] = unknown_3[j];
  76.         unknown_3[j] = unknown_1;
  77.     }
  78.    
  79.     i = 0;
  80.     j = 0;
  81.    
  82.     for (let k = 0; k < crypted.length; k++) {
  83.         i = (i + 1) % 256;
  84.         j = (j + unknown_3[i]) % 256;
  85.         unknown_1 = unknown_3[i];
  86.         unknown_3[i] = unknown_3[j];
  87.         unknown_3[j] = unknown_1;
  88.         unknown_2 += String.fromCharCode(crypted.charCodeAt(k) ^ unknown_3[(unknown_3[i] + unknown_3[j]) % 256]);
  89.     }
  90.    
  91.     return unknown_2;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement