forked from traut/lastfm-loved2grooveshark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
groovesharkeygen.py
38 lines (28 loc) · 1.1 KB
/
groovesharkeygen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
import urllib
import json
import md5
import getpass
print "Please provide your Grooveshark username and password as arguments."
gl = raw_input("Username: ")
gp = getpass.getpass("Password: ")
# Getting Grooveshark API key and endpoint URL
params = "user=%s&pass=%s" % (gl, gp)
gshark_response = urllib.urlopen("https://ssl.apishark.com/generateAPIKey", data=params)
result = gshark_response.read()
if result.rfind("is now") == -1 : print "Error getting API URL"
else:
a = result.rfind("is now")
grooveshark_url = result[a+8:a+32]
print "API URL: %s" % grooveshark_url
# Getting Grooveshark API authorization key
gp = md5.new(gp)
params = md5.new("%s%s" % (gl, gp.hexdigest()))
params = urllib.urlencode(dict(username=gl, token=params.hexdigest()))
gshark_response = json.load(urllib.urlopen("http://1.apishark.com/genGSAuth/", data=params))
if gshark_response['Success']:
grooveshark_gsauth = gshark_response['Result']
print "GSAuth: %s" % grooveshark_gsauth
else:
print "Error getting GSAuth string"
print "Authentication failed. Please check your username and password."