tvdb: don't download zip files, just use the xml endpoint

This commit is contained in:
Ryan Hitchman 2013-11-19 16:26:40 -08:00
parent 980ebad385
commit cb514dfede
1 changed files with 4 additions and 17 deletions

View File

@ -1,12 +1,9 @@
""" """
TV information, written by Lurchington 2010 TV information, written by Lurchington 2010
modified by rmmh 2010 modified by rmmh 2010, 2013
""" """
import datetime import datetime
from urllib2 import URLError
from zipfile import ZipFile
from cStringIO import StringIO
from lxml import etree from lxml import etree
from util import hook, http, timesince from util import hook, http, timesince
@ -16,21 +13,12 @@ base_url = "http://thetvdb.com/api/"
api_key = "469B73127CA0C411" api_key = "469B73127CA0C411"
def get_zipped_xml(*args, **kwargs):
try:
path = kwargs.pop("path")
except KeyError:
raise KeyError("must specify a path for the zipped file to be read")
zip_buffer = StringIO(http.get(*args, **kwargs))
return etree.parse(ZipFile(zip_buffer, "r").open(path))
def get_episodes_for_series(seriesname): def get_episodes_for_series(seriesname):
res = {"error": None, "ended": False, "episodes": None, "name": None} res = {"error": None, "ended": False, "episodes": None, "name": None}
# http://thetvdb.com/wiki/index.php/API:GetSeries # http://thetvdb.com/wiki/index.php/API:GetSeries
try: try:
query = http.get_xml(base_url + 'GetSeries.php', seriesname=seriesname) query = http.get_xml(base_url + 'GetSeries.php', seriesname=seriesname)
except URLError: except http.URLError:
res["error"] = "error contacting thetvdb.com" res["error"] = "error contacting thetvdb.com"
return res return res
@ -43,9 +31,8 @@ def get_episodes_for_series(seriesname):
series_id = series_id[0] series_id = series_id[0]
try: try:
series = get_zipped_xml(base_url + '%s/series/%s/all/en.zip' % series = http.get_xml(base_url + '%s/series/%s/all/en.xml' % (api_key, series_id))
(api_key, series_id), path="en.xml") except http.URLError:
except URLError:
res["error"] = "error contacting thetvdb.com" res["error"] = "error contacting thetvdb.com"
return res return res