Skip to content

Commit

Permalink
no tracktotal in beets schema albums, get_distinct started
Browse files Browse the repository at this point in the history
  • Loading branch information
rawdlite committed Jun 23, 2015
1 parent 67f7a44 commit 304d8dd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
45 changes: 29 additions & 16 deletions mopidy_beetslocal/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,15 @@ def lookup(self, uri):
def get_distinct(self, field, query=None):
logger.warn('get_distinct called field: %s, Query: %s' % (field,
query))
q = []
for key, values in (query.items() if query else []):
q.extend((key, value) for value in values)
logger.warn(q)
logger.info('get_distinct not fully implemented yet')
result = []
if field == 'artist':
result = self._browse_artist(query)
elif field == 'genre':
result = self._browse_genre()
else:
result = []
return set([v[0] for v in result])

def _browse_track(self, query):
return self.lib.items('album_id:\'%s\'' % query['album'])
Expand All @@ -184,11 +189,19 @@ def _browse_album(self, query):
return self.lib.albums('mb_albumartistid:\'%s\' genre:\'%s\''
% (query['artist'], query['genre']))

def _browse_artist(self, query):
return self._query_beets_db('select Distinct albumartist, '
'mb_albumartistid from albums where '
'genre = \"%s\" order by albumartist'
% query['genre'])
def _browse_artist(self, query=None):
statement = 'select Distinct albumartist, mb_albumartistid from albums'
if query:
statement += ' where 1=1 '
statement += self._build_statement(query, 'genre', 'genre')
statement += self._build_statement(query, 'artist', 'albumartist')
statement += self._build_statement(query, 'album', 'album')
statement += self._build_statement(query, 'mb_albumid',
'mb_albumid')
statement += self._build_statement(query, 'date', 'year')
statement += ' order by albumartist'
logger.debug('browse_artist: %s' % statement)
return self._query_beets_db(statement)

def _browse_genre(self):
return self._query_beets_db('select Distinct genre '
Expand Down Expand Up @@ -278,7 +291,7 @@ def _find_tracks(self, query):

def _find_albums(self, query):
statement = ('select id, album, day, month, year, '
'albumartist, tracktotal, disctotal, '
'albumartist, disctotal, '
'mb_albumid, artpath, mb_albumartistid '
'from albums where 1=1 ')
statement += self._build_statement(query, 'genre', 'genre')
Expand All @@ -298,15 +311,15 @@ def _find_albums(self, query):
except:
date = None
artist = Artist(name=row[5],
musicbrainz_id=row[10],
uri="beetslocal:artist:%s:" % row[10])
musicbrainz_id=row[9],
uri="beetslocal:artist:%s:" % row[9])
albums.append(Album(name=row[1],
date=date,
artists=[artist],
num_tracks=row[6],
num_discs=row[7],
musicbrainz_id=row[8],
images=[row[9]],
# num_tracks=row[6],
num_discs=row[6],
musicbrainz_id=row[7],
images=[row[8]],
uri="beetslocal:album:%s:" % row[0]))
return albums

Expand Down
2 changes: 1 addition & 1 deletion xunit-py27.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0" encoding="UTF-8"?><testsuite name="nosetests" tests="3" errors="0" failures="0" skip="0"><testcase classname="tests.test_extension.ExtensionTest" name="test_get_config_schema" time="0.011"></testcase><testcase classname="tests.test_extension.ExtensionTest" name="test_get_default_config" time="0.005"></testcase><testcase classname="tests.test_extension.ExtensionTest" name="test_setup" time="0.009"></testcase></testsuite>
<?xml version="1.0" encoding="UTF-8"?><testsuite name="nosetests" tests="3" errors="0" failures="0" skip="0"><testcase classname="tests.test_extension.ExtensionTest" name="test_get_config_schema" time="0.011"></testcase><testcase classname="tests.test_extension.ExtensionTest" name="test_get_default_config" time="0.004"></testcase><testcase classname="tests.test_extension.ExtensionTest" name="test_setup" time="0.011"></testcase></testsuite>

0 comments on commit 304d8dd

Please sign in to comment.