Merge pull request #147 from pylast/develop

Fix get_recent_tracks (and more)
This commit is contained in:
Hugo van Kemenade 2015-09-05 10:56:01 +03:00
commit b96dcddb3d

View file

@ -21,7 +21,7 @@
# https://github.com/pylast/pylast # https://github.com/pylast/pylast
import hashlib import hashlib
from xml.dom import minidom from xml.dom import minidom, Node
import xml.dom import xml.dom
import time import time
import shelve import shelve
@ -4014,6 +4014,16 @@ def _string(string):
return casted return casted
def cleanup_nodes(doc):
"""
Remove text nodes containing only whitespace
"""
for node in doc.documentElement.childNodes:
if node.nodeType == Node.TEXT_NODE and node.nodeValue.isspace():
doc.documentElement.removeChild(node)
return doc
def _collect_nodes(limit, sender, method_name, cacheable, params=None): def _collect_nodes(limit, sender, method_name, cacheable, params=None):
""" """
Returns a sequence of dom.Node objects about as close to limit as possible Returns a sequence of dom.Node objects about as close to limit as possible
@ -4029,8 +4039,9 @@ def _collect_nodes(limit, sender, method_name, cacheable, params=None):
while not end_of_pages and (not limit or (limit and len(nodes) < limit)): while not end_of_pages and (not limit or (limit and len(nodes) < limit)):
params["page"] = str(page) params["page"] = str(page)
doc = sender._request(method_name, cacheable, params) doc = sender._request(method_name, cacheable, params)
doc = cleanup_nodes(doc)
main = doc.documentElement.childNodes[1] main = doc.documentElement.childNodes[0]
if main.hasAttribute("totalPages"): if main.hasAttribute("totalPages"):
total_pages = _number(main.getAttribute("totalPages")) total_pages = _number(main.getAttribute("totalPages"))