Advertisement
Guest User

YT

a guest
Jun 19th, 2019
608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 11.69 KB | None | 0 0
  1. import requests
  2. import json
  3. import re
  4. import threading
  5. import urlparse
  6. import os
  7. import glob
  8. #import os
  9.  
  10. SUCCESS_LOGIN  = 0
  11. FAILED_LOGIN   = 0
  12. SUCCESS_ACTION = 0
  13. FAILED_ACTION  = 0
  14. Threadtimeout = 60
  15. ThreadPoolSize = 3
  16. storeThreads = []
  17.  
  18. def threadManager(function,Funcargs,Startthreshold,Threadtimeout=5):
  19.     if len(storeThreads) != Startthreshold:
  20.         storeThreads.append(threading.Thread(target=function,args=tuple(Funcargs) ))
  21.     if len(storeThreads) == Startthreshold:
  22.         for metaThread in storeThreads:
  23.             metaThread.start()
  24.         for metaThread in storeThreads:
  25.             metaThread.join(Threadtimeout)
  26.         del storeThreads[::]
  27.  
  28. def G_identifier(email,SessionManager):
  29.     while 1:
  30.         try:
  31.             params = (('hl', 'en'),('_reqid', '60794'),('rt', 'j'))
  32.             headers = {
  33.                 'x-same-domain': '1',
  34.                 'origin': 'https://accounts.google.com',
  35.                 'accept-encoding': 'gzip, deflate, br',
  36.                 'accept-language': 'en-US,en;q=0.9,ar;q=0.8',
  37.                 'google-accounts-xsrf': '1',
  38.                 'cookie': 'GAPS=1:5anptsFCcX86o8zx79JaMKbjR6SUSg:i9ZZi85-G8eD7wsC; ',
  39.                 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36',
  40.                 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8',
  41.                 'accept': '*/*',
  42.                 'referer': 'https://accounts.google.com/signin/v2/identifier?continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Fhl%3Den%26app%3Ddesktop%26next%3D%252F%26action_handle_signin%3Dtrue&hl=en&service=youtube&passive=true&uilel=3&flowName=GlifWebSignIn&flowEntry=ServiceLogin',
  43.                 'authority': 'accounts.google.com',
  44.                 'dnt': '1'
  45.             }
  46.             data = [
  47.               ('continue', 'https://www.youtube.com/signin?hl=en&app=desktop&next=%2F&action_handle_signin=true'),
  48.               ('service', 'youtube'),
  49.               ('hl', 'en'),
  50.               ('f.req', '["{email}","",[],null,"EG",null,null,2,false,true,[null,null,[2,1,null,1,"https://accounts.google.com/ServiceLogin?continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Fhl%3Den%26app%3Ddesktop%26next%3D%252F%26action_handle_signin%3Dtrue&hl=en&service=youtube&passive=true&uilel=3",null,[],4,[],"GlifWebSignIn"],1,[null,null,[]],null,null,null,true],"{email}"]'.format(email=email)),
  51.               ('cookiesDisabled', 'false'),
  52.               ('deviceinfo', '[null,null,null,[],null,"EG",null,null,[],"GlifWebSignIn",null,[null,null,[]]]'),
  53.               ('gmscoreversion', 'undefined'),
  54.               ('checkConnection', 'youtube:202:1'),
  55.               ('checkedDomains', 'youtube'),
  56.               ('pstMsg', '1')
  57.             ]
  58.             response = SessionManager.post('https://accounts.google.com/_/signin/sl/lookup', headers=headers, params=params, data=data)
  59.             return json.loads((response.content).replace(")]}'",""))[0][0][2]
  60.         except:
  61.             pass
  62. def login(identifier,password,SessionManager):
  63.     while(1):
  64.         try:
  65.             params = (('hl', 'en'),('_reqid', '260794'),('rt', 'j'))
  66.             headers = {
  67.                 'x-same-domain': '1',
  68.                 'origin': 'https://accounts.google.com',
  69.                 'accept-encoding': 'gzip, deflate, br',
  70.                 'accept-language': 'en-US,en;q=0.9,ar;q=0.8',
  71.                 'google-accounts-xsrf': '1',
  72.                 'cookie': 'GAPS=1:Q6gx2sQ34TRRxWUO3mC1_Be79xLYpA:akZ-LyOsSbAsOKOQ',
  73.                 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36',
  74.                 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8',
  75.                 'accept': '*/*',
  76.                 'referer': 'https://accounts.google.com/signin/v2/sl/pwd?continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Fhl%3Den%26app%3Ddesktop%26next%3D%252F%26action_handle_signin%3Dtrue&hl=en&service=youtube&passive=true&uilel=3&flowName=GlifWebSignIn&flowEntry=ServiceLogin&cid=1&navigationDirection=forward',
  77.                 'authority': 'accounts.google.com',
  78.                 'dnt': '1',
  79.             }
  80.             data = [
  81.               ('continue', 'https://www.youtube.com/signin?hl=en&app=desktop&next=%2F&action_handle_signin=true'),
  82.               ('service', 'youtube'),
  83.               ('hl', 'en'),
  84.               ('f.req', '["{G_identifier}",null,1,null,[1,null,null,null,["{Password}",null,true]],[null,null,[2,1,null,1,"https://accounts.google.com/ServiceLogin?continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Fhl%3Den%26app%3Ddesktop%26next%3D%252F%26action_handle_signin%3Dtrue&hl=en&service=youtube&passive=true&uilel=3",null,[],4,[],"GlifWebSignIn"],1,[null,null,[]],null,null,null,true]]'.format(G_identifier=identifier,Password=password)),
  85.               ('cookiesDisabled', 'false'),
  86.               ('deviceinfo', '[null,null,null,[],null,"EG",null,null,[],"GlifWebSignIn",null,[null,null,[]]]'),
  87.               ('gmscoreversion', 'undefined'),
  88.               ('checkConnection', 'youtube:202:1'),
  89.               ('checkedDomains', 'youtube'),
  90.               ('pstMsg', '1'),
  91.             ]
  92.             response = SessionManager.post('https://accounts.google.com/_/signin/sl/challenge', headers=headers, params=params, data=data)
  93.             login  = (response.content).replace(")]}'","")
  94.             login =  json.loads(login)
  95.             try:
  96.                 if "CheckCookie" in response:
  97.                     return 1
  98.                 if str(login[0][0][5][5]) == "INCORRECT_ANSWER_ENTERED":
  99.                     return 0
  100.             except:
  101.                 return 1
  102.         except:
  103.             pass
  104.  
  105. def YouTubeSubscribe(url,SessionManager):
  106.     while(1):
  107.         try:
  108.             html = SessionManager.get(url).content
  109.             session_token = (re.findall("XSRF_TOKEN\W*(.*)=", html , re.IGNORECASE)[0]).split('"')[0]
  110.             id_yt = url.replace("https://www.youtube.com/channel/","")
  111.             params = (('name', 'subscribeEndpoint'),)
  112.             data = [
  113.               ('sej', '{"clickTrackingParams":"","commandMetadata":{"webCommandMetadata":{"url":"/service_ajax","sendPost":true}},"subscribeEndpoint":{"channelIds":["'+id_yt+'"],"params":"EgIIAg%3D%3D"}}'),
  114.               ('session_token', session_token+"=="),
  115.             ]
  116.             response = SessionManager.post('https://www.youtube.com/service_ajax', params=params, data=data)
  117.             check_state = json.loads(response.content)['code']
  118.             #print response
  119.             if check_state == "SUCCESS":
  120.                 return 1
  121.             else:
  122.                 return 0
  123.         except:
  124.             pass
  125.  
  126. def LoginYT(SessionManager):
  127.     while(1):
  128.         try:
  129.             headers = {
  130.                 'authority': 'accounts.google.com',
  131.                 'upgrade-insecure-requests': '1',
  132.                 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36',
  133.                 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
  134.                 'referer': 'https://www.youtube.com/',
  135.                 'accept-encoding': 'gzip, deflate, br',
  136.                 'accept-language': 'en-US,en;q=0.9'
  137.             }
  138.             params = (
  139.                 ('passive', 'true'),
  140.                 ('continue', 'https://www.youtube.com/signin?app=desktop&next=%2F&hl=en&action_handle_signin=true'),
  141.                 ('hl', 'en'),
  142.                 ('uilel', '3'),
  143.                 ('service', 'youtube'),
  144.             )
  145.             SessionManager.get('https://accounts.google.com/ServiceLogin', headers=headers, params=params)
  146.             return 1
  147.         except:
  148.             pass
  149.  
  150. def YouTubeLike(url,SessionManager):
  151.     while (1):
  152.         try:
  153.             vid_id = urlparse.parse_qs(urlparse.urlparse(url).query)['v'][0]
  154.             html = SessionManager.get(url).content
  155.             session_token = (re.findall("XSRF_TOKEN\W*(.*)=", html , re.IGNORECASE)[0]).split('"')[0]
  156.             params = (('name', 'likeEndpoint'),)
  157.             data = [
  158.               ('sej', '{"clickTrackingParams":"","commandMetadata":{"webCommandMetadata":{"url":"/service_ajax","sendPost":true}},"likeEndpoint":{"status":"LIKE","target":{"videoId":"'+vid_id+'"}}}'),
  159.               ('session_token',session_token+"=="),
  160.             ]
  161.             response = SessionManager.post('https://www.youtube.com/service_ajax', params=params, data=data)
  162.             check_state = json.loads(response.content)['code']
  163.  
  164.             if check_state == "SUCCESS":
  165.                 return 1
  166.             else:
  167.                 return 0
  168.         except:
  169.             pass
  170.  
  171. def show_status(action="",channel_id="",live_count=""):
  172.     os.system("cls")
  173.     banner = """
  174. >>> ===================================================== <<<
  175. >>>                                                       <<<
  176. >>>       __   _______   ____  _   _  ___  ____           <<<
  177. >>>       \ \ / |_   _| / ___|| | | |/ _ \|  _ \         <<<
  178. >>>        \ V /  | |   \___ \| |_| | | | | |_) |         <<<
  179. >>>         | |   | |    ___) |  _  | |_| |  __/          <<<
  180. >>>         |_|   |_|   |____/|_| |_|\___/|_|             <<<
  181. >>>                                                       <<<
  182. >>> ===================================================== <<<
  183. >>> [DEV] : Amir A. shalaby                               <<<
  184. >>> [Version] : 5.8v                                      <<<
  185. >>> +++++++++++++++++++++++++++++++++++++++++++++++++++++ <<<
  186.  
  187. """
  188.     if action == "START":
  189.         print banner
  190.     if action == "YT_SUB":
  191.         s = "[+] Successful Logins   = {}\n[!] Failed Logins    = {}\n[Channel ID : {}] Live subscribers count = {}\n"
  192.         print banner
  193.         print s.format(SUCCESS_LOGIN,FAILED_LOGIN,channel_id,live_count)
  194.     if action == "YT_LIKE":
  195.         s = "[+] Successful Logins        = {}\n[+] Successful likes      = {}\n[!] Failed Logins = {}\n[!] Failed likes  = {}"
  196.         print banner
  197.         print s.format(SUCCESS_LOGIN,FAILED_LOGIN,SUCCESS_ACTION,FAILED_ACTION)
  198.  
  199.  
  200. def YTGetSubCount(url):
  201.     x = requests.get(url).content
  202.     x = x.split("subscriber-count")
  203.     x = x[1].split("</span>")
  204.     x =  re.findall('title="(.*?)"',x[0])[0]
  205.     return x
  206.  
  207. def main(email,password,action,YTUrl):
  208.         global FAILED_LOGIN
  209.         global SUCCESS_LOGIN
  210.         global SUCCESS_ACTION
  211.         global FAILED_ACTION
  212.  
  213.         SessionManager  = requests.Session()
  214.         identifier      = G_identifier(email,SessionManager)
  215.         logged          = login(identifier,password,SessionManager)
  216.         LoginYT(SessionManager)
  217.  
  218.         if not logged:
  219.             FAILED_LOGIN += 1
  220.             return "LOGIN_ERROR"
  221.         else:
  222.             SUCCESS_LOGIN += 1
  223.        
  224.        
  225.         if action.upper() == "YT_SUB":
  226.             try:
  227.                 if YouTubeSubscribe(YTUrl,SessionManager):
  228.                     pass
  229.                 else:
  230.                     FAILED_ACTION += 1
  231.             except:
  232.                 return "ERR_YT_SUB"
  233.            
  234.         if action.upper() == "YT_LIKE":
  235.             try:
  236.                 if YouTubeLike(YTUrl,SessionManager):
  237.                     pass
  238.                 else:
  239.                     FAILED_ACTION += 1
  240.             except:
  241.                 return "ERR_YT_LIKE"
  242. while (1):
  243.     try:
  244.         show_status("START")
  245.         action = ""
  246.         while (1):
  247.             action = raw_input("[*] Choose action (l = like , s = subscribe): ")
  248.             if action == "l":
  249.                 action = "YT_LIKE"
  250.                 break
  251.             if action == "s":
  252.                 action = "YT_SUB"
  253.                 break
  254.             print "[!] Are you sure that's right ? "
  255.         ThreadPoolSize_custom = raw_input("[*] Choose number of threads [default = {}] [press Enter to use defaults]: ".format(ThreadPoolSize))
  256.         if ThreadPoolSize_custom != "":
  257.             ThreadPoolSize = int(ThreadPoolSize_custom)
  258.         os.chdir(".")
  259.         for file in glob.glob("*.txt"):
  260.             print(" |_--> " + file)
  261.         while (1):
  262.             combo_file = raw_input("[*] Setect the name of your [Email:Password] Combo file: ")
  263.             try:
  264.                 read_combo  = open(combo_file,"r").read()
  265.                 break
  266.             except:
  267.                 print "[!] Check your [Email:Password] Combo file name !"
  268.         while (1):
  269.             ytfile = raw_input("[*] Setect the name of your [YouTube] Combo file: ")
  270.             try:
  271.                 yt_combo  = open(ytfile,"r").read()
  272.                 break
  273.             except:
  274.                 print "[!] Check your [YouTube] Combo file name !"
  275.         raw_input("[+] All Done! , Press Enter to start .. ")
  276.         for data in read_combo.split("\n"):
  277.             if data == "":break
  278.             email = data.split(":")[0]
  279.             password = data.split(":")[1]
  280.             for yturl in yt_combo.split("\n"):
  281.                 if yturl == "":break
  282.                 while(1):
  283.                     try:
  284.                         threadManager( main, [email,password,action ,yturl]  , ThreadPoolSize ,Threadtimeout)
  285.                         if action == "YT_SUB":
  286.                             live_count  = YTGetSubCount(yturl)
  287.                             channel_id = yturl.replace("https://www.youtube.com/channel/","").replace(" ","").replace("\n","")
  288.                             show_status(action,channel_id,live_count)
  289.                             break
  290.                         else:
  291.                             show_status(action)
  292.                             break
  293.                     except:
  294.                         pass
  295.         break
  296.     except Exception as e:
  297.         open('loop_error.txt','w').write(str(e))
  298.         pass
  299.    
  300.  
  301.     except Exception as e:
  302.         print "[!!!] Fetal Error {}".format(e)
  303.         open('error_log.txt','w').write(str(e))
  304.  
  305. print "[!] DONE"
  306. import time
  307. time.sleep(60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement