import re, json
import urllib, urllib2, cookielib
def get_download_url(project, download_id):
"""\
project: You can find it from project's home URL like http://HERE_IS_PROJECT.codeplex.com/
download_id: You can find it from project's downloads page, every downloadable file has
this kind of link; http://PROJECT.codeplex.com/downloads/get/HERE_IS_DOWNLOAD_ID
"""
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
opener.addheaders = [('User-agent', '')]
res=opener.open("http://%s.codeplex.com/downloads/get/%s"%(project, download_id))
html=res.read()
pattern = r'name="__RequestVerificationToken" type="hidden" value="(.*?)"'
token=re.search(pattern, html).groups()[0]
token2=filter(lambda s: s.startswith("__RequestVerificationToken2"), cj._cookies[".codeplex.com"]["/"].keys())[0]
post_data = urllib.urlencode({
"fileId": download_id,
"clickOncePath": "",
"allowRedirectToAds": False,
"__RequestVerificationToken": token,
"__RequestVerificationToken2": token2,
})
res=opener.open("http://%s.codeplex.com/releases/captureDownload"%project, post_data)
json_text=res.read()
download_url = json.loads(json_text)['RedirectUrl']
return download_url
def test():
download_id="582218"
project="wix"
print get_download_url(project, download_id)
if __name__=="__main__":
test()