diff --git a/headphones/searcher.py b/headphones/searcher.py index ec60c3f6..3b53ee47 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -831,7 +831,7 @@ def searchTorrent(albumid=None, new=False, losslessOnly=False): logger.warn("What.cd credentials incorrect or site is down.") if whatcd: -# whatcd.enableCaching() + whatcd.enableCaching() logger.info("Getting artist information for %s..." % artistterm) artist = whatcd.getArtist(artistterm) artist_id = artist.getArtistId() @@ -855,8 +855,9 @@ def searchTorrent(albumid=None, new=False, losslessOnly=False): all_children = [] for group in release_torrent_groups: logger.info(u"Getting individual torrents for parent ID %s" % group.getTorrentParentId()) - all_children += group.getTorrentChildren() - logger.info(u"Found torrent IDs: %s" % ", ".join(all_children)) + new_children = group.getTorrentChildren() + all_children += new_children + logger.info(u"Found torrent IDs: %s" % ", ".join(new_children)) # cap at 10 matches, 1 per second to reduce hits on API...don't wanna get in trouble. # Might want to turn up number of matches later. # max_torrent_info_reads = 10 diff --git a/lib/whatapi.py b/lib/whatapi.py index 1d612133..ecdcd5cb 100755 --- a/lib/whatapi.py +++ b/lib/whatapi.py @@ -36,6 +36,7 @@ import re import urllib import shelve import tempfile +import threading from htmlentitydefs import name2codepoint as n2cp @@ -339,17 +340,22 @@ def getWhatcdNetwork(username="", password=""): class _ShelfCacheBackend(object): """Used as a backend for caching cacheable requests.""" + cache_lock = threading.Lock() + def __init__(self, file_path=None): self.shelf = shelve.open(file_path) def getHTML(self, key): - return self.shelf[key] + with _ShelfCacheBackend.cache_lock: + return self.shelf[key] def setHTML(self, key, xml_string): - self.shelf[key] = xml_string + with _ShelfCacheBackend.cache_lock: + self.shelf[key] = xml_string def hasKey(self, key): - return key in self.shelf.keys() + with _ShelfCacheBackend.cache_lock: + return key in self.shelf.keys() class Request(object):