DxCx / plugin.video.9anime

plugin.video.9anime - 9Anime plugin for kodi
GNU General Public License v3.0
143 stars 47 forks source link

Get DD without external provider #288

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hi,

code for getting the DD without an external provider because im not a fan of anyone knowing im using 9anime besides 9anime itself^^

Use-case Download current all.js calculate and persist DD value. There should be an option in the menu called "Reload DD-Value [fill in a better name]." to reload the new DD value and only download a new all.js if it is really new (the hash after ? changes with new files)

Attention You have to download the all.js?..... like its linked in the html script> ... section. The all.js and the all.js?p5b325dd5 are not the same

import re

def createDDVariable(i, t):
    s = 0
    o = ''
    t = t.decode('base64').decode('UTF-8')
    e = range(0, 256)
    for a in xrange(256):
        s = (s + e[a] + ord(i[a % len(i)])) % 256
        n = e[a]
        e[a] = e[s]
        e[s] = n
    s = 0
    a = 0
    for c in xrange(len(t)):
        a = (a + 1) % 256
        s = (s + e[a]) % 256
        n = e[a]
        e[a] = e[s]
        e[s] = n
        o += chr(ord(t[c]) ^ e[(e[a] + e[s]) % 256])
    return o

def getDDVariable(text):
    dTKey = 'dT' #'XC'
    vTKey = 'vT' #'JC'
    lTKey = 'lT' #'YC'

    #line numbers are based on chromium

    #line 1 (get all plaintext mappings)
    lookupTableRaw = re.findall(r'[^,]+?\s*?=\s*?".*?"', text)
    lookupTable = dict(map(lambda x: map(lambda y: y.strip().strip('"'), x.split('=', 1)), lookupTableRaw))

    #line 9860 (get encrypted mappings)
    dTRaw = re.findall(dTKey + r'\s*?=\s*?\[\s*?(.*?)\s*?\]\s*?;', text)[0]
    dTValues = map(lambda x: map(lambda z: z.strip(), x.split('+')), dTRaw.split(','))

    #replace variables from plaintextmappings
    dT = map(lambda x: ''.join(map(lambda y:
                                   y.strip('"') if y.startswith('"') else
                                   lookupTable[y],
                                   x)), dTValues)

    #shift array by number
    shiftCountRaw = re.search(lTKey + r'\s*?=\s*?(\d+)', text)
    shiftCount = int(shiftCountRaw.group(1))
    # line 9863
    for i in xrange(shiftCount):
        dT.append(dT.pop(0))

    #10065
    # var i, n, e = vT(Hm, $n), s = a[vb + no + yt](p, e), o = {}, r = {};
    # t = Hm und i = $n
    inputVariablesRaw = re.search(r'\S*?e\s*?=\s*?' + vTKey + r'\s*?\((\S*?),\s*?(\S*?)\)', text[shiftCountRaw.end():])

    # get values from lookupTable and dT
    t_lookupVar = lookupTable[inputVariablesRaw.group(1)]

    t = dT[int(t_lookupVar, 16 if 'x' in t_lookupVar else 10)]
    i = ''.join(map(lambda y: y.strip('"') if '"' in y else lookupTable[y], inputVariablesRaw.group(2).split('+')))

    return createDDVariable(i, t)

if __name__ == '__main__':
    with open('all.js', 'r') as f:
        lines = f.readlines()

    text = str(lines)
    print getDDVariable(text)
DxCx commented 6 years ago

this looks like it can break very easly :( i mean, sometimes the actualy encoding function change and not only the DD and then it wont work anymore..

the "external" provider is used right now only as fallback

also im sure you have the skills to disable this behavior locally for you and update the DD manually ;)

ghost commented 6 years ago

i know it´ll break easily because im not doing semantic parsing. lets see how long it will take.

the code is more for a "nice to know where those changes are made" and those who code themselves. So maybe leave it open for a while^^

ruegnueg commented 6 years ago

it's working, why should I, a noob, manually change something ;-)

RedNinjaX commented 6 years ago

@ruegnueg because as he said he's merely afraid of anyone gaining any "stats" on his anime watching habits, if you can gather what he means.

Rest assured though the only info we can view is the amount of total requests that is made to the API and nothing more, which isn't many at that as like what DxCx said it's simply a fallback method at the moment and 9a hasn't changed anything yet so currently all links use 834 for the extra parameter, no DD token knowledge required.

Even so the API is managed by romxuk, DxCx and I and is overseen by DxCx, but even he prefers having not to rely on it as much as possible, so I can't really expect anyone else to do any different.

Anyway do what you will. Our job here is done.