change tvdb a bit because I am obsessive

This commit is contained in:
Ryan Hitchman 2010-09-10 21:23:17 -05:00
parent 1c474fb095
commit bef56c0a93
1 changed files with 15 additions and 19 deletions

View File

@ -4,18 +4,13 @@ modified by rmmh 2010
""" """
import datetime import datetime
from contextlib import closing
from urllib2 import URLError from urllib2 import URLError
from zipfile import ZipFile from zipfile import ZipFile
from cStringIO import StringIO
from lxml import etree from lxml import etree
from util import hook, http from util import hook, http
# StringIO fallback method from: http://effbot.org/librarybook/cstringio.htm
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
base_url = "http://thetvdb.com/api/" base_url = "http://thetvdb.com/api/"
api_key = "469B73127CA0C411" api_key = "469B73127CA0C411"
@ -26,7 +21,7 @@ def get_zipped_xml(*args, **kwargs):
except KeyError: except KeyError:
raise KeyError("must specify a path for the zipped file to be read") raise KeyError("must specify a path for the zipped file to be read")
with closing(StringIO(http.get(*args, **kwargs))) as zip_buffer: zip_buffer = StringIO(http.get(*args, **kwargs))
return etree.parse(ZipFile(zip_buffer, "r").open(path)) return etree.parse(ZipFile(zip_buffer, "r").open(path))
@hook.command @hook.command
@ -62,23 +57,24 @@ def tv_next(inp):
for episode in reversed(series.xpath('//Episode')): for episode in reversed(series.xpath('//Episode')):
first_aired = episode.findtext("FirstAired") first_aired = episode.findtext("FirstAired")
try: try:
airdate = datetime.date(*map(int, first_aired.split('-'))) airdate = datetime.date(*map(int, first_aired.split('-')))
except (ValueError, TypeError): except (ValueError, TypeError):
continue continue
episode_num = "S%02dE%02d" % (int(episode.findtext("SeasonNumber")),
int(episode.findtext("EpisodeNumber")))
episode_name = episode.findtext("EpisodeName") episode_name = episode.findtext("EpisodeName")
# in the event of an unannounced episode title, users either leave the # in the event of an unannounced episode title, users either leave the
# field out (None) or fill it with TBA # field out (None) or fill it with TBA
if episode_name == "TBA": if episode_name == "TBA":
episode_name = None episode_name = None
episode_num = "S%02dE%02d" % (int(episode.findtext("SeasonNumber")), episode_desc = '%s' % episode_num
int(episode.findtext("EpisodeNumber"))) if episode_name:
#only include actually valid information, arranged in a familiar episode_desc += ' - %s' % episode_name
#filename convention
episode_desc = ' - '.join([item for item in (episode_num, episode_name)
if item])
if airdate > today: if airdate > today:
next_eps = ['%s (%s)' % (first_aired, episode_desc)] next_eps = ['%s (%s)' % (first_aired, episode_desc)]