Python Code; Download Youtube Videos with Facebook
It is recommended that you receive a token..
just enter your Facebook login details and access token once, and every time you open the script, the script will read your passwords and tokens from the facevideo club it recorded on the first login. if you will use a different account or token FaceVideo in the classic mail.TXT and passw.token for TXT or token.delete the TXT files.
the first installation requires a one-time normal Internet connection to install some modules.
Important Note: run the script with the Pydroid application.
Tip: for easy access to code below: pytube.py export the file to the sdcard native language. You can run the code by typing import facetube each time you open the pydroid.. if you use Android 6 and above, once you touch the file icon in the top bar of the pydroid application and give the reader permission to read by saying ‘open’, otherwise you can not run the code by saying ‘import facetube’..
Python Youtube Video Download with Facebook Codes;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | #-*-coding:utf8;-*- import HTMLParser import urllib2 import re,sys,urllib,time,os from xml.sax import saxutils as su from urllib import quote, unquote import platform import subprocess windows = False if platform.platform().startswith("Linux"): try: os.makedirs('/sdcard/FaceVideo/') except: pass try: from termcolor import colored, cprint except: print "Gerekli modüller yükleniyor…\n" arg="pip install termcolor" os.system(sys.executable+" "+sys.prefix+"/bin/"+arg) os.execv(sys.executable, ['python'] + sys.argv) from termcolor import colored, cprint try: from bs4 import BeautifulSoup except: arg="pip install bs4" os.system(sys.executable+" "+sys.prefix+"/bin/"+arg) os.execv(sys.executable, ['python'] + sys.argv) from bs4 import BeautifulSoup try: import mechanize except: arg="pip install mechanize" os.system(sys.executable+" "+sys.prefix+"/bin/"+arg) os.execv(sys.executable, ['python'] + sys.argv) import mechanize try: import requests except: arg="pip install requests" os.system(sys.executable+" "+sys.prefix+"/bin/"+arg) os.execv(sys.executable, ['python'] + sys.argv) import requests try: from requests_toolbelt import MultipartEncoder except: arg="pip install requests_toolbelt" os.system(sys.executable+" "+sys.prefix+"/bin/"+arg) os.execv(sys.executable, ['python'] + sys.argv) from requests_toolbelt import MultipartEncoder else: try: from termcolor import colored, cprint except: print "Gerekli modüller yükleniyor…\n" subprocess.call(["python","-m","pip","install","termcolor"]) try: from bs4 import BeautifulSoup except: subprocess.call(["python","-m","pip","install","bs4"]) from termcolor import colored, cprint try: import mechanize except: subprocess.call(["python","-m","pip","install","mechanize"]) import mechanize try: import requests except: subprocess.call(["python","-m","pip","install","requests"]) import requests try: from requests_toolbelt import MultipartEncoder except: subprocess.call(["python","-m","pip","install","requests_toolbelt"]) from requests_toolbelt import MultipartEncoder try: from colorama import init init() except: subprocess.call(["python","-m","pip","install","colorama"]) from colorama import init init() windows = True if windows == True: def yaz(parametre, time_sleep = 0.009): sys.stdout.write(parametre) sys.stdout.flush() else: def yaz(parametre, time_sleep = 0.009): for i in parametre: time.sleep(time_sleep) sys.stdout.write(i) sys.stdout.flush() y=colored('Proje Adı : FaceTube Video Downloader \n','white','on_blue') a=colored('İletişim : http://www.qpython.club \n','white','on_blue') c=colored('Geliştirici: Ethnic \n','white','on_blue') des= colored('_'*60,'blue',attrs=['bold']) yaz(des+'\n\n'+y+'\n'+a+'\n'+c+'\n'+des+'\n',0.002) h = HTMLParser.HTMLParser() br = mechanize.Browser() br.set_handle_robots(False) br.addheaders = [('User-agent', 'Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.5 (like Gecko) (Kubuntu)')] if platform.platform().startswith("Linux"): try: token=open("/sdcard/FaceVideo/token.txt") token=token.read() except: token=open("/sdcard/FaceVideo/token.txt","w") token=token.write(raw_input(colored("Access Token : ",'blue',attrs=['bold']))) token=open("/sdcard/FaceVideo/token.txt") token=token.read() try: mail=open("/sdcard/FaceVideo/mail.txt") mail=mail.read() except: mail=open("/sdcard/FaceVideo/mail.txt","w") mail=mail.write(raw_input(colored("\nFacebook email : ",'blue',attrs=['bold']))) mail=open("/sdcard/FaceVideo/mail.txt") mail=mail.read() try: pasw=open("/sdcard/FaceVideo/pasw.txt") pasw=pasw.read() except: pasw=open("/sdcard/FaceVideo/pasw.txt","w") pasw=pasw.write(raw_input(colored("\nFacebook şifre : ",'blue',attrs=['bold']))) pasw=open("/sdcard/FaceVideo/pasw.txt") pasw=pasw.read() else: try: token=open("token.txt") token=token.read() except: token=open("token.txt","w") token=token.write(raw_input(colored("Access Token : ",'blue',attrs=['bold']))) token=open("token.txt") token=token.read() try: mail=open("mail.txt") mail=mail.read() except: mail=open("mail.txt","w") mail=mail.write(raw_input(colored("\nFacebook email : ",'blue',attrs=['bold']))) mail=open("mail.txt") mail=mail.read() try: pasw=open("pasw.txt") pasw=pasw.read() except: pasw=open("pasw.txt","w") pasw=pasw.write(raw_input(colored("\nFacebook şifre : ",'blue',attrs=['bold']))) pasw=open("pasw.txt") pasw=pasw.read() yaz(colored('\nFacebook Yükleniyor','blue',attrs=['bold'])) op=br.open("https://facebook.com") username=mail password=pasw yaz(colored('\n\n- Kullanici verileri isleniyor…','blue',attrs=['bold'])) br.select_form(nr=0) br.form["email"]=username br.form["pass"]=password br.method="POST" br.submit() yaz(colored("\n\n- Facebook'a giriş yapılıyor…",'blue',attrs=['bold'])) text=br.open("https://facebook.com").read() if(text.find("home_icon",0,len(text))!=-1): yaz(colored('\n\n- Başarıyla giriş yapıldı.\n\n','green',attrs=['dark'])+des+'\n\n',0.001) else: yaz(colored('\n\n- Giriş Yapılamadı! Lütfen Giriş bilgilerinizi kontrol ediniz\n','red',attrs=['bold'])) try: os.remove("/sdcard/FaceVideo/mail.txt") os.remove("/sdcard/FaceVideo/pasw.txt") quit() except: try: os.remove("mail.txt") os.remove("pasw.txt") quit() except: quit() face='https://developers.facebook.com/tools/debug/echo/?q=' def indir(son,isim): oku = urllib2.urlopen(son) toplam = int(oku.info().getheaders('Content-Length')[0]) if toplam < 1048576 : mb= str(toplam/1025) + ' kb' else: mb= str(toplam/1048576) + ' mb' print des+'\n\n' print colored('- Video boyutu : %s \n\n' % mb,'yellow',attrs=['bold']) uzanti = oku.info().getheaders('Content-Type')[0].split('/')[1] if uzanti == '3gpp': uzanti=uzanti.replace('3gpp','3gp') else: pass if platform.platform().startswith("Linux"): save=open("/sdcard/FaceVideo/"+isim+'.'+uzanti,"ab") else: save=open(isim+'.'+uzanti,"ab") sayi=0 sayi2=0 while True: a = toplam/50 b = oku.read(a) sayi += a if not b: break save.write(b) if(sayi < toplam): sayi+=0 sayi2+=2 kb= str(sayi/1048576) + ' mb' sys.stdout.write(colored("- Video idiriliyor : %%%s " % str(sayi2) + " %s \r" % str(kb),'green',attrs=['bold'])) sys.stdout.flush() yaz(colored('\n\n- Video FaceVideo klasörüne indirildi. \n\n','blue',attrs=['bold'])) def hdlink(title): yaz(colored('- Videonun hesabınıza yansıması bekleniyor.\n\n- Bu işlem bir kaç dk sürebilir…\n\n','blue',attrs=['bold'])) while True: try: hedef=h.unescape(br.open("http://facebook.com/profile.php?=73322363").read().decode('utf-8')) soup = BeautifulSoup(hedef, 'html.parser') vlin=re.findall('href="(.*?)videos_by',hedef)[-1]+'videos_by' break except: time.sleep(5) pass aut=0 while True: try: vlink=h.unescape(br.open(vlin).read().decode('utf-8')) except: print 'Bağlantı Hatası!' # print vlink try: vurl='https://www.facebook.com'+re.findall('class="async_saving _400z _2-40 __-q" href="(.*?)\"',vlink)[0] except: pass try: vtitle=re.findall('video_tab" aria-label="(.*?)ajaxify="#" rel="async"',vlink)[0] except: vtitle='' pass # print title # print vtitle if title in vtitle: durl=h.unescape(br.open(vurl).read().decode('utf-8')) try: try: hdurl=re.findall('hd_src:\"(.*?)\"',durl)[0] except: hdurl=re.findall('sd_src:\"(.*?)\"',durl)[0] except Exception as e: print e pass indir(hdurl,vtitle) break else: time.sleep(4) aut+=1 if aut == 20: yaz(colored('\n- Video bulunamadı!\n','red',attrs=['bold'])) break pass def put_video(video_url, page_id, access_token,description, title): yaz(colored('- Video Facebook\'a yükleniyor..\n\n- Bu işlem bir kaç dakika sürebilir \n\n','blue',attrs=['bold'])) video_file_name=title local_video_file=video_url path = "{0}/videos".format(page_id) fb_url = "https://graph-video.facebook.com/{0}?access_token={1}".format( path, access_token) m = MultipartEncoder( fields={'description': description, 'title': title, 'comment':'postvideo', 'file_url': video_url } ) r = requests.post(fb_url, headers={'Content-Type': m.content_type}, data=m) if r.status_code == 200: j_res = r.json() facebook_video_id = j_res.get('id') # print ("facebook_video_id = {0}".format(facebook_video_id)) yaz(colored("- Video hesabınıza yüklendi. \n\n",'green')) hdlink(title) else: yaz(colored("\n\n- Facebook upload error: {0}".format(r.text),'red',attrs=['bold'])) quit() def youtube(): google = raw_input(colored('Youtube\'da Ara : ','red',attrs=['bold'])) print '\n' google=google.replace(' ','+') query = urllib.quote(google) url = "https://www.youtube.com/results?search_query="+query try: html= h.unescape(br.open(face+url).read().decode('utf-8')) except: yaz(colored('\n-Bağlantı hatası! Veri bağlantısını kontrol edin.\n\n','red',attrs=['bold'])) quit() if str(c[29]) != 'c': quit() else: pass try: data=su.unescape(html, {'"':'"','&':'&'}) soup = BeautifulSoup(html, 'html.parser') sure=[] for sur in soup.findAll('span', class_="video-time"): sure.append(sur.getText()) say = 0 link= [] title1=[] for vid in soup.findAll(attrs={'class':'yt-uix-tile-link'}): adres= 'https://www.youtube.com' + vid['href'] say+=1 liste = str(say) + " — " + vid['title'] +' '+colored(sure[say-1],'green',attrs=['dark'])+'\n'+colored('-','red',attrs=['bold'])*60+'\n' link.append(adres) title1.append(vid['title']) yaz(liste,0.0001) print des+'\n' except Exception as e: print des+'\n' pass if not link: yaz(colored('\n- Sonuç bulunamadı! Yeniden deneyin.\n\n','red',attrs=['bold'])) youtube() else: pass yanlis = False while not yanlis: try: al=raw_input(colored('Video Seç : ','blue',attrs=['bold'])) cevap='http://video.genyoutube.net/'+link[int(al)-1].split('?v=')[1] isim=title1[int(al)-1] break except: yaz(colored('\n- Lütfen video numarasını doğru giriniz.\n\n','red',attrs=['bold'])) pass yaz(colored('\nSecilen ','blue',attrs=['bold'])+ colored(isim.encode('utf-8'),'cyan',attrs=['dark']) + '\n\n') res= h.unescape(br.open(face+cevap).read().decode('utf-8')) soup1 = BeautifulSoup(res, 'html.parser') sad=[] for vid in soup1.findAll('div',class_="col-md-3 col-sm-4 col-xs-6 text-center downbuttonbox"): sad.append(vid.find('a').get("href")) video_url=sad[0] page_id = "me" access_token=token description = "qpython.club" title = isim put_video(video_url, page_id, access_token, description, title) youtube() |
if you have a any issue please comment.