#-*-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
def yaz(parametre, time_sleep = 0.009):
for i in parametre:
time.sleep(time_sleep)
sys.stdout.write(i)
sys.stdout.flush()
if platform.platform().startswith("Linux"):
try:
os.makedirs('/sdcard/FaceVideo/')
except:
pass
try:
from termcolor import colored, cprint
except:
yaz('- 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)
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)
try:
import mechanize
except:
arg="pip install mechanize"
os.system(sys.executable+" "+sys.prefix+"/bin/"+arg)
os.execv(sys.executable, ['python'] + sys.argv)
try:
import requests
except:
arg="pip install requests"
os.system(sys.executable+" "+sys.prefix+"/bin/"+arg)
os.execv(sys.executable, ['python'] + sys.argv)
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)
else:
try:
from termcolor import colored, cprint
except:
yaz("- Gerekli modüller yükleniyor...\n")
subprocess.call(["python","-m","pip","install","termcolor"])
from termcolor import colored, cprint
try:
from bs4 import BeautifulSoup
except:
subprocess.call(["python","-m","pip","install","bs4"])
from bs4 import BeautifulSoup
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 MultipartEncode
except:
subprocess.call(["python","-m","pip","install","requests_toolbelt"])
from requests_toolbelt import MultipartEncoder
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()
try:
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()
except:
yaz(colored('\n- Bir hata oluştu! Tekrar deneyin.\n','red',attrs=['bold']))
quit()
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- Giriş Yapılamadı! Lütfen Giriş bilgilerinizi kontrol ediniz\n','red',attrs=['bold']))
try:
try:
os.remove("/sdcard/mail.txt")
os.remove("/sdcard/pasw.txt")
quit()
except:
os.remove("mail.txt")
os.remove("pasw.txt")
quit()
except:
pass
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
try:
save=open("/sdcard/FaceVideo/"+isim+'.'+uzanti,"ab")
except:
save=open("/sdcard/"+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']))
hedef=h.unescape(br.open("https://facebook.com").read().decode('utf-8'))
soup = BeautifulSoup(hedef, 'html.parser')
for mid in soup.findAll(attrs={'class':'_2s25'}):
vlin=mid['href']+'/videos_by'
break
aut=0
while True:
vlink=h.unescape(br.open(vlin).read().decode('utf-8'))
vurl='https://www.facebook.com'+re.findall('<a class="\_\_\-\q" href="(.*?)\"',vlink)[0]
vtitle=re.findall('video_tab" aria-label="(.*?)" ajaxify="/',vlink)[0]
# print title
# print vtitle
if vtitle == title:
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(5)
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\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')
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'] + '\n'+colored('-','red',attrs=['bold'])*60+'\n'
link.append(adres)
title1.append(vid['title'])
yaz(liste,0.0001)
print des+'\n'
except:
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()