From 348603188b86c8236c12cb6e37bd3851d0786e43 Mon Sep 17 00:00:00 2001 From: "Daniel St.Jacques" Date: Tue, 13 Mar 2012 08:46:57 -0400 Subject: [PATCH] Updated searching for new shows to also query each word individually --- sickbeard/webserve.py | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 6e79d7604a..abb8740389 100755 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -26,6 +26,7 @@ import threading import datetime import random +from sets import Set from Cheetah.Template import Template import cherrypy.lib @@ -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]