ghoshRitesh12 / aniwatch-api

Node.js API for obtaining anime information from hianime.to
https://aniwatch-api.onrender.com
MIT License
267 stars 162 forks source link

Solving issue of "streaming link decryption is not working" #30

Closed itzzzme closed 7 months ago

itzzzme commented 8 months ago

Problem The streaming link decyption method is not working , because the key you are using is not correct.

Possible solution I explored other repos too but none of their keys are correct. I also saw that the repo consumet is using to decrypt the link is not correct as well

Alternatives I suggest to write your own function/script to extract those keys perfectly without depending on other's repo

Suggested solution

You can implement this logic, currently this is working fine

function matchingKey(value, script) {
  const regex = new RegExp(`,${value}=((?:0x)?([0-9a-fA-F]+))`);
  const match = script.match(regex);
  if (match) {
    return match[1].replace(/^0x/, "");
  } else {
    throw new ErrorLoadingException("Failed to match the key");
  }
}
function getKeys(script) {
  const regex =
    /case\s*0x[0-9a-f]+:(?![^;]*=partKey)\s*\w+\s*=\s*(\w+)\s*,\s*\w+\s*=\s*(\w+);/g;
  const matches = script.matchAll(regex);
  const indexPairs = Array.from(matches, (match) => {
    const matchKey1 = matchingKey(match[1], script);
    const matchKey2 = matchingKey(match[2], script);
    try {
      return [parseInt(matchKey1, 16), parseInt(matchKey2, 16)];
    } catch (e) {
      return [];
    }
  }).filter((pair) => pair.length > 0);
  return indexPairs;
}
const script = await axios.get('https://rapid-cloud.co/js/player/prod/e6-player-v2.min.js');
console.log(getKeys(script.data))

Expected Output

[ [ 36,6 ] , [ 90,7 ] , [ 118 , 7 ] ]

let me know if it works

ghoshRitesh12 commented 8 months ago

Hey @itzzzme, thank you so much for sharing this info. I'll try it out sometime and see how it goes.

itzzzme commented 8 months ago

@ghoshRitesh12 , sure , it works for both rapid-cloud and megacloud server so you can implement this for both server

ghoshRitesh12 commented 7 months ago

@itzzzme Thank you so much for this ❤️