dandygithub / kodi

KODI Addons Project
GNU General Public License v3.0
77 stars 49 forks source link

hdrezka add-on failing to playback movies #70

Closed mpashkovskiy closed 2 years ago

mpashkovskiy commented 2 years ago

Looks like they changed response format:

2022-01-06 11:51:57.738 T:2713     INFO <general>: hdrezka: *** main params: {'mode': 'show', 'uri': '/films/drama/42649-kupe-nomer-6-2021.html'}
2022-01-06 11:51:58.266 T:2713     INFO <general>: hdrezka: fault parseDOM ex: list index out of range
2022-01-06 11:51:58.304 T:2713     INFO <general>: hdrezka: *** get_links data: #hWzM2MHBdaHR0cDovL3N0cmVhbS52b2lkYm9vc3QuY2MvNC82LzEvMi82LzEvOTI0MDExYmZiZmI1YzhhNWI4ZTEzMWEyODkyZGIyN\/\/_\/\/QEBAQEAhIyMhXl5emE6MjAyMjAxMDcwODo4Yjk1ZTI1ZC1kZDY2LTRhYTMtOGU1OS1kNzU0NWRjYmQ3ZTYvZzh0eHoubXA0OmhsczptYW5pZmVzdC5tM3U4IG9yIGh0dHA6Ly9zdHJlYW0udm9pZGJvb3N0LmNjLzJiYTZjYmU2N2FlMWRlZTI5ODNiYWI0ZGRhMDgzODk3OjIwMjIwMTA3MDg6OGI5NWUyNWQtZGQ2Ni00YWEzLThlNTktZDc1NDVkY2JkN2U2LzQvNi8xLzIvNi8xL2c4dHh6Lm1wNCxbNDgwcF1odHRwOi8vc3RyZWFtLnZvaWRib29zdC5jYy80LzYvMS8yLzYvMS85MjQwMTFiZmJmYjVjOGE1YjhlMTMxYTI4OTJkYjI2YToyMDIyMDEwNzA4OjhiOTVlMjVkLWRkNjYtNGFhMy04ZTU5LWQ3NTQ1ZGNiZDdlNi9rdTdzN\/\/_\/\/JCQjISFAIyFAIyM=S5tc\/\/_\/\/Xl5eIUAjIyEhIyM=DQ6aGxzOm1hbmlmZXN0Lm0zdTggb3IgaHR0cDovL3N0cmVhbS52b2lkYm9vc3QuY2MvMzQ4ZTNjYjVlNTQ3MTE5MjliZGRiOGZhYTJmMzBmNWQ6MjAy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VkY2JkN2U2LzZqaW90Lm1wNDpobHM6bWFuaWZlc3QubTN1OCBvciBodHRwOi8vc3RyZWFtLnZvaWRib29zdC5jY\/\/_\/\/JCQhIUAkJEBeIUAjJCRAy9mZDBkN2NhZDBiZWQzMzU0OGE3OGE0NWJkYThlY2IwMjoyMDIyMDEwNzA4OjhiOTVlMjVkLWRkNjYtNGFhMy04ZTU5LWQ3NTQ1ZGNiZDdlNi80LzYvMS8yLzYvMS82amlvdC5tcDQ=
2022-01-06 11:51:58.311 T:2713    ERROR <general>: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                                - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                                   Error Type: <class 'IndexError'>
                                                   Error Contents: list index out of range
                                                   Traceback (most recent call last):
                                                     File "/home/pi/.kodi/addons/plugin.video.hdrezka.tv/default.py", line 584, in <module>
                                                       plugin.main()
                                                     File "/home/pi/.kodi/addons/plugin.video.hdrezka.tv/default.py", line 88, in main
                                                       self.show(params.get('uri'))
                                                     File "/home/pi/.kodi/addons/plugin.video.hdrezka.tv/default.py", line 442, in show
                                                       links = self.get_links(data)
                                                     File "/home/pi/.kodi/addons/plugin.video.hdrezka.tv/default.py", line 377, in get_links
                                                       manifest_links[int(link.split("]")[0].replace("[", "").replace("p", ""))] = link.split("]")[1]
                                                   IndexError: list index out of range
                                                   -->End of Python script error report<--

2022-01-06 11:51:58.727 T:2713     INFO <general>: Python interpreter stopped
2022-01-06 11:51:58.735 T:2712    ERROR <general>: GetDirectory - Error getting plugin://plugin.video.hdrezka.tv/?mode=show&uri=%2ffilms%2fdrama%2f42649-kupe-nomer-6-2021.html
2022-01-06 11:51:58.745 T:957     ERROR <general>: CGUIMediaWindow::GetDirectory(plugin://plugin.video.hdrezka.tv/?mode=show&uri=%2ffilms%2fdrama%2f42649-kupe-nomer-6-2021.html) failed
SuperZombi commented 2 years ago

Hdrezka blocking their API

Image ![image](https://user-images.githubusercontent.com/75096786/148447431-62214db4-05df-4cb1-a804-73af476bacde.png)
babkavkedakh commented 2 years ago

Sorry for the shitty code, but it works :) https://github.com/dandygithub/kodi/pull/71

DesSolo commented 2 years ago

I think this issues can be closed

SuperZombi commented 2 years ago

Sorry for the shitty code, but it works :) #71

Can U help me to convert this code to JS?

SuperZombi commented 2 years ago

Sorry for the shitty code, but it works :) #71

r_decoded = base64.b64decode(to_decode)
  File "Python39\lib\base64.py", line 87, in b64decode
    return binascii.a2b_base64(s)
binascii.Error: Incorrect padding
babkavkedakh commented 2 years ago

"binascii.Error: Incorrect padding" it means string to b64decode incorrect.

I don't know JS, but this is how the algorithm works:

1) Server response contains obfuscated and base64 encoded string 2) Characters are used for obfuscation: @ # ! ^ $ 3) Characters are grouped by 2 or 3. Ex: ## or @!@ or ^^! , because after encoding this group will always have length 4. Several groups can go in a row. 4) Response always starts from "#h" and always has parts separated by symbols "// //". All trash characters inserted after "// //" 5) I believe the obfuscation on the server was done in 2 passes 6) So, let's begin:

SuperZombi commented 2 years ago

"binascii.Error: Incorrect padding" it means string to b64decode incorrect.

@babkavkedakh, What version of python are you using? I copied your code, but its still gives me this error.

babkavkedakh commented 2 years ago

"binascii.Error: Incorrect padding" it means string to b64decode incorrect.

@babkavkedakh, What version of python are you using?

2.7 for master branch

SuperZombi commented 2 years ago

"binascii.Error: Incorrect padding" it means string to b64decode incorrect.

@babkavkedakh, What version of python are you using?

2.7 for master branch

I am 3.9

babkavkedakh commented 2 years ago

мой вариант очистки работает посимвольно. С байтами там чет не фурычило.

SuperZombi commented 2 years ago

I wrote my function that does this in Python 3:

import base64
from itertools import product

def clearTrash(data):
    trashList = ["@","#","!","^","$"]
    trashCodesSet = []
    for i in range(2,4):
        startchar = ''
        for chars in product(trashList, repeat=i):
            data_bytes = startchar.join(chars).encode("utf-8")
            trashcombo = base64.b64encode(data_bytes)
            trashCodesSet.append(trashcombo)

    arr = data.replace("#h", "").split("//_//")
    trashString = ''.join(arr)

    for i in trashCodesSet:
        temp = i.decode("utf-8")
        trashString = trashString.replace(temp, '')

    finalString = base64.b64decode(trashString+"==")
    return finalString.decode("utf-8")
babkavkedakh commented 2 years ago

есть нюанс, почему я упомянул двойной проход при обфускации: мусорный блок может стоять внутри другого мусорного блока. Поэтому просто разделить строку по //_ // и бахнуть очисткой перебором не получится, т.к. коды не сойдутся. Для этого и используется поэтапное объединение строк с конца и очистка каждого полученного результата.

SuperZombi commented 2 years ago

есть нюанс, почему я упомянул двойной проход при обфускации: мусорный блок может стоять внутри другого мусорного блока. Поэтому просто разделить строку по //_ // и бахнуть очисткой перебором не получится, т.к. коды не сойдутся. Для этого и используется поэтапное объединение строк с конца и очистка каждого полученного результата.

Не совсем понял, что вы имеете ввиду, но по идее должно работать. Привидите тогда пример.

babkavkedakh commented 2 years ago

Не совсем понял, что вы имеете ввиду, но по идее должно работать. Привидите тогда пример.

похоже, что в вашей реализации мой нюанс не важен - все работает :) спасибо!

SuperZombi commented 2 years ago

Не совсем понял, что вы имеете ввиду, но по идее должно работать. Привидите тогда пример.

похоже, что в вашей реализации мой нюанс не важен - все работает :) спасибо!

Помогите теперь плиз на JS это переписать. А то я щас не могу разобраться с декодировкой из base64. JS говно)

babkavkedakh commented 2 years ago

не силен в js, увы

SuperZombi commented 2 years ago

JS:

function clearTrash(data){
    function product(iterables, repeat) {
        var argv = Array.prototype.slice.call(arguments), argc = argv.length;
        if (argc === 2 && !isNaN(argv[argc - 1])) {
            var copies = [];
        for (var i = 0; i < argv[argc - 1]; i++) {
            copies.push(argv[0].slice()); // Clone
        }
        argv = copies;
        }
        return argv.reduce(function tl(accumulator, value) {
        var tmp = [];
        accumulator.forEach(function(a0) {
            value.forEach(function(a1) {
            tmp.push(a0.concat(a1));
            });
        });
        return tmp;
        }, [[]]);
    }
    function unite(arr){
        var final = [];
        arr.forEach(function(e){
            final.push(e.join(""))
        })
        return final;
    }
    var trashList = ["@","#","!","^","$"];
    var two = unite(product(trashList, 2));
    var tree = unite(product(trashList, 3));
    var trashCodesSet = two.concat(tree);

    var arr = data.replace("#h", "").split("//_//");
    var trashString = arr.join('');

    trashCodesSet.forEach(function(i){
        var temp = btoa(i)
        trashString = trashString.replaceAll(temp, '')
    })

    var final_string = atob(trashString);
    return final_string;
}