-
Notifications
You must be signed in to change notification settings - Fork 615
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c159a11
Showing
7 changed files
with
809 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
OnlyFans [LEGACY- NOT WORKING].py |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import requests | ||
from bs4 import BeautifulSoup | ||
from urllib.request import urlretrieve | ||
import os | ||
from multiprocessing.dummy import Pool as ThreadPool | ||
from multiprocessing import current_process, Pool | ||
import multiprocessing | ||
from itertools import product | ||
import re | ||
import json | ||
|
||
# You MUST fill all of this in for the script to work :D | ||
json_data = json.load(open('settings.json')) | ||
j_directory = json_data['directory']+"/Users/" | ||
app_token = json_data['app-token'] | ||
sess = json_data['sess'] | ||
user_agent = json_data['user-agent'] | ||
|
||
# You don't have to fill anything else in below this line :) | ||
auth_cookie = { | ||
'domain': '.onlyfans.com', | ||
'expires': None, | ||
'name': 'sess', | ||
'path': '/', | ||
'value': sess, | ||
'version': 0 | ||
} | ||
|
||
session = requests.Session() | ||
session.cookies.set(**auth_cookie) | ||
session.headers = { | ||
'User-Agent': user_agent, 'Referer': 'https://onlyfans.com/'} | ||
|
||
|
||
def link_check(link): | ||
r = session.get(link) | ||
raw_html = r.content | ||
html = BeautifulSoup(raw_html, 'html.parser') | ||
temp_user_id = html.find("div", {"class": "b-users"}).find("a", attrs={"data-user", True}) | ||
if temp_user_id: | ||
return temp_user_id["data-user"] | ||
return False | ||
|
||
|
||
def scrape_choice(): | ||
print('Scrape: a = Everything | b = Images | c = Videos') | ||
input_choice = input() | ||
image_api = "https://onlyfans.com/api2/v2/users/"+user_id+"/posts/photos?limit=1000&offset=0&order=publish_date_" \ | ||
"desc&app-token="+app_token+"" | ||
video_api = "https://onlyfans.com/api2/v2/users/"+user_id+"/posts/videos?limit=1000&offset=0&order=publish_date_" \ | ||
"desc&app-token="+app_token+"" | ||
if input_choice == "a": | ||
location = "/Images/" | ||
media_scraper(image_api, location, j_directory) | ||
print("Photos Finished") | ||
location = "/Videos/" | ||
media_scraper(video_api, location, j_directory) | ||
print("Videos Finished") | ||
return | ||
if input_choice == "b": | ||
location = "/Images/" | ||
media_scraper(image_api, location, j_directory) | ||
return | ||
if input_choice == "c": | ||
location = "/Videos/" | ||
media_scraper(video_api, location, j_directory) | ||
return | ||
|
||
|
||
def media_scraper(link, location, directory): | ||
r = session.get(link) | ||
y = json.loads(r.text) | ||
|
||
media_set = dict([]) | ||
media_count = 0 | ||
for media_api in y: | ||
for media in media_api["media"]: | ||
file = media["source"]["source"] | ||
media_set[media_count] = {} | ||
media_set[media_count]["link"] = file | ||
media_count += 1 | ||
|
||
if "/Users/" == directory: | ||
directory = os.path.dirname(os.path.realpath(__file__))+"/Users/"+username+location | ||
else: | ||
directory = directory+username+location | ||
|
||
print("DIRECTORY - " + directory) | ||
if not os.path.exists(directory): | ||
os.makedirs(directory) | ||
|
||
max_threads = multiprocessing.cpu_count() | ||
pool = ThreadPool(max_threads) | ||
pool.starmap(download_media, product(media_set.items(), [directory])) | ||
|
||
|
||
def download_media(media, directory): | ||
link = media[1]["link"] | ||
file_name = link.rsplit('/', 1)[-1] | ||
urlretrieve(link, directory + file_name) | ||
print(link) | ||
return | ||
|
||
|
||
while True: | ||
print('Input a username or profile link') | ||
input_link = input().strip() | ||
username = input_link.rsplit('/', 1)[-1] | ||
input_link = 'https://onlyfans.com/search/users/'+username | ||
user_id = link_check(input_link) | ||
if not user_id: | ||
print("User Not Found") | ||
print("First time? Did you forget to edit your settings.json file?") | ||
continue | ||
scrape_choice() | ||
print('Finished') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Open settings.json | ||
|
||
// OPTIONAL | ||
|
||
// Directory - Leave directory empty if you want files to be downloaded in the script folder | ||
|
||
// Directory - If you're going to fill, please remember to use forward ("/") slashes only | ||
|
||
|
||
// MANDATORY | ||
|
||
// It is MANDATORY to fill everything else in otherwise the script won't work | ||
|
||
// After logging in on the browser, go to www.onlyfans.com, then check the examples folder on how to get app-token, sess and user-agent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"directory":"","app-token":"","sess":"","user-agent":""} |