Advertisement
Thelorgoreng

Youtube search

Aug 15th, 2015
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. def tube(args):
  2.  try:
  3.                 search = args.split()
  4.                 import urllib.request
  5.                 with urllib.request.urlopen("http://gdata.youtube.com/feeds/api/videos?vq=%s&racy=include&orderby=relevance&max-results=1" % "+".join(search)) as url:
  6.                     udict = url.read().decode()
  7.                 a = re.finditer('http://www.youtube.com/watch\?v=(.+?)&', udict)
  8.                 matches = []
  9.                 for match in a:
  10.                     match = str(match.group(0))
  11.                     match = match[:42]
  12.                     matches.append(match)
  13.                
  14.                 id = random.choice(matches)
  15.                 id = id[31:]
  16.                 link = "http://www.youtube.com/watch?v=%s" % id
  17.                 info = youtube.Video(id)
  18.                 info_title = "%s..." % info.get_title()[:50]
  19.                 room.message("%s I Found: \"%s\" by %s. <b>%s</b>" % (sntonick(user.name), info_title, info.get_auth()[:50], link), True)
  20.  except Exception as e:
  21.                 room.message("%s I'm sorry, I was unable to find anything :|" % sntonick(user.name), True)
  22.                 print(e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement