ajithkp560

Facebook Video Downloader in Python [GUI]

Sep 21st, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.46 KB | None | 0 0
  1. #!/bin/python
  2.  
  3. # Download project with dependencies: https://github.com/ajithkp560/fbvideo-dl
  4.  
  5. import urllib2
  6. from beautifulsoup.beautifulsoup import BeautifulSoup
  7. from Tkinter import *
  8. import Tix as tk
  9. from tkinter.ttk import Progressbar, Style
  10.  
  11. print '''
  12. [][][*] c0ded by Ajith Kp (ajithkp560) [http://www.terminalcoders.blogspot.com]
  13. [][][*] HTML Parser: BeautifulSoup
  14. [][][*] GUI: tk
  15. [][][*] If tk is not installed run $ sudo apt-get install python-tk
  16. [][][*] Grab the URL to input by right click on video and click 'Copy Video URL at current time'
  17. '''
  18.  
  19.  
  20. class GUI:
  21.     def __init__(self,v):
  22.         self.main=v
  23.         self.t = StringVar()
  24.         self.t.set(":.: Facebook Video Download Tool :.:")
  25.         self.label=Label(v, textvariable=self.t, font='Helvetica -14 bold', bg='#3b5998', fg='#fcfcfc')
  26.         self.label.config(highlightbackground='#fcfcfc')
  27.         self.label.pack(padx=10, pady=10)
  28.        
  29.         self.entry = Entry(v, width=65, bg='#3b5998', fg='#fcfcfc')
  30.         self.entry.config(highlightbackground='#fcfcfc')
  31.         self.entry.pack(padx=10, pady=10)
  32.        
  33.         self.button=Button(v, text="Download",command=self.pressButton, bg="#3b5998", fg="#fcfcfc")
  34.         self.button.config(highlightbackground='#fcfcfc')
  35.         self.button.pack(padx=10, pady=10)
  36.        
  37.        
  38.         self.n = 0
  39.     def pressButton(self):
  40.         link = self.entry.get()
  41.         try:
  42.             res = urllib2.urlopen(link)
  43.             html = res.read().decode("iso-8859-1")
  44.             soup = BeautifulSoup(html)
  45.             tag = soup.find('meta',  property='og:video')#soup.body.find('meta', attrs={'property' : 'og:video:url'}).text
  46.             vid_url = tag['content']
  47.             file_name = vid_url.split('/')[-1].split('?')[0]#vid_url[vid_url.rfind("/")+1:]
  48.            
  49.             s = Style()
  50.             s.theme_use("classic")  
  51.             s.configure("green.Horizontal.TProgressbar", foreground='green', background='green')
  52.             self.progress = Progressbar(self.main, style="green.Horizontal.TProgressbar", orient = HORIZONTAL, length = 100, mode = 'determinate')
  53.             self.progress.pack(pady = 10)
  54.            
  55.             nhandler = urllib2.urlopen(vid_url)
  56.             vid_file = open(file_name, 'wb')
  57.             meta = nhandler.info()
  58.             filesize = int (meta.getheaders ("Content-Length")[0])  
  59.             filesizedown = 0
  60.             blocksize = 10000
  61.             self.message=Label(w, text='Download: %d / %d'%(filesizedown, filesize), font='Helvetica -13 bold', fg='#fcfcfc', bg='#3b5998')            
  62.             self.message.pack(padx=10, pady=10)
  63.             while True:
  64.                 buffer = nhandler.read(blocksize)
  65.                 if not buffer:
  66.                     break
  67.                 filesizedown += len(buffer)
  68.                 vid_file.write(buffer)
  69.                 percent = filesizedown * 100. / filesize
  70.                 self.progress['value'] = percent
  71.                 self.main.update_idletasks()
  72.                 self.message['text'] = 'Download: %d / %d'%(filesizedown, filesize)
  73.             self.message['text']='Download Completed'
  74.             self.message['fg']='#ccffcc'
  75.         except Exception, e:
  76.             self.label=Label(w, text="Error: %s"%(e), font='Helvetica -13 bold', fg='#fcfcfc', bg='#3b5998')
  77.             self.label.pack()
  78. w=Tk()
  79. w.configure(background='#3b5998')
  80. w.title("Facebook Video Downloader by Ajith Kp")
  81. w.minsize(300,200)
  82. gui=GUI(w)
  83. w.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment