v18 Mega.nz addon
#1
hi.
i started to write an addon for Mega.nz ,
i almost got it, i was able to get the download link the problem is that the data is encrypted i dont know how to play this, i am adding my code (basicly its not my code i found it on Github and modified it).
how can i send the decryptor to "xbmcplugin.setResolvedUrl"?
 thanks for all your help.


def getfile(file_id, file_key):

    key = base64_to_a32(file_key)

    k = (key[0] ^ key[4], key[1] ^ key[5], key[2] ^ key[6], key[3] ^ key[7])
    iv = key[4:6] + (0, 0)
    meta_mac = key[6:8]

    file = api_req({'a': 'g', 'g': 1, 'p': file_id})
    dl_url = file['g']
    size = file['s']

    attributes = base64urldecode(file['at'])
    attributes = dec_attr(attributes, k)

    logging.warning( "Downloading %s (size: %d), url = %s" % (attributes['n'], size, dl_url))
    
    infile = urllib.urlopen(dl_url)
    loc=os.path.join(user_dataDir,'down.mkv')
    outfile = open(loc, 'wb')

#here is the decryptor !!!

    decryptor = AES.new(a32_to_str(k), AES.MODE_CTR, counter=Counter.new(128, initial_value=((iv[0] << 32) + iv[1]) << 64))
    return dl_url
    file_mac = [0, 0, 0, 0]
    x=0
    for chunk_start, chunk_size in sorted(get_chunks(file['s']).items()):
        chunk = infile.read(chunk_size)
        chunk = decryptor.decrypt(chunk)
        outfile.write(chunk)
        
        chunk_mac = [iv[0], iv[1], iv[0], iv[1]]
        for i in xrange(0, len(chunk), 16):
            block = chunk[i:i+16]
            if len(block) % 16:
                block += '\0' * (16 - (len(block) % 16))
            block = str_to_a32(block)
            chunk_mac = [chunk_mac[0] ^ block[0], chunk_mac[1] ^ block[1], chunk_mac[2] ^ block[2], chunk_mac[3] ^ block[3]]
            chunk_mac = aes_cbc_encrypt_a32(chunk_mac, k)
            
        file_mac = [file_mac[0] ^ chunk_mac[0], file_mac[1] ^ chunk_mac[1], file_mac[2] ^ chunk_mac[2], file_mac[3] ^ chunk_mac[3]]
        file_mac = aes_cbc_encrypt_a32(file_mac, k)
        
    outfile.close()
    infile.close()

    if (file_mac[0] ^ file_mac[1], file_mac[2] ^ file_mac[3]) != meta_mac:
        print "MAC mismatch"
    else:
        print "MAC OK"
Reply
#2
I'd like someone to help you, a Mega addon would be great
Reply
#3
Thread moved to add-on development
|Banned add-ons (wiki)|Forum rules (wiki)|VPN policy (wiki)|First time user (wiki)|FAQs (wiki) Troubleshooting (wiki)|Add-ons (wiki)|Free content (wiki)|Debug Log (wiki)|

Kodi Blog Posts
Reply
#4
How is the development going?
Having a mega nz addon would be beautiful Love
Reply
#5
(2019-09-11, 16:51)HatsuneMX Wrote: How is the development going?
Having a mega nz addon would be beautiful Love

since no one can answer it is going nowhere.
sorry.
Reply
#6
this would be amazing
Reply
#7
You can create a service addon that serves an http service, an you can write the decrypted chinks to that web server. To kodi, you will provide the local web server url where you wrote the decrypted file.

I did not check the details but looking at your code the stream is encrypted in the file chunks..
Reply
#8
(2019-12-11, 21:26)boogiepop Wrote: You can create a service addon that serves an http service, an you can write the decrypted chinks to that web server. To kodi, you will provide the local web server url where you wrote the decrypted file.

I did not check the details but looking at your code the stream is encrypted in the file chunks..

hi
first of all thanks for your answer, yes i guess this will work, do you have any example of such service ? what will happen if the player jumps forward? how does the service handle that ? or in other words how to build a streaming server?
thanks a lot.
Reply
#9
I think the most pragmatic way would be implementing something like a proxy server.

Let the kodi manage get requests to the proxy server, proxy server will forward this request to actual server but will return the response decrypted.

This way you will be immune to seek / forward issues because in protocol level these are generally custom get requests with range header to request partial or get full but a specific chunk if the container is an hls. But all of those will be managed by kodi and your service will be the man in the middle.

There are several ways to implememt it and the moat easiest way is to use python embedded webswrver. I think also asyncio is a part of py3 now. There are other options like tornado, twisted as well but they may increase the complexity

I remember i had something similar in past i will check if i can find aomething, but still there are ecamples on the net to play around

I think the most critical concern here would be the perodrmance, since you will do aes decrypt in packet level, streamning performance will degrade, put an extra overhead an ptthin slowness as an extra as well.
Reply
#10
Since Kodi is authored in python, this mega.nz API for python could make your life a great deal easier.

https://pypi.org/project/mega.py/
Reply
#11
A very minimal Kodi addon to stream videos from your MEGA account using MEGAcmd command-line tool

https://github.com/ritiek/plugin.video.megacmd

Hope that helps !
Reply



Logout Mark Read Team Forum Stats Members Help
Mega.nz addon0
This forum uses Lukasz Tkacz MyBB addons.