Add in things that changed from the original. First commit was to see the diff.
This commit is contained in:
parent
f0c8669dff
commit
6ea9187a3a
1 changed files with 28 additions and 11 deletions
|
@ -3,20 +3,24 @@ import re
|
||||||
from util import hook, http
|
from util import hook, http
|
||||||
from urllib import urlencode
|
from urllib import urlencode
|
||||||
|
|
||||||
gateway = 'http://open.spotify.com/{}/{}' # http spotify gw address
|
gateway = 'http://open.spotify.com/{}/{}' # http spotify gw address
|
||||||
spuri = 'spotify:{}:{}'
|
spuri = 'spotify:{}:{}'
|
||||||
|
|
||||||
spotify_re = (r'(spotify:(track|album|artist|user):([a-zA-Z0-9]+))', re.I)
|
spotify_re = (r'(spotify:(track|album|artist|user):([a-zA-Z0-9]+))', re.I)
|
||||||
http_re = (r'(open\.spotify\.com\/(track|album|artist|user)\/'
|
http_re = (r'(open\.spotify\.com\/(track|album|artist|user)\/'
|
||||||
'([a-zA-Z0-9]+))', re.I)
|
'([a-zA-Z0-9]+))', re.I)
|
||||||
|
|
||||||
@hook.command
|
|
||||||
def sptfy(inp):
|
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)
|
# 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"
|
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})
|
||||||
soup = http.get_soup(shortenurl, post_data=data, cookies=True)
|
try:
|
||||||
|
soup = http.get_soup(shortenurl, post_data=data, cookies=True)
|
||||||
|
except:
|
||||||
|
return inp
|
||||||
try:
|
try:
|
||||||
link = soup.find('div', {'class': 'resultLink'}).text.strip()
|
link = soup.find('div', {'class': 'resultLink'}).text.strip()
|
||||||
return link
|
return link
|
||||||
|
@ -28,7 +32,11 @@ def sptfy(inp):
|
||||||
@hook.command
|
@hook.command
|
||||||
def spotify(inp):
|
def spotify(inp):
|
||||||
"spotify <song> -- Search Spotify for <song>"
|
"spotify <song> -- Search Spotify for <song>"
|
||||||
data = http.get_json("http://ws.spotify.com/search/1/track.json", q=inp.strip())
|
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:
|
try:
|
||||||
type, id = data["tracks"][0]["href"].split(":")[1:]
|
type, id = data["tracks"][0]["href"].split(":")[1:]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
@ -39,7 +47,11 @@ def spotify(inp):
|
||||||
@hook.command
|
@hook.command
|
||||||
def spalbum(inp):
|
def spalbum(inp):
|
||||||
"spalbum <album> -- Search Spotify for <album>"
|
"spalbum <album> -- Search Spotify for <album>"
|
||||||
data = http.get_json("http://ws.spotify.com/search/1/album.json", q=inp.strip())
|
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:
|
try:
|
||||||
type, id = data["albums"][0]["href"].split(":")[1:]
|
type, id = data["albums"][0]["href"].split(":")[1:]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
@ -50,7 +62,11 @@ def spalbum(inp):
|
||||||
@hook.command
|
@hook.command
|
||||||
def spartist(inp):
|
def spartist(inp):
|
||||||
"spartist <artist> -- Search Spotify for <artist>"
|
"spartist <artist> -- Search Spotify for <artist>"
|
||||||
data = http.get_json("http://ws.spotify.com/search/1/artist.json", q=inp.strip())
|
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:
|
try:
|
||||||
type, id = data["artists"][0]["href"].split(":")[1:]
|
type, id = data["artists"][0]["href"].split(":")[1:]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
@ -64,6 +80,7 @@ def spotify_url(match):
|
||||||
type = match.group(2)
|
type = match.group(2)
|
||||||
spotify_id = match.group(3)
|
spotify_id = match.group(3)
|
||||||
url = spuri.format(type, spotify_id)
|
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)
|
data = http.get_json("http://ws.spotify.com/lookup/1/.json", uri=url)
|
||||||
if type == "track":
|
if type == "track":
|
||||||
name = data["track"]["name"]
|
name = data["track"]["name"]
|
||||||
|
|
Reference in a new issue