summary refs log tree commit diff stats
path: root/main.py
diff options
context:
space:
mode:
authorMarco Andronaco <andronacomarco@gmail.com>2023-07-12 09:14:36 +0200
committerMarco Andronaco <andronacomarco@gmail.com>2023-07-12 09:14:36 +0200
commit733a0a23988fb074c93e6c398d8b9142ee180b29 (patch)
tree6a06a08378b0744474d45d8692ac1ce17bec7859 /main.py
downloadsunstroke-733a0a23988fb074c93e6c398d8b9142ee180b29.tar.gz
initial commit
Diffstat (limited to 'main.py')
-rw-r--r--main.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/main.py b/main.py
new file mode 100644
index 0000000..53502c8
--- /dev/null
+++ b/main.py
@@ -0,0 +1,48 @@
+import json
+import requests # https://github.com/pyload/pyload/wiki/module.Api.Api
+from Sole import get_sole, remove_first
+
+SESSION_FILENAME = "session.txt"
+PYLOAD_PROTOCOL = "http"
+PYLOAD_HOST = "localhost"
+PYLOAD_PORT = 8000
+PYLOAD_USER = "pyload"
+PYLOAD_PW = "pyload"
+PYLOAD_API_ENDPOINT = "/api"
+PYLOAD_LOGIN_ENDPOINT = "/login"
+PYLOAD_ADDPACKAGE_ENDPOINT = "/generateAndAddPackages"
+PYLOAD_API_URL = f"{ PYLOAD_PROTOCOL }://{ PYLOAD_HOST }:{ PYLOAD_PORT }{ PYLOAD_API_ENDPOINT }"
+
+LOGIN_DATA = { "username": PYLOAD_USER, "password": PYLOAD_PW }
+LOGIN_URL = PYLOAD_API_URL + PYLOAD_LOGIN_ENDPOINT
+ADDPACKAGE_URL = PYLOAD_API_URL + PYLOAD_ADDPACKAGE_ENDPOINT
+
+def get_session_id():
+    try:
+        with open(SESSION_FILENAME, "r", encoding="utf-8") as in_file:
+            return in_file.readline()
+    except FileNotFoundError:
+        res = requests.post(LOGIN_URL, data=LOGIN_DATA)
+        cookies = res.cookies.get_dict()
+        session_id = cookies['pyload_session']
+        with open(SESSION_FILENAME, "w", encoding="utf-8") as out_file:
+            out_file.write(session_id)
+        return session_id
+    
+def add_package(links):
+    ADDPACKAGE_DATA = { "links": json.dumps(links), "session": session_id }
+    print(ADDPACKAGE_URL)
+    print(ADDPACKAGE_DATA)
+    kek = requests.post(ADDPACKAGE_URL, data=LOGIN_DATA).text
+    return kek
+
+if __name__ == "__main__":
+    session_id = get_session_id()
+    
+    #sole = get_sole()
+    #sole_link = remove_first(sole)[1][0]
+    
+    
+    links = [ "http://localhost:8080/file2", "http://localhost:8080/file1" ]
+    
+    print(add_package(links))