import websocket
import json
import threading
import time
import urllib
from bs4 import BeautifulSoup as bs
########## infos ##########
channel = input('channel:\n>>')
trip = input('passwd:\n>>')
nick = input('nick:\n>>')
if trip == '':
pass
else:
nick = nick + '#' + trip
def _search_tube():
while True:
a=0
_input = json.loads(ws.recv())
if _input['cmd']=='chat':
if len(_input['text'].strip())>9:
if '`search ' in _input['text']:
_input=_input['text']
term=_input[8::]
encoded_search = urllib.parse.quote(term)
print(encoded_search)
url='https://youtube.com/results?search_query='+encoded_search
req = urllib.request.Request(url)
response = urllib.request.urlopen(req)
output=bs(response,'html.parser')
_result=[]
for vid in output.select(".yt-uix-tile-link"):
if a<1:
if vid["href"].startswith("/watch?v="):
a+=1
vid_info = {"title": vid["title"], "link": vid["href"], "id": vid["href"][vid["href"].index("=")+1:]}
title=vid_info['title']
link=vid_info['link']
url=title+'\t'+'https://youtube.com'+link
_send_msg(url)
def _send_msg(msg):
_send({"cmd": "chat", "text": msg})
def _send_to(target, msg):
_send({"cmd": "whisper", "nick": target, "text": msg})
def _send(pkg):
encoded = json.dumps(pkg)
ws.send(encoded)
def _stay_in_chat():
while ws.connected:
_send({"cmd": "ping"})
time.sleep(60)
def _send_msg_in_chat():
while True:
msg = input()
_send({"cmd": "chat", "text": msg})
ws = websocket.create_connection('wss://hack.chat/chat-ws')
_send({"cmd": "join", "channel": channel, "nick": nick})
threading.Thread(target=_stay_in_chat).start()
url= threading.Thread(target=_search_tube).start()
msg = threading.Thread(target=_send_msg_in_chat).start()
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}