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