from TheSilent.clear import *
from TheSilent.return_user_agent import *

import requests
import time

cyan = "\033[1;36m"
red = "\033[1;31m"

tor_proxy = {"http": "socks5h://localhost:9050", "https": "socks5h://localhost:9050"}

#create html sessions object
web_session = requests.Session()

#increased security
requests.packages.urllib3.disable_warnings()
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS += ":HIGH:!DH:!aNULL"

#increased security
try:
    requests.packages.urllib3.contrib.pyopenssl.util.ssl_.DEFAULT_CIPHERS += ":HIGH:!DH:!aNULL"

except AttributeError:
    pass

def osint(username, delay = 1, tor = False):
    clear()

    my_list = []

    special_list = ["_", "-", ".", ""]
    username_list = []
    
    website_dict = {"AllMyLinks":"https://allmylinks.com/{}", "Apple Developer":"https://developer.apple.com/forums/profile/{}", "Apple Discussions":"https://discussions.apple.com/profile/{}", "Archive.org":"https://archive.org/details/@{}", "Ask Fedora":"https://ask.fedoraproject.org/u/{}", "Bandcamp":"https://www.bandcamp.com/{}", "BitCoinForum":"https://bitcoinforum.com/profile/{}", "BongaCams":"https://pt.bongacams.com/profile/{}", "BraveCommunity":"https://community.brave.com/u/{}/", "BuyMeACoffee":"https://buymeacoff.ee/{}", "BuzzFeed":"https://buzzfeed.com/{}", "ChaturBate":"https://chaturbate.com/{}", "CloudflareCommunity":"https://community.cloudflare.com/u/{}", "CNET":"https://www.cnet.com/profiles/{}/", "Codecademy":"https://www.codecademy.com/profiles/{}", "Cryptomator Forum":"https://community.cryptomator.org/u/{}", "DailyMotion":"https://www.dailymotion.com/{}", "Fandom":"https://www.fandom.com/u/{}", "FortniteTracker":"https://fortnitetracker.com/profile/all/{}", "Freesound":"https://freesound.org/people/{}/", "Gamespot":"https://www.gamespot.com/profile/{}/", "Genius (Artists)":"https://genius.com/artists/{}", "Genius (Users)":"https://genius.com/{}", "geocaching":"https://www.geocaching.com/p/default.aspx?u={}", "Giphy":"https://giphy.com/{}", "GitHub":"https://www.github.com/{}", "GoodReads":"https://www.goodreads.com/{}", "HackerOne":"https://hackerone.com/{}", "Instagram":"https://www.picuki.com/profile/{}", "Instructables":"https://www.instructables.com/member/{}", "Linktree":"https://linktr.ee/{}", "Minecraft":"https://api.mojang.com/users/profiles/minecraft/{}", "Myspace":"https://myspace.com/{}", "Newgrounds":"https://{}.newgrounds.com", "OnlyFans":"https://onlyfans.com/api2/v2/users/{}", "OpenStreetMap":"https://www.openstreetmap.org/user/{}", "Oracle Community":"https://community.oracle.com/people/{}", "Pastebin":"https://pastebin.com/u/{}", "Patreon":"https://www.patreon.com/{}", "PCGamer":"https://forums.pcgamer.com/members/?username={}", "Periscope":"https://www.periscope.tv/{}/", "Pinterest":"https://www.pinterest.com/{}/", "PlayStore":"https://play.google.com/store/apps/developer?id={}", "Pokemon Showdown":"https://pokemonshowdown.com/users/{}", "Pornhub":"https://pornhub.com/users/{}", "Poshmark":"https://poshmark.com/closet/{}", "PyPi":"https://pypi.org/user/{}", "Quizlet":"https://quizlet.com/{}", "Roblox":"https://www.roblox.com/user.aspx?username={}", "RoyalCams":"https://royalcams.com/profile/{}", "Scratch":"https://scratch.mit.edu/users/{}", "Signal":"https://community.signalusers.org/u/{}", "Slack":"https://{}.slack.com", "Slant":"https://www.slant.co/users/{}", "SoundCloud":"https://soundcloud.com/{}", "SourceForge":"https://sourceforge.net/u/{}", "Speedrun.com":"https://speedrun.com/user/{}", "TikTok":"https://tiktok.com/@{}", "Trello":"https://trello.com/1/Members/{}", "TryHackMe":"https://tryhackme.com/p/{}", "Twitch":"https://m.twitch.tv/{}", "Vimeo":"https://vimeo.com/{}", "VirusTotal":"https://www.virustotal.com/ui/users/{}/avatar", "VSCO":"https://vsco.co/{}", "Wattpad":"https://www.wattpad.com/api/v3/users/{}/", "Xbox Gamertag":"https://xboxgamertag.com/search/{}", "xHamster":"https://xhamster.com/users/{}", "Xvideos":"https://xvideos.com/profiles/{}", "YouPorn":"https://youporn.com/uservids/{}"}
    type_dict = {"AllMyLinks":"Not Found[False]", "Apple Developer":"status_code", "Apple Discussions":"The page you tried was not found. You may have used an outdated link or may have typed the address (URL) incorrectly.[False]", "Archive.org":"cannot find account[False]", "Ask Fedora":"status_code", "Bandcamp":"status_code", "BitCoinForum":"The user whose profile you are trying to view does not exist.[False]", "BongaCams":"status_code", "BraveCommunity":"status_code", "BuyMeACoffee":"status_code", "BuzzFeed":"status_code", "ChaturBate":"status_code", "CloudflareCommunity":"status_code", "CNET":"status_code", "Codecademy":"This profile could not be found[False]", "Codecademy":"This profile could not be found", "Cryptomator Forum":"status_code", "DailyMotion":"status_code", "Fandom":"status_code", "FortniteTracker":"status_code", "Freesound":"status_code", "Gamespot":"status_code", "Genius (Artists)":"status_code", "Genius (Users)":"status_code", "geocaching":"status_code", "Giphy":"status_code", "GitHub":"status_code", "GoodReads":"status_code", "HackerOne":"{}[True]", "Instagram":"Nothing found![False]", "Instructables":"status_code", "Linktree":"status_code", "Minecraft":"status_code", "Myspace":"status_code", "Newgrounds":"status_code", "OnlyFans":"status_code", "OpenStreetMap":"status_code", "Oracle Community":"status_code", "Pastebin":"Not Found (#404)[False]", "Patreon":"status_code", "PCGamer":"The specified member cannot be found. Please enter a member's entire name.[False]", "Periscope":"status_code", "Pinterest":"@{}[True]", "PlayStore":"status_code", "Pokemon Showdown":"Pokemon Showdown", "Pornhub":"status_code", "Poshmark":"status_code", "PyPi":"status_code", "Quizlet":"Page Unavailable[False]", "Roblox":"Page cannot be found or no longer exists[False]", "RoyalCams":"status_code", "Scratch":"status_code", "Signal":"Oops! That page doesn\u2019t exist or is private.[False]", "Slack":"status_code", "Slant":"status_code", "SoundCloud":"status_code", "SourceForge":"status_code", "Speedrun.com":"not found.[False]", "TikTok":"status_code", "Trello":"model not found[False]", "TryHackMe":"status_code", "Twitch":"status_code", "Vimeo":"status_code", "VirusTotal":"status_code", "VSCO":"status_code", "Wattpad":"status_code", "Xbox Gamertag":"status_code", "xHamster":"status_code", "Xvideos":"status_code", "YouPorn":"status_code"}
    
    print(cyan + "checking " + str(len(website_dict)) + " websites\n")

    for i in special_list:
        new_name = username.replace(" ", i)
        username_list.append(new_name)     

    if " " not in username:
        for i in range(len(list(website_dict.values()))):
            time.sleep(delay)
            try:
                print(cyan + "Checking: " + list(website_dict)[i] + " (" + username + ")")
                
                if list(type_dict.values())[i] == "status_code":
                    url = list(website_dict.values())[i]
                    url = url.replace("{}", username)

                    if tor == True:
                        my_request = requests.get(url, headers = {"User-Agent" : return_user_agent()}, proxies = tor_proxy, timeout = (60,120)).status_code

                    if tor == False:
                        my_request = requests.get(url, headers = {"User-Agent" : return_user_agent()}, timeout = (5,30)).status_code

                    if my_request == 200:
                        print(cyan + "True: " + list(website_dict)[i] + " (" + username + ")")
                        my_list.append(list(website_dict)[i] + " (" + username + ")")

                if list(type_dict.values())[i] != "status_code":
                    url = list(website_dict.values())[i]
                    url = url.replace("{}", username)

                    if tor == True:
                        my_request = requests.get(url, headers = {"User-Agent" : return_user_agent()}, proxies = tor_proxy, timeout = (60,120)).text

                    if tor == False:
                        my_request = requests.get(url, headers = {"User-Agent" : return_user_agent()}, timeout = (5,30)).text
                    
                    parse = list(type_dict.values())[i].replace("{}", username)
                    parse = parse.replace("[False]", "")
                    parse = parse.replace("[True]", "")

                    if parse not in my_request and "[False]" in list(type_dict.values())[i]:
                        print(cyan + "True: " + list(website_dict)[i] + " (" + username + ")")
                        my_list.append(list(website_dict)[i] + " (" + username + ")")

                    if parse in my_request and "[True]" in list(type_dict.values())[i]:
                        print(cyan + "True: " + list(website_dict)[i] + " (" + username + ")")
                        my_list.append(list(website_dict)[i] + " (" + username + ")")

            except:
                print(red + "ERROR!")

    if " " in username:
        for i in range(len(list(website_dict.values()))):
            for new_name in username_list:
                time.sleep(delay)

                try:
                    
                    print("Checking: " + list(website_dict)[i] + " (" + new_name + ")")

                    if list(type_dict.values())[i] == "status_code":
                        url = list(website_dict.values())[i]
                        url = url.replace("{}", new_name)

                        if tor == True:
                            my_request = requests.get(url, headers = {"User-Agent" : return_user_agent()}, proxies = tor_proxy, timeout = (60,120)).status_code

                        if tor == False:
                            my_request = requests.get(url, headers = {"User-Agent" : return_user_agent()}, timeout = (5,30)).status_code

                        if my_request == 200:
                            print(cyan + "True: " + list(website_dict)[i] + " (" + new_name + ")")
                            my_list.append(list(website_dict)[i] + " (" + new_name + ")")

                    if list(type_dict.values())[i] != "status_code":
                        url = list(website_dict.values())[i]
                        url = url.replace("{}", new_name)

                        if tor == True:
                            my_request = requests.get(url, headers = {"User-Agent" : return_user_agent()}, proxies = tor_proxy, timeout = (60,120)).text

                        if tor == False:
                            my_request = requests.get(url, headers = {"User-Agent" : return_user_agent()}, timeout = (5,30)).text

                        parse = list(type_dict.values())[i].replace("{}", new_name)
                        parse = parse.replace("[False]", "")
                        parse = parse.replace("[True]", "")

                        if parse not in my_request and "[False]" in list(type_dict.values())[i]:
                            print(cyan + "True: " + list(website_dict)[i] + " (" + new_name + ")")
                            my_list.append(list(website_dict)[i] + " (" + new_name + ")")

                        if parse in my_request and "[True]" in list(type_dict.values())[i]:
                            print(cyan + "True: " + list(website_dict)[i] + " (" + new_name + ")")
                            my_list.append(list(website_dict)[i] + " (" + new_name + ")")

                except:
                    print(red + "ERROR!")

    print(cyan + "")
    clear()
    
    return my_list
