File size: 3,984 Bytes
dcb132a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import json
import sys

import requests


def tmdb_test(config):
    if config.get("tmdb_api_key") != None and config.get("tmdb_api_key") != "":
        res = requests.get(
            "https://api.themoviedb.org/3/?api_key=%s" % (config.get("tmdb_api_key"))
        ).json()
        if res.get("status_code") != 34:
            print("\033[31mERROR! THE TMDB_API_KEY PROVIDED IS INCORRECT!\033[0m")
    else:
        print("\033[31mERROR! YOU HAVE NOT PROVIDED A TMDB_API_KEY!\033[0m")
        sys.exit()


def category_list_test(config):
    passed = True
    if isinstance(config.get("category_list"), list):
        for item in config.get("category_list"):
            if (
                (isinstance(item, dict))
                and (item.get("id", "") != "")
                and (item.get("name", "") != "")
                and (item.get("type") in ["Movies", "TV Shows"])
            ):
                pass
            else:
                passed = False
                break
    else:
        passed = False
    if passed == False:
        print("\033[31mERROR! YOUR CATEGORY_LIST IS NOT VALID!\033[0m")
        sys.exit()


def account_list_test(config):
    passed = True
    if isinstance(config.get("account_list"), list):
        for item in config.get("account_list"):
            if (
                (isinstance(item, dict))
                and (item.get("auth", "") != "")
                and (item.get("username", "") != "")
                and (item.get("password", "") != "")
            ):
                pass
            else:
                passed = False
                break
    else:
        passed = False
    if passed == False:
        print("\033[31mERROR! YOUR ACCOUNT_LIST IS NOT VALID!\033[0m")
        sys.exit()


def cloudflare_test(config):
    if config.get("cloudflare") not in ["local", "", None]:
        if not config.get("cloudflare").startswith("http") and not config.get(
            "cloudflare"
        ).startswith("//"):
            print(
                "\033[31mERROR! YOUR CLOUDFLARE URL IS NOT VALID! THE URL MUST START WITH HTTP:// OR HTTPS://\033[0m"
            )
            sys.exit()
        res = requests.get(config.get("cloudflare")).text
        if not res.startswith("libDrive"):
            print(
                "\033[31mERROR! YOUR WEB HOSTED CLOUDFLARE DEPLOYMENT IS NOT RETURNING A VALID RESPONSE! MAKE SURE IT IS CORRECTLY CONFIGURED!\033[0m"
            )
            sys.exit()
    elif config.get("cloudflare") == "local":
        try:
            res = requests.get("http://localhost:31146").text
            if not res.startswith("libDrive"):
                print(
                    "\033[31mERROR! YOUR LOCALLY HOSTED CLOUDFLARE DEPLOYMENT IS NOT RETURNING A VALID RESPONSE! MAKE SURE IT IS CORRECTLY CONFIGURED!\033[0m"
                )
                sys.exit()
        except:
            print(
                "\033[31mERROR! YOUR LOCALLY HOSTED CLOUDFLARE DEPLOYMENT IS NOT RETURNING A VALID RESPONSE! MAKE SURE IT IS CORRECTLY CONFIGURED!\033[0m"
            )
            sys.exit()
    else:
        try:
            res = requests.get("http://localhost:31146").text
            if res:
                if res.startswith("libDrive"):
                    print(
                        "\033[33mA LOCALLY HOSTED CLOUDFLARE WORKER WAS FOUND, IT WILL BE USED INSTEAD.\033[0m"
                    )
                    config["cloudflare"] = "local"
                    with open("config.json", "w+") as w:
                        json.dump(obj=config, fp=w, sort_keys=True, indent=4)
                else:
                    print(
                        "\033[31mERROR! YOUR LOCALLY HOSTED CLOUDFLARE DEPLOYMENT IS NOT RETURNING A VALID RESPONSE! MAKE SURE IT IS CORRECTLY CONFIGURED!\033[0m"
                    )
                    sys.exit()
        except:
            pass