mirror of
https://github.com/moparisthebest/SickRage
synced 2024-12-12 11:02:21 -05:00
Cleaned up code for TVDB/TVRage show searching.
This commit is contained in:
parent
1f178686cc
commit
36fd50fb9c
@ -164,7 +164,7 @@ def sanitizeFileName(name):
|
|||||||
return name
|
return name
|
||||||
|
|
||||||
|
|
||||||
def getURL(url, post_data=None, headers=None, timeout=None):
|
def getURL(url, post_data=None, headers=None, params=None, timeout=None):
|
||||||
"""
|
"""
|
||||||
Returns a byte-string retrieved from the url provider.
|
Returns a byte-string retrieved from the url provider.
|
||||||
"""
|
"""
|
||||||
@ -182,7 +182,7 @@ Returns a byte-string retrieved from the url provider.
|
|||||||
url = urlparse.urlunparse(parsed)
|
url = urlparse.urlunparse(parsed)
|
||||||
|
|
||||||
it = iter(req_headers)
|
it = iter(req_headers)
|
||||||
resp = requests.get(url, data=post_data, headers=dict(zip(it, it)))
|
resp = requests.get(url, params=params, data=post_data, headers=dict(zip(it, it)))
|
||||||
except requests.HTTPError, e:
|
except requests.HTTPError, e:
|
||||||
logger.log(u"HTTP error " + str(e.errno) + " while loading URL " + url, logger.WARNING)
|
logger.log(u"HTTP error " + str(e.errno) + " while loading URL " + url, logger.WARNING)
|
||||||
return None
|
return None
|
||||||
|
@ -1903,8 +1903,8 @@ class NewHomeAddShows:
|
|||||||
if not lang or lang == 'null':
|
if not lang or lang == 'null':
|
||||||
lang = "en"
|
lang = "en"
|
||||||
|
|
||||||
baseURL_TVDB = "http://thetvdb.com/api/GetSeries.php?"
|
baseURL_TVDB = "http://thetvdb.com/api/GetSeries.php"
|
||||||
baseURL_TVRAGE = "http://services.tvrage.com/feeds/search.php?"
|
baseURL_TVRAGE = "http://services.tvrage.com/feeds/search.php"
|
||||||
nameUTF8 = name.encode('utf-8')
|
nameUTF8 = name.encode('utf-8')
|
||||||
|
|
||||||
# Use each word in the show's name as a possible search term
|
# Use each word in the show's name as a possible search term
|
||||||
@ -1917,20 +1917,14 @@ class NewHomeAddShows:
|
|||||||
|
|
||||||
# Query the TVDB for each search term and build the list of results
|
# Query the TVDB for each search term and build the list of results
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
for searchTerm in keywords:
|
for searchTerm in keywords:
|
||||||
paramsTVDB = {'seriesname': searchTerm,
|
paramsTVDB = {'seriesname': searchTerm,
|
||||||
'language': lang}
|
'language': lang}
|
||||||
|
|
||||||
paramsTVRAGE = {'show': searchTerm}
|
paramsTVRAGE = {'show': searchTerm}
|
||||||
|
|
||||||
finalURL_TVDB = baseURL_TVDB + urllib.urlencode(paramsTVDB)
|
urlDataTVDB = helpers.getURL(baseURL_TVDB, params=paramsTVDB)
|
||||||
finalURL_TVRAGE = baseURL_TVRAGE + urllib.urlencode(paramsTVRAGE)
|
urlDataTVRAGE = helpers.getURL(baseURL_TVRAGE, params=paramsTVRAGE)
|
||||||
|
|
||||||
logger.log(u"Searching for Show with searchterm: \'" + searchTerm.decode('utf-8') + u"\' on URL " + finalURL_TVDB, logger.DEBUG)
|
|
||||||
|
|
||||||
urlDataTVDB = helpers.getURL(finalURL_TVDB)
|
|
||||||
urlDataTVRAGE = helpers.getURL(finalURL_TVRAGE)
|
|
||||||
|
|
||||||
if urlDataTVDB is None and urlDataTVRAGE is None:
|
if urlDataTVDB is None and urlDataTVRAGE is None:
|
||||||
# When urlData is None, trouble connecting to TVDB and TVRage, don't try the rest of the keywords
|
# When urlData is None, trouble connecting to TVDB and TVRage, don't try the rest of the keywords
|
||||||
@ -1945,20 +1939,21 @@ class NewHomeAddShows:
|
|||||||
try:
|
try:
|
||||||
seriesXML_TVDB = etree.ElementTree(etree.XML(urlDataTVDB))
|
seriesXML_TVDB = etree.ElementTree(etree.XML(urlDataTVDB))
|
||||||
seriesTVDB = seriesXML_TVDB.getiterator('Series')
|
seriesTVDB = seriesXML_TVDB.getiterator('Series')
|
||||||
except Exception, e:
|
|
||||||
# use finalURL in log, because urlData can be too much information
|
|
||||||
logger.log(u"Unable to parse XML from " + indexer + " for some reason: " + ex(e) + " from XML: " + finalURL_TVDB, logger.ERROR)
|
|
||||||
series = ''
|
|
||||||
|
|
||||||
# add each TVDB result to our list
|
# add each TVDB result to our list
|
||||||
for curSeries in seriesTVDB:
|
if seriesTVDB:
|
||||||
indexer_id = int(curSeries.findtext('seriesid'))
|
for curSeries in seriesTVDB:
|
||||||
|
indexer_id = int(curSeries.findtext('seriesid'))
|
||||||
|
|
||||||
# don't add duplicates
|
# don't add duplicates
|
||||||
if indexer_id in [x[0] for x in results]:
|
if indexer_id in [x[0] for x in results]:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
results.append((indexer, indexer_id, curSeries.findtext('SeriesName'), curSeries.findtext('FirstAired')))
|
results.append((indexer, indexer_id, curSeries.findtext('SeriesName'), curSeries.findtext('FirstAired')))
|
||||||
|
|
||||||
|
except Exception, e:
|
||||||
|
# use finalURL in log, because urlData can be too much information
|
||||||
|
logger.log(u"Unable to parse XML from " + indexer + " for some reason: " + ex(e), logger.ERROR)
|
||||||
|
|
||||||
if urlDataTVRAGE is not None:
|
if urlDataTVRAGE is not None:
|
||||||
indexer = "TVRage"
|
indexer = "TVRage"
|
||||||
@ -1968,20 +1963,20 @@ class NewHomeAddShows:
|
|||||||
try:
|
try:
|
||||||
seriesXML_TVRAGE = etree.ElementTree(etree.XML(urlDataTVRAGE))
|
seriesXML_TVRAGE = etree.ElementTree(etree.XML(urlDataTVRAGE))
|
||||||
seriesTVRAGE = seriesXML_TVRAGE.getiterator('show')
|
seriesTVRAGE = seriesXML_TVRAGE.getiterator('show')
|
||||||
|
|
||||||
|
# add each TVRAGE result to our list
|
||||||
|
for curSeries in seriesTVRAGE:
|
||||||
|
indexer_id = int(curSeries.findtext('showid'))
|
||||||
|
|
||||||
|
# don't add duplicates
|
||||||
|
if indexer_id in [x[0] for x in results]:
|
||||||
|
continue
|
||||||
|
|
||||||
|
results.append((indexer, indexer_id, curSeries.findtext('name'), curSeries.findtext('started')))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
# use finalURL in log, because urlData can be too much information
|
# use finalURL in log, because urlData can be too much information
|
||||||
logger.log(u"Unable to parse XML from " + indexer + " for some reason: " + ex(e) + " from XML: " + finalURL_TVRAGE, logger.ERROR)
|
logger.log(u"Unable to parse XML from " + indexer + " for some reason: " + ex(e), logger.ERROR)
|
||||||
series = ''
|
|
||||||
|
|
||||||
# add each TVRAGE result to our list
|
|
||||||
for curSeries in seriesTVRAGE:
|
|
||||||
indexer_id = int(curSeries.findtext('showid'))
|
|
||||||
|
|
||||||
# don't add duplicates
|
|
||||||
if indexer_id in [x[0] for x in results]:
|
|
||||||
continue
|
|
||||||
|
|
||||||
results.append((indexer, indexer_id, curSeries.findtext('name'), curSeries.findtext('started')))
|
|
||||||
|
|
||||||
lang_id = indexer_api.indexerApi().config['langabbv_to_id'][lang]
|
lang_id = indexer_api.indexerApi().config['langabbv_to_id'][lang]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user