Created
April 20, 2012 21:49
-
-
Save NOLFXceptMe/2432102 to your computer and use it in GitHub Desktop.
Badly hacked together script to print the number of videos watched by 'Username'
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/env python | |
# Naveen Kumar Molleti | |
# 21st April 2012 | |
# Badly hacked together script to print the number of videos watched by 'Username' | |
# Dunno why but returns 1000000 for an a/c with a large history, must've missed something in the API doc | |
import httplib | |
import re | |
appdevkey="Your App Dev Key here" | |
url="https://www.google.com/accounts/ClientLogin" | |
username="Set Username here" | |
password="Set Password here" ## NOTE: Password in plaintext | |
service="youtube" | |
headers={'Context-Type':"application/x-www-form-urlencoded"} | |
conn=httplib.HTTPConnection("www.google.com") | |
conn.request('GET', url+ '?Email='+username+'&Passwd='+password+'&service=youtube', '', headers) | |
resplist=conn.getresponse().read().strip().split('\n') | |
respmap={} | |
for ele in resplist: | |
elesplit=ele.split('=') | |
respmap[elesplit[0]]=elesplit[1] | |
#print respmap | |
temp_headers={} | |
temp_headers['Authorization'], temp_headers['X-GData-Key'] = "GoogleLogin auth=" + respmap['Auth'], "key=" + appdevkey | |
conn.request('GET', 'https://gdata.youtube.com/feeds/api/users/default/watch_history?v=2','', temp_headers) | |
response=conn.getresponse() | |
responseXML=response.read() | |
#print responseXML | |
pattern=re.compile("<openSearch:totalResults>.*</openSearch:totalResults>") | |
result = pattern.findall(responseXML) | |
pattern=re.compile("\d+") | |
print pattern.findall(result[0])[0] | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment