Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
tkem committed Nov 18, 2015
1 parent 8ab0c6e commit 104fec8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 9 additions & 1 deletion mopidy_internetarchive/library.py
Expand Up @@ -67,10 +67,17 @@ def refresh(self, uri=None):
self.__lookup.clear()

def search(self, query=None, uris=None, exact=False):
# sanitize uris
uris = set(uris or [self.root_directory.uri])
if self.root_directory.uri in uris:
# TODO: from cached root collections?
uris.update(translator.uri(identifier)
for identifier in self.__config['collections'])
uris.remove(self.root_directory.uri)
try:
qs = translator.query(query, uris, exact)
except ValueError as e:
logger.info('Not searching %s: %s', Extension.ext_name, e)
logger.info('Not searching %s: %s', Extension.dist_name, e)
return None
else:
logger.debug('Internet Archive query: %s' % qs)
Expand Down Expand Up @@ -118,6 +125,7 @@ def __browse_views(self, identifier, scheme=Extension.ext_name):
return refs

def __browse_root(self):
# TODO: cache this
result = self.backend.client.search(
'mediatype:collection AND identifier:(%s)' % (
' OR '.join(self.__config['collections'])
Expand Down
9 changes: 6 additions & 3 deletions mopidy_internetarchive/translator.py
Expand Up @@ -34,8 +34,11 @@
'albumartist': lambda values: (
'creator:(%s)' % ' '.join(map(quote, values))
),
'artist': lambda values: (
'creator:(%s)' % ' '.join(map(quote, values))
),
'date': lambda values: (
# date:(2014-01-01) gives error
# TODO: sanitize, not quote date! date:(2014-01-01) gives error
' AND '.join('date:%s' % quote(value) for value in values)
)
}
Expand Down Expand Up @@ -171,9 +174,9 @@ def query(query, uris=None, exact=False):
elif parts.query or parts.fragment:
raise ValueError('Cannot search "%s"' % uri)
else:
pass
pass # root uri?
if collections:
terms.append(' collection:(%s)' % ' OR '.join(collections))
terms.append('collection:(%s)' % ' OR '.join(collections))
return ' AND '.join(terms)


Expand Down

0 comments on commit 104fec8

Please sign in to comment.