diff --git a/mopidy/backends/local/library.py b/mopidy/backends/local/library.py index 0de63faf..24145e9a 100644 --- a/mopidy/backends/local/library.py +++ b/mopidy/backends/local/library.py @@ -58,7 +58,7 @@ class LocalLibraryProvider(base.BaseLibraryProvider): q = value.strip() uri_filter = lambda t: q == t.uri - track_filter = lambda t: q == t.name + track_filter = lambda t: int(q) == t.track_no album_filter = lambda t: q == getattr(t, 'album', Album()).name artist_filter = lambda t: filter( lambda a: q == a.name, t.artists) diff --git a/mopidy/frontends/mpd/protocol/music_db.py b/mopidy/frontends/mpd/protocol/music_db.py index f81d57ee..20d53a94 100644 --- a/mopidy/frontends/mpd/protocol/music_db.py +++ b/mopidy/frontends/mpd/protocol/music_db.py @@ -11,7 +11,7 @@ from mopidy.frontends.mpd.protocol import handle_request, stored_playlists QUERY_RE = ( r'(?P("?([Aa]lbum|[Aa]rtist|[Dd]ate|[Ff]ile|[Ff]ilename|' - r'[Tt]itle|[Aa]ny)"? "[^"]*"\s?)+)$') + r'[Tt]itle|[Tt]rack|[Aa]ny)"? "[^"]*"\s?)+)$') def _get_field(field, search_results): @@ -54,7 +54,16 @@ def count(context, mpd_query): - does not add quotes around the tag argument. - use multiple tag-needle pairs to make more specific searches. """ - return [('songs', 0), ('playtime', 0)] # TODO + try: + query = translator.query_from_mpd_search_format(mpd_query) + except ValueError: + return + results = context.core.library.find_exact(**query).get() + result_tracks = [] + + result_tracks = _get_tracks(results) + return [('songs', len(result_tracks)), + ('playtime', sum(track.length for track in result_tracks) / 1000)] @handle_request(r'^find ' + QUERY_RE) diff --git a/mopidy/frontends/mpd/translator.py b/mopidy/frontends/mpd/translator.py index df3338ba..8f70320d 100644 --- a/mopidy/frontends/mpd/translator.py +++ b/mopidy/frontends/mpd/translator.py @@ -195,7 +195,7 @@ def query_from_mpd_search_format(mpd_query): query_parts = re.findall(query_pattern, mpd_query) query_part_pattern = ( r'"?(?P([Aa]lbum|[Aa]rtist|[Dd]ate|[Ff]ile|[Ff]ilename|' - r'[Tt]itle|[Aa]ny))"? "(?P[^"]+)"') + r'[Tt]itle|[Tt]rack|[Aa]ny))"? "(?P[^"]+)"') query = {} for query_part in query_parts: m = re.match(query_part_pattern, query_part)