change tvdb a bit because I am obsessive
This commit is contained in:
parent
1c474fb095
commit
bef56c0a93
|
@ -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,8 +21,8 @@ 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
|
||||||
def tv_next(inp):
|
def tv_next(inp):
|
||||||
|
@ -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_name = episode.findtext("EpisodeName")
|
|
||||||
#in the event of an unannounced episode title, users either leave the
|
|
||||||
#field out (None) or fill it with TBA
|
|
||||||
if episode_name == "TBA":
|
|
||||||
episode_name = None
|
|
||||||
|
|
||||||
episode_num = "S%02dE%02d" % (int(episode.findtext("SeasonNumber")),
|
episode_num = "S%02dE%02d" % (int(episode.findtext("SeasonNumber")),
|
||||||
int(episode.findtext("EpisodeNumber")))
|
int(episode.findtext("EpisodeNumber")))
|
||||||
#only include actually valid information, arranged in a familiar
|
|
||||||
#filename convention
|
episode_name = episode.findtext("EpisodeName")
|
||||||
episode_desc = ' - '.join([item for item in (episode_num, episode_name)
|
# in the event of an unannounced episode title, users either leave the
|
||||||
if item])
|
# field out (None) or fill it with TBA
|
||||||
|
if episode_name == "TBA":
|
||||||
|
episode_name = None
|
||||||
|
|
||||||
|
episode_desc = '%s' % episode_num
|
||||||
|
if episode_name:
|
||||||
|
episode_desc += ' - %s' % episode_name
|
||||||
|
|
||||||
if airdate > today:
|
if airdate > today:
|
||||||
next_eps = ['%s (%s)' % (first_aired, episode_desc)]
|
next_eps = ['%s (%s)' % (first_aired, episode_desc)]
|
||||||
|
|
Loading…
Reference in New Issue