Created
March 14, 2015 20:33
-
-
Save Igglybuff/a57a4133bf7b50dcf197 to your computer and use it in GitHub Desktop.
youtube-search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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