Skip to content

Instantly share code, notes, and snippets.

@Igglybuff
Created March 14, 2015 20:33
Show Gist options
  • Save Igglybuff/a57a4133bf7b50dcf197 to your computer and use it in GitHub Desktop.
Save Igglybuff/a57a4133bf7b50dcf197 to your computer and use it in GitHub Desktop.
youtube-search
#!/usr/bin/python3
import urllib.request
import urllib.parse
import re
import sys
inargs = sys.argv
inargs.remove(inargs[0])
inargs = ' '.join(inargs)
query_string = urllib.parse.urlencode({"search_query" : inargs})
html_content = urllib.request.urlopen("http://www.youtube.com/results?" + query_string)
search_results = re.findall(r'href=\"\/watch\?v=(.{11})', html_content.read().decode())
print("http://www.youtube.com/watch?v=" + search_results[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment