From fb4a7b795bd6cf6737bc99fa5e337f2f5bcb168e Mon Sep 17 00:00:00 2001 From: Carey Li Date: Thu, 23 Jun 2016 04:30:42 +1000 Subject: [PATCH] Add addQueue API endpoint NoneType check --- headphones/api.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/headphones/api.py b/headphones/api.py index a8b97c02b..4cce5c431 100644 --- a/headphones/api.py +++ b/headphones/api.py @@ -307,13 +307,24 @@ def _queueAlbum(self, **kwargs): lossless = False myDB = db.DBConnection() - controlValueDict = {'AlbumID': self.id} - if lossless: - newValueDict = {'Status': 'Wanted Lossless'} + + # Validate that albums are already in db + album = myDB.action('SELECT * from albums WHERE AlbumID=?', [self.id]).fetchone() + logger.info('Typeof album %s is %s' % ( + self.id, type(album).__name__)) + + if album is None: + logger.info('Album %s is of type none, adding release' % ( + self.id)) + importer.addReleaseById(self.id) else: - newValueDict = {'Status': 'Wanted'} - myDB.upsert("albums", newValueDict, controlValueDict) - searcher.searchforalbum(self.id, new) + controlValueDict = {'AlbumID': self.id} + if lossless: + newValueDict = {'Status': 'Wanted Lossless'} + else: + newValueDict = {'Status': 'Wanted'} + myDB.upsert("albums", newValueDict, controlValueDict) + searcher.searchforalbum(self.id, new) def _unqueueAlbum(self, **kwargs):