forked from ikeadoorframe/OnlyFans-Downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
143 lines (116 loc) · 3.91 KB
/
main.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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import eel
import re
import os
import sys
import json
import shutil
import requests
from concurrent.futures import ThreadPoolExecutor
executor = ThreadPoolExecutor(max_workers=10)
def download_media(media):
global PROFILE
id = str(media["id"])
source = media["source"]["source"]
if media["type"] != "photo" and media["type"] != "video":
return
ext = re.findall('\.\w+\?', source)
if len(ext) == 0:
return
ext = ext[0][:-1]
path = "/" + media["type"] + "s/" + id + ext
file = id + ext
eel.sendLog(file + "\n")
r = requests.get(source, stream=True)
with open("downloads/" + PROFILE + path, 'wb') as f:
r.raw.decode_content = True
shutil.copyfileobj(r.raw, f)
def api_request(endpoint, getdata = None, postdata = None):
global URL
global API_URL
global API_HEADER
global APP_TOKEN
getparams = {
"app-token": APP_TOKEN
}
if getdata is not None:
for i in getdata:
getparams[i] = getdata[i]
if postdata is None:
return requests.get(URL + API_URL + endpoint,
headers=API_HEADER,
params=getparams)
else:
return requests.post(URL + API_URL + endpoint + "?app-token=" + APP_TOKEN,
headers=API_HEADER,
params=getparams,
data=postdata)
def get_user_info(profile):
info = api_request("/users/" + profile).json()
if "error" in info:
eel.sendLog("ERROR: " + info["error"]["message"] + "\n")
exit()
return info
@eel.expose
def start(username, access_token, user_agent, post_amount):
global API_HEADER
global API_HEADER
global APP_TOKEN
global PROFILE
global POST_LIMIT
USER_AGENT = user_agent
API_HEADER = {
"Accept": "application/json, text/plain, */*",
"User-Agent": USER_AGENT,
"Accept-Encoding": "gzip, deflate"
}
PROFILE = username
API_HEADER["access-token"] = access_token
POST_LIMIT = post_amount
with ThreadPoolExecutor(max_workers=10) as executor:
executor.submit(main)
def main():
global URL
global API_URL
global API_HEADER
global APP_TOKEN
global PROFILE
global POST_LIMIT
URL = "https://onlyfans.com"
API_URL = "/api2/v2"
APP_TOKEN = "33d57ade8c02dbc5a333db99ff9ae26a"
USER_INFO = {}
PROFILE_INFO = {}
PROFILE_ID = ""
eel.sendLog("Getting auth info...\n")
USER_INFO = get_user_info("customer")
API_HEADER["user-id"] = str(USER_INFO["id"])
eel.sendLog("Getting profile info...\n")
PROFILE_INFO = get_user_info(PROFILE)
PROFILE_ID = str(PROFILE_INFO["id"])
if not os.path.isdir("downloads"):
os.mkdir("downloads")
eel.sendLog("Created downloads\n")
if not os.path.isdir("downloads/" + PROFILE):
os.mkdir("downloads/" + PROFILE)
eel.sendLog("Created downloads/" + PROFILE + "\n")
if not os.path.isdir("downloads/" + PROFILE + "/photos"):
os.mkdir("downloads/" + PROFILE + "/photos")
eel.sendLog("Created downloads/" + PROFILE + "/photos" + "\n")
if not os.path.isdir("downloads/" + PROFILE + "/videos"):
os.mkdir("downloads/" + PROFILE + "/videos")
eel.sendLog("Created downloads/" + PROFILE + "/videos" + "\n")
eel.sendLog("Downloading content to downloads/" + PROFILE + "\n\n")
# get all user posts
eel.sendLog("Finding posts...\n")
posts = api_request("/users/" + PROFILE_ID + "/posts", getdata={"limit": POST_LIMIT}).json()
if len(posts) == 0:
eel.sendLog("ERROR: 0 posts found.\n")
exit()
eel.sendLog("Downloading " + str(len(posts)) + " posts...\n")
for post in posts:
if not post["canViewMedia"]:
continue
for media in post["media"]:
executor.submit(download_media, media)
eel.init('web')
eel.start('ofdl.html', size=(700, 321))