aboutsummaryrefslogtreecommitdiff
path: root/plugins/youtube/Signature.hpp
blob: 7456615cdaba21a99a912b7649b1a7995834eac0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once

#include "../../include/AsyncTask.hpp"
#include <string>
#include <vector>
#include <map>
#include <mutex>
#include <time.h>

namespace QuickMedia {
    // Thread safe
    class YoutubeSignatureDecryptor {
    public:
        static YoutubeSignatureDecryptor& get_instance();
        bool decrypt(const std::string &s, const std::string &sp, std::string &sig_key, std::string &sig_value);
    private:
        YoutubeSignatureDecryptor();
        ~YoutubeSignatureDecryptor();
        YoutubeSignatureDecryptor(const YoutubeSignatureDecryptor&) = delete;
        YoutubeSignatureDecryptor& operator=(const YoutubeSignatureDecryptor&) = delete;

        struct DecryptFuncCall {
            std::string func_name;
            long arg;
        };

        enum class DecryptFunction {
            REVERSE,
            SPLICE,
            SWAP
        };

        bool js_code_to_operations(const std::string &function_body_str, const std::string &var_body_str, std::vector<DecryptFuncCall> &new_func_calls, std::map<std::string, DecryptFunction> &new_func_decls);
        int update_decrypt_function();
    private:
        AsyncTask<void> poll_task;
        std::mutex update_signature_mutex;
        std::string decryption_function;
        time_t decrypt_function_last_updated = 0;
        bool running = false;
        bool up_to_date = false;

        std::vector<DecryptFuncCall> func_calls;
        std::map<std::string, DecryptFunction> func_decls;
    };
}