def addArtisttoDB(artistid, extrasonly=False): # Can't add various artists - throws an error from MB if artistid == various_artists_mbid: logger.warn('Cannot import Various Artists.') return myDB = db.DBConnection() artist = mb.getArtist(artistid, extrasonly) if not artist: return if artist['artist_name'].startswith('The '): sortname = artist['artist_name'][4:] else: sortname = artist['artist_name'] logger.info(u"Now adding/updating: " + artist['artist_name']) controlValueDict = {"ArtistID": artistid} newValueDict = {"ArtistName": artist['artist_name'], "ArtistSortName": sortname, "DateAdded": helpers.today(), "Status": "Loading"} if headphones.INCLUDE_EXTRAS: newValueDict['IncludeExtras'] = 1 myDB.upsert("artists", newValueDict, controlValueDict) for rg in artist['releasegroups']: rgid = rg['id'] # check if the album already exists rg_exists = myDB.select("SELECT * from albums WHERE AlbumID=?", [rg['id']]) try: release_dict = mb.getReleaseGroup(rgid) except Exception, e: logger.info('Unable to get release information for %s - there may not be any official releases in this release group' % rg['title']) continue if not release_dict: continue logger.info(u"Now adding/updating album: " + rg['title']) controlValueDict = {"AlbumID": rg['id']} if len(rg_exists): newValueDict = {"AlbumASIN": release_dict['asin'], "ReleaseDate": release_dict['releasedate'], } else: newValueDict = {"ArtistID": artistid, "ArtistName": artist['artist_name'], "AlbumTitle": rg['title'], "AlbumASIN": release_dict['asin'], "ReleaseDate": release_dict['releasedate'], "DateAdded": helpers.today(), "Type": rg['type'] } if release_dict['releasedate'] > helpers.today(): newValueDict['Status'] = "Wanted" else: newValueDict['Status'] = "Skipped" myDB.upsert("albums", newValueDict, controlValueDict) try: lastfm.getAlbumDescription(rg['id'], artist['artist_name'], rg['title']) except Exception, e: logger.error('Attempt to retrieve album description from Last.fm failed: %s' % e)
def addArtisttoDB(artistid, extrasonly=False): # Can't add various artists - throws an error from MB if artistid == various_artists_mbid: logger.warn('Cannot import Various Artists.') return myDB = db.DBConnection() # We need the current minimal info in the database instantly # so we don't throw a 500 error when we redirect to the artistPage controlValueDict = {"ArtistID": artistid} # Don't replace a known artist name with an "Artist ID" placeholder dbartist = myDB.action('SELECT * FROM artists WHERE ArtistID=?', [artistid]).fetchone() if dbartist is None: newValueDict = {"ArtistName": "Artist ID: %s" % (artistid), "Status": "Loading"} else: newValueDict = {"Status": "Loading"} myDB.upsert("artists", newValueDict, controlValueDict) artist = mb.getArtist(artistid, extrasonly) if not artist: logger.warn("Error fetching artist info. ID: " + artistid) if dbartist is None: newValueDict = {"ArtistName": "Fetch failed, try refreshing. (%s)" % (artistid), "Status": "Active"} else: newValueDict = {"Status": "Active"} myDB.upsert("artists", newValueDict, controlValueDict) return if artist['artist_name'].startswith('The '): sortname = artist['artist_name'][4:] else: sortname = artist['artist_name'] logger.info(u"Now adding/updating: " + artist['artist_name']) controlValueDict = {"ArtistID": artistid} newValueDict = {"ArtistName": artist['artist_name'], "ArtistSortName": sortname, "DateAdded": helpers.today(), "Status": "Loading"} if headphones.INCLUDE_EXTRAS: newValueDict['IncludeExtras'] = 1 myDB.upsert("artists", newValueDict, controlValueDict) for rg in artist['releasegroups']: rgid = rg['id'] # check if the album already exists rg_exists = myDB.select("SELECT * from albums WHERE AlbumID=?", [rg['id']]) try: release_dict = mb.getReleaseGroup(rgid) except Exception, e: logger.info('Unable to get release information for %s - there may not be any official releases in this release group' % rg['title']) continue if not release_dict: continue logger.info(u"Now adding/updating album: " + rg['title']) controlValueDict = {"AlbumID": rg['id']} if len(rg_exists): newValueDict = {"AlbumASIN": release_dict['asin'], "ReleaseDate": release_dict['releasedate'], } else: newValueDict = {"ArtistID": artistid, "ArtistName": artist['artist_name'], "AlbumTitle": rg['title'], "AlbumASIN": release_dict['asin'], "ReleaseDate": release_dict['releasedate'], "DateAdded": helpers.today(), "Type": rg['type'] } if release_dict['releasedate'] > helpers.today(): newValueDict['Status'] = "Wanted" else: newValueDict['Status'] = "Skipped" myDB.upsert("albums", newValueDict, controlValueDict) try: lastfm.getAlbumDescription(rg['id'], artist['artist_name'], rg['title']) except Exception, e: logger.error('Attempt to retrieve album description from Last.fm failed: %s' % e)
def addArtisttoDB(artistid, extrasonly=False): # Can't add various artists - throws an error from MB if artistid == various_artists_mbid: logger.warn('Cannot import Various Artists.') return myDB = db.DBConnection() # We need the current minimal info in the database instantly # so we don't throw a 500 error when we redirect to the artistPage controlValueDict = {"ArtistID": artistid} # Don't replace a known artist name with an "Artist ID" placeholder dbartist = myDB.action('SELECT * FROM artists WHERE ArtistID=?', [artistid]).fetchone() if dbartist is None: newValueDict = { "ArtistName": "Artist ID: %s" % (artistid), "Status": "Loading" } else: newValueDict = {"Status": "Loading"} myDB.upsert("artists", newValueDict, controlValueDict) artist = mb.getArtist(artistid, extrasonly) if not artist: logger.warn("Error fetching artist info. ID: " + artistid) if dbartist is None: newValueDict = { "ArtistName": "Fetch failed, try refreshing. (%s)" % (artistid), "Status": "Active" } else: newValueDict = {"Status": "Active"} myDB.upsert("artists", newValueDict, controlValueDict) return if artist['artist_name'].startswith('The '): sortname = artist['artist_name'][4:] else: sortname = artist['artist_name'] logger.info(u"Now adding/updating: " + artist['artist_name']) controlValueDict = {"ArtistID": artistid} newValueDict = { "ArtistName": artist['artist_name'], "ArtistSortName": sortname, "DateAdded": helpers.today(), "Status": "Loading" } if headphones.INCLUDE_EXTRAS: newValueDict['IncludeExtras'] = 1 myDB.upsert("artists", newValueDict, controlValueDict) for rg in artist['releasegroups']: rgid = rg['id'] # check if the album already exists rg_exists = myDB.select("SELECT * from albums WHERE AlbumID=?", [rg['id']]) try: release_dict = mb.getReleaseGroup(rgid) except Exception, e: logger.info( 'Unable to get release information for %s - there may not be any official releases in this release group' % rg['title']) continue if not release_dict: continue logger.info(u"Now adding/updating album: " + rg['title']) controlValueDict = {"AlbumID": rg['id']} if len(rg_exists): newValueDict = { "AlbumASIN": release_dict['asin'], "ReleaseDate": release_dict['releasedate'], } else: newValueDict = { "ArtistID": artistid, "ArtistName": artist['artist_name'], "AlbumTitle": rg['title'], "AlbumASIN": release_dict['asin'], "ReleaseDate": release_dict['releasedate'], "DateAdded": helpers.today(), "Type": rg['type'] } if headphones.AUTOWANT_ALL: newValueDict['Status'] = "Wanted" elif release_dict['releasedate'] > helpers.today( ) and headphones.AUTOWANT_UPCOMING: newValueDict['Status'] = "Wanted" else: newValueDict['Status'] = "Skipped" myDB.upsert("albums", newValueDict, controlValueDict) try: lastfm.getAlbumDescription(rg['id'], artist['artist_name'], rg['title']) except Exception, e: logger.error( 'Attempt to retrieve album description from Last.fm failed: %s' % e)
def addArtisttoDB(artistid, extrasonly=False): # Can't add various artists - throws an error from MB if artistid == various_artists_mbid: logger.warn("Cannot import Various Artists.") return myDB = db.DBConnection() artist = mb.getArtist(artistid, extrasonly) if not artist: return if artist["artist_name"].startswith("The "): sortname = artist["artist_name"][4:] else: sortname = artist["artist_name"] logger.info(u"Now adding/updating: " + artist["artist_name"]) controlValueDict = {"ArtistID": artistid} newValueDict = { "ArtistName": artist["artist_name"], "ArtistSortName": sortname, "DateAdded": helpers.today(), "Status": "Loading", } if headphones.INCLUDE_EXTRAS: newValueDict["IncludeExtras"] = 1 myDB.upsert("artists", newValueDict, controlValueDict) for rg in artist["releasegroups"]: rgid = rg["id"] # check if the album already exists rg_exists = myDB.select("SELECT * from albums WHERE AlbumID=?", [rg["id"]]) try: release_dict = mb.getReleaseGroup(rgid) except Exception, e: logger.info( "Unable to get release information for %s - there may not be any official releases in this release group" % rg["title"] ) continue if not release_dict: continue logger.info(u"Now adding/updating album: " + rg["title"]) controlValueDict = {"AlbumID": rg["id"]} if len(rg_exists): newValueDict = {"AlbumASIN": release_dict["asin"], "ReleaseDate": release_dict["releasedate"]} else: newValueDict = { "ArtistID": artistid, "ArtistName": artist["artist_name"], "AlbumTitle": rg["title"], "AlbumASIN": release_dict["asin"], "ReleaseDate": release_dict["releasedate"], "DateAdded": helpers.today(), "Type": rg["type"], } if release_dict["releasedate"] > helpers.today(): newValueDict["Status"] = "Wanted" else: newValueDict["Status"] = "Skipped" if rg["type"] == "Album" and headphones.AUTOWANT_ALBUM: newValueDict["Status"] = "Wanted" if rg["type"] == "Compilation" and headphones.AUTOWANT_COMPILATION: newValueDict["Status"] = "Wanted" if rg["type"] == "EP" and headphones.AUTOWANT_EP: newValueDict["Status"] = "Wanted" if rg["type"] == "Remix" and headphones.AUTOWANT_REMIX: newValueDict["Status"] = "Wanted" if rg["type"] == "Single" and headphones.AUTOWANT_SINGLE: newValueDict["Status"] = "Wanted" if rg["type"] == "Live" and headphones.AUTOWANT_LIVE: newValueDict["Status"] = "Wanted" if rg["type"] == "Soundtrack" and headphones.AUTOWANT_SOUNDTRACK: newValueDict["Status"] = "Wanted" myDB.upsert("albums", newValueDict, controlValueDict) try: lastfm.getAlbumDescription(rg["id"], artist["artist_name"], rg["title"]) except Exception, e: logger.error("Attempt to retrieve album description from Last.fm failed: %s" % e)
def addArtisttoDB(artistid, extrasonly=False): # Can't add various artists - throws an error from MB if artistid == various_artists_mbid: logger.warn('Cannot import Various Artists.') return myDB = db.DBConnection() artist = mb.getArtist(artistid, extrasonly) if not artist: return if artist['artist_name'].startswith('The '): sortname = artist['artist_name'][4:] else: sortname = artist['artist_name'] logger.info(u"Now adding/updating: " + artist['artist_name']) controlValueDict = {"ArtistID": artistid} newValueDict = { "ArtistName": artist['artist_name'], "ArtistSortName": sortname, "DateAdded": helpers.today(), "Status": "Loading" } if headphones.INCLUDE_EXTRAS: newValueDict['IncludeExtras'] = 1 myDB.upsert("artists", newValueDict, controlValueDict) for rg in artist['releasegroups']: rgid = rg['id'] # check if the album already exists rg_exists = myDB.select("SELECT * from albums WHERE AlbumID=?", [rg['id']]) try: release_dict = mb.getReleaseGroup(rgid) except Exception, e: logger.info( 'Unable to get release information for %s - there may not be any official releases in this release group' % rg['title']) continue if not release_dict: continue logger.info(u"Now adding/updating album: " + rg['title']) controlValueDict = {"AlbumID": rg['id']} if len(rg_exists): newValueDict = { "AlbumASIN": release_dict['asin'], "ReleaseDate": release_dict['releasedate'], } else: newValueDict = { "ArtistID": artistid, "ArtistName": artist['artist_name'], "AlbumTitle": rg['title'], "AlbumASIN": release_dict['asin'], "ReleaseDate": release_dict['releasedate'], "DateAdded": helpers.today(), "Type": rg['type'] } if release_dict['releasedate'] > helpers.today(): newValueDict['Status'] = "Wanted" else: newValueDict['Status'] = "Skipped" myDB.upsert("albums", newValueDict, controlValueDict) try: lastfm.getAlbumDescription(rg['id'], artist['artist_name'], rg['title']) except Exception, e: logger.error( 'Attempt to retrieve album description from Last.fm failed: %s' % e)