Skip to content

Commit

Permalink
Updated searching for new shows to also query each word individually
Browse files Browse the repository at this point in the history
  • Loading branch information
dstjacques committed Mar 13, 2012
1 parent 7a4287d commit 3486031
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions sickbeard/webserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import threading
import datetime
import random
from sets import Set

from Cheetah.Template import Template
import cherrypy.lib
Expand Down Expand Up @@ -1553,26 +1554,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 3486031

Please sign in to comment.