all repos — sunstroke @ 733a0a23988fb074c93e6c398d8b9142ee180b29

main.py (view raw)

 1import json
 2import requests # https://github.com/pyload/pyload/wiki/module.Api.Api
 3from Sole import get_sole, remove_first
 4
 5SESSION_FILENAME = "session.txt"
 6PYLOAD_PROTOCOL = "http"
 7PYLOAD_HOST = "localhost"
 8PYLOAD_PORT = 8000
 9PYLOAD_USER = "pyload"
10PYLOAD_PW = "pyload"
11PYLOAD_API_ENDPOINT = "/api"
12PYLOAD_LOGIN_ENDPOINT = "/login"
13PYLOAD_ADDPACKAGE_ENDPOINT = "/generateAndAddPackages"
14PYLOAD_API_URL = f"{ PYLOAD_PROTOCOL }://{ PYLOAD_HOST }:{ PYLOAD_PORT }{ PYLOAD_API_ENDPOINT }"
15
16LOGIN_DATA = { "username": PYLOAD_USER, "password": PYLOAD_PW }
17LOGIN_URL = PYLOAD_API_URL + PYLOAD_LOGIN_ENDPOINT
18ADDPACKAGE_URL = PYLOAD_API_URL + PYLOAD_ADDPACKAGE_ENDPOINT
19
20def get_session_id():
21    try:
22        with open(SESSION_FILENAME, "r", encoding="utf-8") as in_file:
23            return in_file.readline()
24    except FileNotFoundError:
25        res = requests.post(LOGIN_URL, data=LOGIN_DATA)
26        cookies = res.cookies.get_dict()
27        session_id = cookies['pyload_session']
28        with open(SESSION_FILENAME, "w", encoding="utf-8") as out_file:
29            out_file.write(session_id)
30        return session_id
31    
32def add_package(links):
33    ADDPACKAGE_DATA = { "links": json.dumps(links), "session": session_id }
34    print(ADDPACKAGE_URL)
35    print(ADDPACKAGE_DATA)
36    kek = requests.post(ADDPACKAGE_URL, data=LOGIN_DATA).text
37    return kek
38
39if __name__ == "__main__":
40    session_id = get_session_id()
41    
42    #sole = get_sole()
43    #sole_link = remove_first(sole)[1][0]
44    
45    
46    links = [ "http://localhost:8080/file2", "http://localhost:8080/file1" ]
47    
48    print(add_package(links))