Create a gist now

Instantly share code, notes, and snippets.

how to log in to otaku-streamers in python (vbulletin)
import cookielib
import md5
import re
import sys
import urllib
import urllib2
def login(username, password, cookie_file):
'''login to and save session cookies'''
login_url = ''
#create cookiejar
cj = cookielib.LWPCookieJar()
#tell urllib2 to handle cookies
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
#try to load existing cookies
#ignore_discard=True loads session cookies too
cj.load(cookie_file, ignore_discard=True)
print 'cookies loaded, checking if they are still valid...'
#check to see if login cookies still valid
response = urllib2.urlopen('')
html =
if 'class="welcomelink"' in html:
print 'already logged in as %s.' % username
#lets get out of here!
return True
#if cookie file does not exist we just keep going...
except IOError:
print 'logging in...'
#the onsubmit() javascript does this bit
password_md5 = md5.md5(password).hexdigest()
#build POST data (including hidden form fields)
post_data = urllib.urlencode({'vb_login_username': username,
's': '',
'securitytoken': 'guest',
'do': 'login',
'vb_login_md5password': password_md5,
'vb_login_md5password_utf': password_md5,
#POST to login page
response = urllib2.urlopen(login_url, post_data)
#check for login string
html =
if 'Thank you for logging in, %s.' % username in html:
print 'logged in to otaku-streamers as %s.' % username
#save cookies to disk (ignore_discard=True saves session cookies), ignore_discard=True)
return True
print 'login failed'
return False
def resolve(web_url):
'''return the video stream link for the given web page'''
#grab the page (we already installed our cookie processing opener
#so no need to do it again)
response = urllib2.urlopen(web_url)
html =
#find the video url
video_url = re.findall('"file", "(http.+?video.mp4")', html)
return video_url[0]
#if called from command line....
if __name__ == '__main__':
#get username and password from command line eg.
#python my_username my_password /path/to/otaku.cookies
username = sys.argv[1]
password = sys.argv[2]
cookie_file = sys.argv[3]
#do the login
success = login(username, password, cookie_file)
#resolve a link
print resolve(url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment