Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if "yt: " in msg.text.lower():
- query = msg.text.split(":")
- try:
- if len(query) == 3:
- isi = yt(query[2])
- hasil = isi[int(query[1])-1]
- cl.sendText(msg.to, 'Hasil Pencarian = ' + str(len(isi)) + " ini adalah hasil pencarian ke [" + str(query[1]) + "]")
- cl.sendText(msg.to, hasil)
- else:
- isi = yt(query[1])
- cl.sendText(msg.to, "Hasil Pencarian = " + str(len(isi)))
- cl.sendText(msg.to, isi[0])
- except Exception as e:
- print(e)
- def yt(query):
- with requests.session() as s:
- isi = []
- if query == "":
- query = "S1B nrik"
- s.headers['user-agent'] = 'Mozilla/5.0'
- url = 'http://www.youtube.com/results'
- params = {'search_query': query}
- r = s.get(url, params=params)
- soup = BeautifulSoup(r.content, 'html5lib')
- for a in soup.select('.yt-lockup-title > a[title]'):
- if '&List' not in a['href']:
- if 'watch?v' in a['href']:
- b = a['href'].replace('watch?v=','')
- isi += ['youtu.be' + b]
- return isi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement