Facebook
From LOLI BOI 69, 3 Years ago, written in Python.
Embed
Download Paste or View Raw
Hits: 136
  1. import websocket
  2. import json
  3. import threading
  4. import time
  5. import urllib
  6. from bs4 import BeautifulSoup as bs
  7.  
  8. ##########    infos    ##########
  9.  
  10. channel = input('channel:\n>>')
  11. trip = input('passwd:\n>>')
  12. nick = input('nick:\n>>')
  13.  
  14. if trip == '':
  15.     pass
  16. else:
  17.     nick = nick + '#' + trip
  18.  
  19.    
  20.    
  21.    
  22. def _search_tube():
  23.     while True:
  24.         a=0
  25.         _input = json.loads(ws.recv())
  26.         if _input['cmd']=='chat':
  27.             if len(_input['text'].strip())>9:
  28.                 if '`search ' in _input['text']:
  29.                     _input=_input['text']
  30.                     term=_input[8::]
  31.                     encoded_search = urllib.parse.quote(term)
  32.                     print(encoded_search)
  33.                     url='https://youtube.com/results?search_query='+encoded_search
  34.                     req = urllib.request.Request(url)
  35.                     response = urllib.request.urlopen(req)
  36.                     output=bs(response,'html.parser')
  37.                     _result=[]
  38.                     for vid in output.select(".yt-uix-tile-link"):
  39.                         if a<1:
  40.                             if vid["href"].startswith("/watch?v="):
  41.                                 a+=1
  42.                                 vid_info = {"title": vid["title"], "link": vid["href"], "id": vid["href"][vid["href"].index("=")+1:]}
  43.                                 title=vid_info['title']
  44.                                 link=vid_info['link']
  45.                                 url=title+'\t'+'https://youtube.com'+link
  46.                                 _send_msg(url)
  47.  
  48.  
  49.    
  50.    
  51. def _send_msg(msg):
  52.     _send({"cmd": "chat", "text": msg})
  53.  
  54. def _send_to(target, msg):
  55.     _send({"cmd": "whisper", "nick": target, "text": msg})
  56.  
  57. def _send(pkg):
  58.     encoded = json.dumps(pkg)
  59.     ws.send(encoded)
  60.  
  61. def _stay_in_chat():
  62.     while ws.connected:
  63.         _send({"cmd": "ping"})
  64.         time.sleep(60)
  65.  
  66. def _send_msg_in_chat():
  67.     while True:
  68.         msg = input()
  69.         _send({"cmd": "chat", "text": msg})
  70.  
  71.  
  72.  
  73.                                
  74.                                
  75.  
  76. ws = websocket.create_connection('wss://hack.chat/chat-ws')
  77.  
  78. _send({"cmd": "join", "channel": channel, "nick": nick})
  79. threading.Thread(target=_stay_in_chat).start()
  80.  
  81.  
  82. url= threading.Thread(target=_search_tube).start()
  83. msg = threading.Thread(target=_send_msg_in_chat).start()
  84.  
  85.