Skip to content

Commit

Permalink
Merge branch 'keyword-search' of https://github.com/dstjacques/Sick-B…
Browse files Browse the repository at this point in the history
  • Loading branch information
midgetspy committed Mar 24, 2012
2 parents f4c9975 + eeef7d3 commit 52ac48d
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions sickbeard/webserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -1553,26 +1553,35 @@ def searchTVDBForShowName(self, name, lang="en"):
lang = "en"

baseURL = "http://thetvdb.com/api/GetSeries.php?"
nameUTF8 = name.encode('utf-8')

params = {'seriesname': name.encode('utf-8'),
'language': lang}
# Use each word in the show's name as a possible search term
keywords = nameUTF8.split(' ')

finalURL = baseURL + urllib.urlencode(params)
# Insert the whole show's name as the first search term so best results are first
# ex: keywords = ['Some Show Name', 'Some', 'Show', 'Name']
keywords.insert(0, nameUTF8)

urlData = helpers.getURL(finalURL)
# Query the TVDB for each search term and build the list of results
results = []
for searchTerm in keywords:
params = {'seriesname': searchTerm,
'language': lang}

try:
seriesXML = etree.ElementTree(etree.XML(urlData))
except Exception, e:
logger.log(u"Unable to parse XML for some reason: "+ex(e)+" from XML: "+urlData, logger.ERROR)
return ''
finalURL = baseURL + urllib.urlencode(params)

series = seriesXML.getiterator('Series')
urlData = helpers.getURL(finalURL)

results = []
try:
seriesXML = etree.ElementTree(etree.XML(urlData))
except Exception, e:
logger.log(u"Unable to parse XML for some reason: "+ex(e)+" from XML: "+urlData, logger.ERROR)
return ''

series = seriesXML.getiterator('Series')

for curSeries in series:
results.append((int(curSeries.findtext('seriesid')), curSeries.findtext('SeriesName'), curSeries.findtext('FirstAired')))
for curSeries in series:
results.append((int(curSeries.findtext('seriesid')), curSeries.findtext('SeriesName'), curSeries.findtext('FirstAired')))

lang_id = tvdb_api.Tvdb().config['langabbv_to_id'][lang]

Expand Down

0 comments on commit 52ac48d

Please sign in to comment.