-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathIndex-scraper.py
77 lines (55 loc) · 2.44 KB
/
Index-scraper.py
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
import requests
import base64
import json
import urllib
next_page = False
next_page_token = ""
def authorization_token(username, password):
user_pass = f"{username}:{password}"
return f"Basic {base64.b64encode(user_pass.encode()).decode()}"
def decrypt(string):
return base64.b64decode(string[::-1][24:-20]).decode("utf-8")
def func(payload_input, url, username, password):
global next_page
global next_page_token
url = f"{url}/" if url[-1] != "/" else url
try:
headers = {"authorization": authorization_token(username, password), "Referer": index_link}
except:
return "username/password combination is wrong"
encrypted_response = requests.post(url, data=payload_input, headers=headers)
if encrypted_response.status_code == 401:
return "username/password combination is wrong"
try:
decrypted_response = json.loads(decrypt(encrypted_response.text))
except:
return "something went wrong. check index link/username/password field again"
page_token = decrypted_response["nextPageToken"]
if page_token is None:
next_page = False
else:
next_page = True
next_page_token = page_token
if list(decrypted_response.get("data").keys())[0] != "error":
file_length = len(decrypted_response["data"]["files"])
result = ""
for i, _ in enumerate(range(file_length)):
files_type = decrypted_response["data"]["files"][i]["mimeType"]
if files_type != "application/vnd.google-apps.folder":
files_name = decrypted_response["data"]["files"][i]["name"]
direct_download_link = url + urllib.parse.quote(files_name)
result += f"• {files_name}:-\n{direct_download_link}\n\n"
return result
def main(url, username="none", password="none"):
x = 0
payload = {"page_token": next_page_token, "page_index": x}
print(f"Index Link: {url}\n\n")
print(func(payload, url, username, password))
while next_page:
payload = {"page_token": next_page_token, "page_index": x}
print(func(payload, url, username, password))
x += 1
index_link = "https://anime.anipirates.workers.dev/0:/Breaking%20Bad%20(2008)%20Season%201-5%20S01-S05%20(1080p%20BluRay%20x265%20HEVC%2010bit%20AAC%205.1%20Silence)/Season%201/"
username = "username-default" # optional
password = "password-default" # optional
main(url=index_link, username=username, password=password)