def download(media, session): return_bool = True count = 0 while count < 11: links = media["links"] def choose_link(session, links): for link in links: r = json_request(session, link, "HEAD", True, False) if not isinstance(r, requests.Response): continue header = r.headers content_length = int(header["content-length"]) if not content_length: continue return [link, content_length] result = choose_link(session, links) if not result: count += 1 continue link = result[0] content_length = result[1] date_object = datetime.strptime(media["postedAt"], "%d-%m-%Y %H:%M:%S") download_path = media["download_path"] timestamp = date_object.timestamp() if not overwrite_files: if check_for_dupe_file(download_path, content_length): format_image(download_path, timestamp) return_bool = False count += 1 break r = json_request(session, link, "GET", True, False) if not isinstance(r, requests.Response): return_bool = False count += 1 continue delete = False try: with open(download_path, 'wb') as f: delete = True for chunk in r.iter_content(chunk_size=1024): if chunk: # filter out keep-alive new chunks f.write(chunk) except (ConnectionResetError) as e: if delete: os.unlink(download_path) count += 1 continue except (requests.exceptions.ConnectionError, requests.exceptions.ChunkedEncodingError) as e: count += 1 continue except Exception as e: if delete: os.unlink(download_path) log_error.exception(str(e) + "\n Tries: " + str(count)) count += 1 continue format_image(download_path, timestamp) log_download.info("Link: {}".format(link)) log_download.info("Path: {}".format(download_path)) break return return_bool
def create_auth(session, user_agent, auth_array, max_auth=2): me_api = [] auth_count = 1 auth_version = "(V1)" count = 1 try: auth_cookie = [] auth_cookies = [{ 'name': 'cf_clearance', 'value': auth_array["cf_clearance"], 'domain': '.patreon.com' }] print while auth_count < max_auth + 1: if auth_count == 2: auth_version = "(V2)" if auth_array["session_id"]: del auth_cookies[2] count = 1 print("Auth " + auth_version) session.headers = { 'User-Agent': user_agent, 'Referer': 'https://patreon.com/' } if auth_array["session_id"]: found = False for auth_cookie in auth_cookies: if auth_array["session_id"] == auth_cookie["value"]: found = True break if not found: auth_cookies.append({ 'name': 'session_id', 'value': auth_array["session_id"], 'domain': '.patreon.com' }) for auth_cookie in auth_cookies: session.cookies.set(**auth_cookie) max_count = 10 while count < 11: print("Auth Attempt " + str(count) + "/" + str(max_count)) link = "https://www.patreon.com/api/current_user" r = json_request(session, link) count += 1 if not r: auth_cookies = [] continue me_api = r def resolve_auth(r): if 'error' in r: error = r["error"] error_message = r["error"]["message"] error_code = error["code"] if error_code == 0: print(error_message) if error_code == 101: error_message = "Blocked by 2FA." print(error_message) if auth_array["support_2fa"]: link = "https://onlyfans.com/api2/v2/users/otp?app-token=" + app_token count = 1 max_count = 3 while count < max_count + 1: print("2FA Attempt " + str(count) + "/" + str(max_count)) code = input("Enter 2FA Code\n") data = {'code': code, 'rememberMe': True} r = json_request(session, link, "PUT", data=data) if "error" in r: count += 1 else: print("Success") return [True, r] return [False, r["error"]["message"]] r = r["data"] if "id" not in r: result = resolve_auth(r) if not result[0]: error_message = result[1] if "token" in error_message: break if "Code wrong" in error_message: break continue else: continue r = r["attributes"] print("Welcome " + r["full_name"]) option_string = "username or profile link" array = dict() array["session"] = session array["option_string"] = option_string array["me_api"] = me_api return array auth_count += 1 except Exception as e: log_error.exception(e) # input("Enter to continue") array = dict() array["session"] = None array["me_api"] = me_api return array
def create_auth(session, user_agent, app_token, auth_array, max_auth=2): me_api = [] auth_count = 1 auth_version = "(V1)" count = 1 try: auth_id = auth_array["auth_id"] auth_cookies = [ {'name': 'auth_id', 'value': auth_id}, {'name': 'sess', 'value': auth_array["sess"]}, {'name': 'auth_hash', 'value': auth_array["auth_hash"]}, {'name': 'auth_uniq_'+auth_id, 'value': auth_array["auth_uniq_"]}, {'name': 'fp', 'value': auth_array["fp"]}, ] while auth_count < max_auth+1: if auth_count == 2: auth_version = "(V2)" if auth_array["sess"]: del auth_cookies[2] count = 1 print("Auth "+auth_version) sess = auth_array["sess"] session.headers = { 'User-Agent': user_agent, 'Referer': 'https://onlyfans.com/'} if auth_array["sess"]: found = False for auth_cookie in auth_cookies: if auth_array["sess"] == auth_cookie["value"]: found = True break if not found: auth_cookies.append( {'name': 'sess', 'value': auth_array["sess"], 'domain': '.onlyfans.com'}) for auth_cookie in auth_cookies: session.cookies.set(**auth_cookie) max_count = 10 while count < 11: print("Auth Attempt "+str(count)+"/"+str(max_count)) link = "https://onlyfans.com/api2/v2/users/customer?app-token="+app_token a = [session, link, sess, user_agent] session = create_sign(*a) r = json_request(session, link) count += 1 if not r: continue me_api = r def resolve_auth(r): if 'error' in r: error = r["error"] error_message = r["error"]["message"] error_code = error["code"] if error_code == 0: print(error_message) if error_code == 101: error_message = "Blocked by 2FA." print(error_message) if auth_array["support_2fa"]: link = "https://onlyfans.com/api2/v2/users/otp?app-token="+app_token count = 1 max_count = 3 while count < max_count+1: print("2FA Attempt "+str(count) + "/"+str(max_count)) code = input("Enter 2FA Code\n") data = {'code': code, 'rememberMe': True} r = json_request( session, link, "PUT", data=data) if "error" in r: count += 1 else: print("Success") return [True, r] return [False, r["error"]["message"]] if "name" not in r: result = resolve_auth(r) if not result[0]: error_message = result[1] if "token" in error_message: break if "Code wrong" in error_message: break continue else: continue print("Welcome "+r["name"]) option_string = "username or profile link" link = "https://onlyfans.com/api2/v2/subscriptions/count/all?app-token="+app_token r = json_request(session, link) if not r: break array = dict() array["session"] = session array["option_string"] = option_string array["subscriber_count"] = r["subscriptions"]["active"] array["me_api"] = me_api return array auth_count += 1 except Exception as e: log_error.exception(e) array = dict() array["session"] = None array["me_api"] = me_api return array
def create_auth(session, user_agent, app_token, auth_array): me_api = [] auth_count = 1 auth_version = "(V1)" count = 1 try: auth_cookies = [ ] while auth_count < 2: if auth_count == 2: auth_version = "(V2)" if auth_array["sess"]: del auth_cookies[2] count = 1 print("Auth "+auth_version) session.headers = { 'User-Agent': user_agent, 'Referer': 'https://stars.avn.com/'} if auth_array["sess"]: found = False for auth_cookie in auth_cookies: if auth_array["sess"] == auth_cookie["value"]: found = True break if not found: auth_cookies.append( {'name': 'sess', 'value': auth_array["sess"], 'domain': '.stars.avn.com'}) for auth_cookie in auth_cookies: session.cookies.set(**auth_cookie) while count < 11: print("Attempt "+str(count)+"/"+"10") link = "https://stars.avn.com/api2/v2/users/me" r = json_request(session, link) count += 1 if not r: auth_cookies = [] continue me_api = r if 'error' in r: error = r["error"] error_message = r["error"]["message"] if error["code"] == 101: error_message = "Blocked by 2FA." print(error_message) if "token" in error_message: break continue else: print("Welcome "+r["name"]) option_string = "username or profile link" array = dict() array["session"] = session array["option_string"] = option_string array["subscriber_count"] = r["followingCount"] array["me_api"] = me_api return array auth_count += 1 except Exception as e: log_error.exception(e) # input("Enter to continue") array = dict() array["session"] = None array["me_api"] = me_api return array
def create_session(user_agent, app_token, auth_array): me_api = [] auth_count = 1 auth_version = "(V1)" count = 1 max_threads = multiprocessing.cpu_count() try: auth_cookies = [ {'name': 'auth_id', 'value': auth_array["auth_id"]}, {'name': 'auth_hash', 'value': auth_array["auth_hash"]} ] while auth_count < 3: if auth_count == 2: auth_version = "(V2)" if auth_array["sess"]: del auth_cookies[2] count = 1 print("Auth "+auth_version) session = requests.Session() proxies = {'http': 'socks5://'+proxy, 'https': 'socks5://'+proxy} if proxy: session.proxies = proxies session.mount( 'https://', requests.adapters.HTTPAdapter(pool_connections=max_threads, pool_maxsize=max_threads)) session.headers = { 'User-Agent': user_agent, 'Referer': 'https://onlyfans.com/'} if auth_array["sess"]: found = False for auth_cookie in auth_cookies: if auth_array["sess"] == auth_cookie["value"]: found = True break if not found: auth_cookies.append( {'name': 'sess', 'value': auth_array["sess"], 'domain': '.onlyfans.com'}) for auth_cookie in auth_cookies: session.cookies.set(**auth_cookie) while count < 11: print("Attempt "+str(count)+"/"+"10") link = "https://onlyfans.com/api2/v2/users/customer?app-token="+app_token r = json_request(session, link) count += 1 if not r: auth_cookies = [] continue me_api = r if 'error' in r: error = r["error"] error_message = r["error"]["message"] if error["code"] == 101: error_message = "Blocked by 2FA." print(error_message) if "token" in error_message: break continue else: print("Welcome "+r["name"]) option_string = "username or profile link" link = "https://onlyfans.com/api2/v2/subscriptions/count/all?app-token="+app_token r = json_request(session, link) if not r: break array = dict() array["session"] = session array["option_string"] = option_string array["subscriber_count"] = r["subscriptions"]["active"] array["me_api"] = me_api return array auth_count += 1 except Exception as e: log_error.exception(e) # input("Enter to continue") array = dict() array["session"] = None array["me_api"] = me_api return array