Update valvesounds.py
This commit is contained in:
parent
59d615aa88
commit
ae258e6c37
1 changed files with 10 additions and 3 deletions
|
@ -1,13 +1,20 @@
|
||||||
from util import hook, http, web
|
from util import hook, http, web
|
||||||
import json
|
import json
|
||||||
from urllib2 import HTTPError
|
import urllib2
|
||||||
|
|
||||||
|
|
||||||
def get_sound_info(game, search):
|
def get_sound_info(game, search):
|
||||||
|
# Currently, http.get_json doesn't support adding headers.
|
||||||
|
def get_json(url, headers):
|
||||||
|
request = urllib2.Request(url)
|
||||||
|
request.add_header('User-Agent', http.ua_cloudbot)
|
||||||
|
opener = urllib2.build_opener()
|
||||||
|
return json.loads(opener.open(request))
|
||||||
|
|
||||||
search = search.replace(" ", "+")
|
search = search.replace(" ", "+")
|
||||||
try:
|
try:
|
||||||
data = http.get_json("http://p2sounds.blha303.com.au/search/%s/%s" % (game, search))
|
data = get_json("http://p2sounds.blha303.com.au/search/%s/%s" % (game, search))
|
||||||
except HTTPError as e:
|
except urllib2.HTTPError as e:
|
||||||
return "Error: " + json.loads(e.read())["error"]
|
return "Error: " + json.loads(e.read())["error"]
|
||||||
items = []
|
items = []
|
||||||
for item in data["items"]:
|
for item in data["items"]:
|
||||||
|
|
Reference in a new issue