Add in things that changed from the original. First commit was to see the diff.

This commit is contained in:
Steven Smith 2013-07-15 22:57:24 +08:00
parent f0c8669dff
commit 6ea9187a3a

View file

@ -10,13 +10,17 @@ spotify_re = (r'(spotify:(track|album|artist|user):([a-zA-Z0-9]+))', re.I)
http_re = (r'(open\.spotify\.com\/(track|album|artist|user)\/'
'([a-zA-Z0-9]+))', re.I)
@hook.command
def sptfy(inp):
"""sptfy url - Shorten spotify url. There's NO REASON to use this command, just say the URL and the bot will return all info for it, AND the short url."""
# try:
# login = http.get("http://sptfy.com/login.php", post_data=urlencode({'loginUsername': 'xDCloudBot', 'loginPassword': 'rjgw67kf', 'submit': '', 'submitme': '1'}), cookies=True)
# except Exception as e:
# return inp
shortenurl = "http://sptfy.com/index.php"
data = urlencode({'longUrl': inp, 'shortUrlDomain': 1, 'submitted': 1, "customUrl": "", "shortUrlPassword": "", "shortUrlExpiryDate": "", "shortUrlUses": 0, "shortUrlType": 0})
data = urlencode({'longUrl': inp, 'shortUrlDomain': 1, 'submitted': 1, "shortUrlFolder": 6, "customUrl": "", "shortUrlPassword": "", "shortUrlExpiryDate": "", "shortUrlUses": 0, "shortUrlType": 0})
try:
soup = http.get_soup(shortenurl, post_data=data, cookies=True)
except:
return inp
try:
link = soup.find('div', {'class': 'resultLink'}).text.strip()
return link
@ -28,7 +32,11 @@ def sptfy(inp):
@hook.command
def spotify(inp):
"spotify <song> -- Search Spotify for <song>"
try:
data = http.get_json("http://ws.spotify.com/search/1/track.json", q=inp.strip())
except Exception as e:
return "Could not get track information: {}".format(e)
try:
type, id = data["tracks"][0]["href"].split(":")[1:]
except IndexError:
@ -39,7 +47,11 @@ def spotify(inp):
@hook.command
def spalbum(inp):
"spalbum <album> -- Search Spotify for <album>"
try:
data = http.get_json("http://ws.spotify.com/search/1/album.json", q=inp.strip())
except Exception as e:
return "Could not get album information: {}".format(e)
try:
type, id = data["albums"][0]["href"].split(":")[1:]
except IndexError:
@ -50,7 +62,11 @@ def spalbum(inp):
@hook.command
def spartist(inp):
"spartist <artist> -- Search Spotify for <artist>"
try:
data = http.get_json("http://ws.spotify.com/search/1/artist.json", q=inp.strip())
except Exception as e:
return "Could not get artist information: {}".format(e)
try:
type, id = data["artists"][0]["href"].split(":")[1:]
except IndexError:
@ -64,6 +80,7 @@ def spotify_url(match):
type = match.group(2)
spotify_id = match.group(3)
url = spuri.format(type, spotify_id)
# no error catching here, if the API is down fail silently
data = http.get_json("http://ws.spotify.com/lookup/1/.json", uri=url)
if type == "track":
name = data["track"]["name"]