Skip to content

Commit

Permalink
Fix #41: Drop exact search support.
Browse files Browse the repository at this point in the history
  • Loading branch information
tkem committed Sep 9, 2015
1 parent 50b655f commit 1d1198c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 405 deletions.
59 changes: 19 additions & 40 deletions mopidy_internetarchive/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import uritools

from . import Extension, translator
from .query import Query

SCHEME = Extension.ext_name

Expand Down Expand Up @@ -77,20 +76,6 @@ def __init__(self, config, backend):
self._cache = _cache(**ext_config)
self._tracks = {} # track cache for faster lookup

def lookup(self, uri):
try:
return [self._tracks[uri]]
except KeyError:
logger.debug("track lookup cache miss %r", uri)
try:
_, _, identifier, _, filename = uritools.urisplit(uri)
tracks = self._lookup(identifier)
self._tracks = trackmap = {t.uri: t for t in tracks}
return [trackmap[uri]] if filename else tracks
except Exception as e:
logger.error('Lookup failed for %s: %s', uri, e)
return []

def browse(self, uri):
logger.info('browse %r', uri)
try:
Expand All @@ -107,26 +92,27 @@ def browse(self, uri):
logger.error('Error browsing %s: %s', uri, e)
return []

def search(self, query=None, uris=None, exact=False):
if exact:
return self.find_exact(query, uris)
def lookup(self, uri):
try:
terms = []
for field, values in (query.iteritems() if query else []):
if field not in QUERY_MAPPING:
return None # no result if unmapped field
else:
terms.extend((QUERY_MAPPING[field], v) for v in values)
if uris:
urisplit = uritools.urisplit
ids = filter(None, (urisplit(uri).path for uri in uris))
terms.append(('collection', tuple(ids)))
return self._search(*terms)
return [self._tracks[uri]]
except KeyError:
logger.debug("track lookup cache miss %r", uri)
try:
_, _, identifier, _, filename = uritools.urisplit(uri)
tracks = self._lookup(identifier)
self._tracks = trackmap = {t.uri: t for t in tracks}
return [trackmap[uri]] if filename else tracks
except Exception as e:
logger.error('Error searching the Internet Archive: %s', e)
return None
logger.error('Lookup failed for %s: %s', uri, e)
return []

def refresh(self, uri=None):
self._cache.clear()
self._tracks.clear()

def find_exact(self, query=None, uris=None):
def search(self, query=None, uris=None, exact=False):
if exact:
return None # exact queries not supported
try:
terms = []
for field, values in (query.iteritems() if query else []):
Expand All @@ -138,18 +124,11 @@ def find_exact(self, query=None, uris=None):
urisplit = uritools.urisplit
ids = filter(None, (urisplit(uri).path for uri in uris))
terms.append(('collection', tuple(ids)))
result = self._search(*terms)
albums = filter(Query(query, True).match_album, result.albums)
return result.copy(albums=albums)
return self._search(*terms)
except Exception as e:
logger.error('Error searching the Internet Archive: %s', e)
return None

def refresh(self, uri=None):
logger.info('Clearing Internet Archive cache')
self._cache.clear()
self._tracks.clear()

@cachetools.cachedmethod(operator.attrgetter('_cache'))
def _browse_root(self):
logger.info('browse root')
Expand Down
206 changes: 0 additions & 206 deletions mopidy_internetarchive/query.py

This file was deleted.

Loading

0 comments on commit 1d1198c

Please sign in to comment.