Skip to content

Commit

Permalink
fixes for mopidy 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rawdlite committed Aug 25, 2016
1 parent f11f8b7 commit a564601
Showing 1 changed file with 29 additions and 38 deletions.
67 changes: 29 additions & 38 deletions mopidy_beetslocal/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self, *args, **kwargs):
def _find_exact(self, query=None, uris=None):
logger.debug("Find query: %s in uris: %s" % (query, uris))
# artists = []
# import pdb; pdb.set_trace()
albums = []
if not (('track_name' in query) or ('composer' in query)):
# when trackname or composer is queried dont search for albums
Expand Down Expand Up @@ -288,6 +289,19 @@ def _build_statement(self, query, query_key, beets_key):
query_string)
return statement

def _build_date(self, year, month, day):
month = 1 if month == 0 else month
day = 1 if day == 0 else day
try:
d = datetime.datetime(
year,
month,
day)
date = '{:%Y-%m-%d}'.format(d)
except:
date = None
return date

def _find_tracks(self, query):
statement = ('select id, title, day, month, year, artist, album, '
'composer, track, disc, length, bitrate, comments, '
Expand All @@ -308,14 +322,7 @@ def _find_tracks(self, query):
tracks = []
result = self._query_beets_db(statement)
for row in result:
try:
d = datetime.datetime(
row[4],
row[3],
row[2])
date = '{:%Y-%m-%d}'.format(d)
except:
date = None
date = self._build_date(row[4], row[3], row[2])
artist = Artist(name=row[5],
musicbrainz_id=row[21],
uri="beetslocal:artist:%s:" % row[21])
Expand All @@ -338,8 +345,8 @@ def _find_tracks(self, query):
composers=[composer],
track_no=row[8],
disc_no=row[9],
date=row[4],
length=row[10] * 1000,
date=date,
length=int(row[10] * 1000),
bitrate=row[11],
comment=row[12],
musicbrainz_id=row[13],
Expand All @@ -361,14 +368,7 @@ def _find_albums(self, query):
result = self._query_beets_db(statement)
albums = []
for row in result:
try:
d = datetime.datetime(
row[4],
row[3],
row[2])
date = '{:%Y-%m-%d}'.format(d)
except:
date = None
date = self._build_date(row[4], row[3], row[2])
artist = Artist(name=row[5],
musicbrainz_id=row[9],
uri="beetslocal:artist:%s:" % row[9])
Expand All @@ -378,7 +378,7 @@ def _find_albums(self, query):
# num_tracks=row[6],
num_discs=row[6],
musicbrainz_id=row[7],
images=[row[8]],
# images=[row[8]],
uri="beetslocal:album:%s:" % row[0]))
return albums

Expand Down Expand Up @@ -477,27 +477,18 @@ def _convert_item(self, item):
if 'mtime' in item:
track_kwargs['last_modified'] = int(item['mtime'] * 1000)

track_kwargs['date'] = None
if self.backend.use_original_release_date:
if 'original_year' in item:
try:
d = datetime.datetime(
item['original_year'],
item['original_month'],
item['original_day'])
track_kwargs['date'] = '{:%Y-%m-%d}'.format(d)
except:
pass
track_kwargs['date'] = self._build_date(
item['original_year'],
item['original_month'],
item['original_day'])
else:
if 'year' in item:
try:
d = datetime.datetime(
item['year'],
item['month'],
item['day'])
track_kwargs['date'] = '{:%Y-%m-%d}'.format(d)
except:
pass
track_kwargs['date'] = self._build_date(
item['year'],
item['month'],
item['day'])

if 'mb_trackid' in item:
track_kwargs['musicbrainz_id'] = item['mb_trackid']
Expand Down Expand Up @@ -581,8 +572,8 @@ def _convert_album(self, album):
# if 'added' in item:
# album_kwargs['last_modified'] = album['added']

if 'artpath' in album:
album_kwargs['images'] = [album['artpath']]
# if 'artpath' in album:
# album_kwargs['images'] = [album['artpath']]

if 'albumartist' in album:
artist_kwargs['name'] = album['albumartist']
Expand Down

0 comments on commit a564601

Please sign in to comment.