pystardust / ani-cli

A cli tool to browse and play anime
GNU General Public License v3.0
7.7k stars 539 forks source link

Automatic encryption keys #649

Closed Derisis13 closed 2 years ago

Derisis13 commented 2 years ago

Gogo likes to ruin our fun more and more often. There's a pseudo-api for it already, we just need to use it. This api is updated automatically. Pros: The current way we deal with key changes is PRs and updates. This is a lot of work and a lot of delay compared to fetching the keys every time the script starts. Cons: We'd be relying on an external provider, when it'll end up breaking, it'll be more work to fix/figure out what to do. Also the codebase would grow.

nemo256 commented 2 years ago

This might be of some help. https://github.com/riimuru/gogoanime

port19x commented 2 years ago

This might be of some help. https://github.com/riimuru/gogoanime

I'm aware of the api and have confirmed over a month ago they could easily handle our traffic: https://github.com/riimuru/gogoanime/issues/5

port19x commented 2 years ago

Gogo likes to ruin our fun more and more often. There's a pseudo-api for it already, we just need to use it. This api is updated automatically. Pros: The current way we deal with key changes is PRs and updates. This is a lot of work and a lot of delay compared to fetching the keys every time the script starts. Cons: We'd be relying on an external provider, when it'll end up breaking, it'll be more work to fix/figure out what to do. Also the codebase would grow.

The pseudo api seems promising. I think transitioning to scrape animixplay is preferable tho

Shinyzenith commented 2 years ago
#!/usr/bin/python3.10
import json
import os
import re
import requests

def main():
    res = requests.get("https://goload.pro/streaming.php?id=MTgxNzk2").text
    keys = re.findall(r"(?:container|videocontent)-(\d+)", res)
    if not keys:
        return
    key, iv, second_key = keys
    data = {"key":key, "second_key":second_key, "iv": iv}

    with open("./keys.json", "w") as fd:
        json.dump(data, fd, indent=4, sort_keys=True)

if __name__=='__main__':
    main()

I extracted the key section from animdl repo, it's quite small and easy to maintain. This can run in CI and then ani-cli can just curl at runtime.

Just an idea ^

Splodienyancat commented 2 years ago

I remember seeing something about pulling the keys every other hour but why cant there just a command to pull the keys exist too. This may be a security issue though.

mdrokz commented 2 years ago
const CryptoJS = require('./crypto');
const $ = require('cheerio').load(require('fs').readFileSync('./streaming.php').toString());

const secret_value = $(`script[data-name="episode"]`).attr('data-value');

const key_iv = $("div[class*='container-']").attr('class').split('-').pop();
const second_key_id = $("div[class*='videocontent-']").attr('class').split('-').pop();
const key_id = $("body[class^='container-']").attr('class').split('-').pop();

const iv = CryptoJS.enc.Utf8.parse(key_iv);
const key = CryptoJS.enc.Utf8.parse(key_id);
const second_key = CryptoJS.enc.Utf8.parse(second_key_id);

const value = CryptoJS['AES'].decrypt(secret_value, key, { iv: iv });

const value_str = CryptoJS.enc.Utf8.stringify(x);

const alias = value_str.substr(0, value_str.indexOf("&"));

const id = CryptoJS['AES'].encrypt(alias, key, { iv: iv }).toString();

console.log(alias, id, iv, key, second_key);

I also wrote this simple code in js to get the keys.

mdrokz commented 2 years ago

I implemented the same logic in my flutter app https://github.com/mdrokz/ani_mobile/blob/d3299bf9bcbd5bd26863b232ee46e1cadd8ed291/lib/utils.dart#L54-L98

https://github.com/mdrokz/ani_mobile/blob/d3299bf9bcbd5bd26863b232ee46e1cadd8ed291/lib/scraper.dart#L86-L111

the extracted keys work and im able to decrypt the stream link

relejek commented 2 years ago

This might be of some help. https://github.com/riimuru/gogoanime

Just throwing an idea in the mix. Will it be practical to build our own method for 'automatic encryption keys' yet have riimuru/gogoanime 's pseudo API as back up when any issue arises. We can remove the dependency on pseudo API after a few months of reliable run of native method.