Skip to content

Commit

Permalink
Use offset attribute XPath for NewzNab providers
Browse files Browse the repository at this point in the history
Instead of requiring that NewzNab providers use a fixed DTD URI for the
newznab XML namespace, search for the nodes with an 'offset' attribute
and then use the one with a namespaced tag ending in 'response'.
  • Loading branch information
fauxfiction committed Dec 30, 2014
1 parent 0b54fbc commit 766e52c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion sickbeard/providers/newznab.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,22 @@ def _doSearch(self, search_params, show=None, max_age=0):

if parsedXML.tag == 'rss':
items = parsedXML.findall('.//item')
response = parsedXML.find('.//{http://www.newznab.com/DTD/2010/feeds/attributes/}response')
# Find all nodes with offset and total attributes
offset_nodes = parsedXML.findall('.//*[@offset]')
total_nodes = parsedXML.findall('.//*[@total]')
# Our set of candidates for the response tag is the union
# of the nodes with offset and total attributes since we
# expect both to be present
response_candidates = set(offset_nodes) & set(total_nodes)
# Filter out any nodes which are not namespaced 'response'
# tags
response_nodes = [node for node in response_candidates if node.tag.endswith('}response')]
# Verify that one and only one node matches and use it,
# return otherwise
if len(response_nodes) != 1:
logger.log("No valid response node was found in the API response!")
return results
response = response_nodes[0]

else:
logger.log(u"Resulting XML from " + self.name + " isn't RSS, not parsing it", logger.ERROR)
Expand Down

0 comments on commit 766e52c

Please sign in to comment.