def artistlist_to_mbids(artistlist, forced=False): for artist in artistlist: if not artist and not (artist == ' '): continue results = mb.findArtist(artist, limit=1) if not results: logger.info('No results found for: %s' % artist) continue try: artistid = results[0]['id'] except IndexError: logger.info('MusicBrainz query turned up no matches for: %s' % artist) continue # Check if it's blacklisted/various artists (only check if it's not forced, e.g. through library scan auto-add.) # Forced example = Adding an artist from Manage New Artists myDB = db.DBConnection() if not forced: bl_artist = myDB.action('SELECT * FROM blacklist WHERE ArtistID=?', [artistid]).fetchone() if bl_artist or artistid in blacklisted_special_artists: logger.info( "Artist ID for '%s' is either blacklisted or Various Artists. To add artist, you must do it manually (Artist ID: %s)" % (artist, artistid)) continue # Add to database if it doesn't exist if not is_exists(artistid): addArtisttoDB(artistid) # Just update the tracks if it does else: havetracks = len( myDB.select('SELECT TrackTitle from tracks WHERE ArtistID=?', [ artistid ])) + len( myDB.select( 'SELECT TrackTitle from have WHERE ArtistName like ?', [artist])) myDB.action('UPDATE artists SET HaveTracks=? WHERE ArtistID=?', [havetracks, artistid]) # Delete it from the New Artists if the request came from there if forced: myDB.action('DELETE from newartists WHERE ArtistName=?', [artist]) # Update the similar artist tag cloud: logger.info('Updating artist information from Last.fm') try: lastfm.getSimilar() except Exception, e: logger.warn('Failed to update arist information from Last.fm: %s' % e)
def artistlist_to_mbids(artistlist, forced=False): for artist in artistlist: if not artist and not (artist == ' '): continue # If adding artists through Manage New Artists, they're coming through as non-unicode (utf-8?) # and screwing everything up if not isinstance(artist, unicode): try: artist = artist.decode('utf-8', 'replace') except: logger.warn("Unable to convert artist to unicode so cannot do a database lookup") continue results = mb.findArtist(artist, limit=1) if not results: logger.info('No results found for: %s' % artist) continue try: artistid = results[0]['id'] except IndexError: logger.info('MusicBrainz query turned up no matches for: %s' % artist) continue # Check if it's blacklisted/various artists (only check if it's not forced, e.g. through library scan auto-add.) # Forced example = Adding an artist from Manage New Artists myDB = db.DBConnection() if not forced: bl_artist = myDB.action('SELECT * FROM blacklist WHERE ArtistID=?', [artistid]).fetchone() if bl_artist or artistid in blacklisted_special_artists: logger.info("Artist ID for '%s' is either blacklisted or Various Artists. To add artist, you must do it manually (Artist ID: %s)" % (artist, artistid)) continue # Add to database if it doesn't exist if not is_exists(artistid): addArtisttoDB(artistid) # Just update the tracks if it does else: havetracks = len(myDB.select('SELECT TrackTitle from tracks WHERE ArtistID=?', [artistid])) + len(myDB.select('SELECT TrackTitle from have WHERE ArtistName like ?', [artist])) myDB.action('UPDATE artists SET HaveTracks=? WHERE ArtistID=?', [havetracks, artistid]) # Delete it from the New Artists if the request came from there if forced: myDB.action('DELETE from newartists WHERE ArtistName=?', [artist]) # Update the similar artist tag cloud: logger.info('Updating artist information from Last.fm') try: lastfm.getSimilar() except Exception as e: logger.warn('Failed to update arist information from Last.fm: %s' % e)
def artistlist_to_mbids(artistlist, forced=False): for artist in artistlist: if forced: artist = unicode(artist, 'utf-8') results = mb.findArtist(artist, limit=1) if not results: logger.info('No results found for: %s' % artist) continue try: artistid = results[0]['id'] except IndexError: logger.info('MusicBrainz query turned up no matches for: %s' % artist) continue # Add to database if it doesn't exist if artistid != various_artists_mbid and not if_exists(artistid): addArtisttoDB(artistid) # Just update the tracks if it does else: myDB = db.DBConnection() havetracks = len(myDB.select('SELECT TrackTitle from tracks WHERE ArtistID=?', [artistid])) + len(myDB.select('SELECT TrackTitle from have WHERE ArtistName like ?', [artist])) myDB.action('UPDATE artists SET HaveTracks=? WHERE ArtistID=?', [havetracks, artistid]) # Update the similar artist tag cloud: logger.info('Updating artist information from Last.fm') try: lastfm.getSimilar() except Exception, e: logger.warn('Failed to update arist information from Last.fm: %s' % e)
def search(self, name, type): if len(name) == 0: raise cherrypy.HTTPRedirect("home") if type == 'artist': searchresults = mb.findArtist(name, limit=100) else: searchresults = mb.findRelease(name, limit=100) return serve_template(templatename="searchresults.html", title='Search Results for: "' + name + '"', searchresults=searchresults, type=type)
def artistlist_to_mbids(artistlist): for artist in artistlist: results = mb.findArtist(artist, limit=1) artistid = results[0]['id'] if artistid != various_artists_mbid: addArtisttoDB(artistid)
def _findArtist(self, **kwargs): if 'name' not in kwargs: self.data = 'Missing parameter: name' return if 'limit' in kwargs: limit = kwargs['limit'] else: limit = 50 self.data = mb.findArtist(kwargs['name'], limit)
def _findArtist(self, **kwargs): if "name" not in kwargs: self.data = "Missing parameter: name" return if "limit" in kwargs: limit = kwargs["limit"] else: limit = 50 self.data = mb.findArtist(kwargs["name"], limit)
def artistlist_to_mbids(artistlist, forced=False): for artist in artistlist: if not artist and not (artist == " "): continue results = mb.findArtist(artist, limit=1) if not results: logger.info("No results found for: %s" % artist) continue try: artistid = results[0]["id"] except IndexError: logger.info("MusicBrainz query turned up no matches for: %s" % artist) continue # Check if it's blacklisted/various artists (only check if it's not forced, e.g. through library scan auto-add.) # Forced example = Adding an artist from Manage New Artists myDB = db.DBConnection() if not forced: bl_artist = myDB.action("SELECT * FROM blacklist WHERE ArtistID=?", [artistid]).fetchone() if bl_artist or artistid in blacklisted_special_artists: logger.info( "Artist ID for '%s' is either blacklisted or Various Artists. To add artist, you must do it manually (Artist ID: %s)" % (artist, artistid) ) continue # Add to database if it doesn't exist if not is_exists(artistid): addArtisttoDB(artistid) # Just update the tracks if it does else: havetracks = len(myDB.select("SELECT TrackTitle from tracks WHERE ArtistID=?", [artistid])) + len( myDB.select("SELECT TrackTitle from have WHERE ArtistName like ?", [artist]) ) myDB.action("UPDATE artists SET HaveTracks=? WHERE ArtistID=?", [havetracks, artistid]) # Delete it from the New Artists if the request came from there if forced: myDB.action("DELETE from newartists WHERE ArtistName=?", [artist]) # Update the similar artist tag cloud: logger.info("Updating artist information from Last.fm") try: lastfm.getSimilar() except Exception, e: logger.warn("Failed to update arist information from Last.fm: %s" % e)
def artistlist_to_mbids(artistlist, forced=False): for artist in artistlist: if forced: artist = unicode(artist, 'utf-8') results = mb.findArtist(artist, limit=1) if not results: logger.info('No results found for: %s' % artist) continue try: artistid = results[0]['id'] except IndexError: logger.info('MusicBrainz query turned up no matches for: %s' % artist) continue # Add to database if it doesn't exist if artistid != various_artists_mbid and not is_exists(artistid): addArtisttoDB(artistid) # Just update the tracks if it does else: myDB = db.DBConnection() havetracks = len( myDB.select('SELECT TrackTitle from tracks WHERE ArtistID=?', [ artistid ])) + len( myDB.select( 'SELECT TrackTitle from have WHERE ArtistName like ?', [artist])) myDB.action('UPDATE artists SET HaveTracks=? WHERE ArtistID=?', [havetracks, artistid]) # Update the similar artist tag cloud: logger.info('Updating artist information from Last.fm') try: lastfm.getSimilar() except Exception, e: logger.warn('Failed to update arist information from Last.fm: %s' % e)
def artistlist_to_mbids(artistlist, forced=False): for artist in artistlist: if forced: artist = unicode(artist, 'utf-8') results = mb.findArtist(artist, limit=1) if not results: logger.info('No results found for: %s' % artist) continue try: artistid = results[0]['id'] except IndexError: logger.info('MusicBrainz query turned up no matches for: %s' % artist) continue # Check if it's blacklisted/various artists myDB = db.DBConnection() bl_artist = myDB.action('SELECT * FROM blacklist WHERE ArtistID=?', [artistid]).fetchone() if bl_artist or artistid == various_artists_mbid: logger.info("Artist ID for '%s' is either blacklisted or Various Artists. To add artist, you must do it manually (Artist ID: %s)" % (artist, artistid)) continue # Add to database if it doesn't exist if not is_exists(artistid): addArtisttoDB(artistid) # Just update the tracks if it does else: havetracks = len(myDB.select('SELECT TrackTitle from tracks WHERE ArtistID=?', [artistid])) + len(myDB.select('SELECT TrackTitle from have WHERE ArtistName like ?', [artist])) myDB.action('UPDATE artists SET HaveTracks=? WHERE ArtistID=?', [havetracks, artistid]) # Update the similar artist tag cloud: logger.info('Updating artist information from Last.fm') try: lastfm.getSimilar() except Exception, e: logger.warn('Failed to update arist information from Last.fm: %s' % e)
def findArtist(self, name): page = [templates._header] page.append(templates._logobar) page.append(templates._nav) if len(name) == 0 or name == 'Add an artist': raise cherrypy.HTTPRedirect("home") else: artistResults = mb.findArtist(name, limit=10) if not artistResults: logger.info(u"No results found for " + name) page.append('''<div class="table"><p class="center">No results! <a class="blue" href="home">Go back</a></p></div>''') return page elif len(artistResults) > 1: page.append('''<div class="table"><p class="center">Search returned multiple artists. Click the artist you want to add:</p>''') for result in artistResults: page.append('''<p class="mediumtext"><a href="addArtist?artistid=%s">%s</a> (<a class="externalred" href="artistInfo?artistid=%s">more info</a>)</p>''' % (result['id'], result['uniquename'], result['id'])) page.append('''</div>''') return page else: for result in artistResults: logger.info(u"Found one artist matching your search term: " + result['name'] +" ("+ result['id']+")") raise cherrypy.HTTPRedirect("addArtist?artistid=%s" % result['id'])
def artistlist_to_mbids(artistlist): for artist in artistlist: results = mb.findArtist(artist['ArtistName'], limit=1) if not results: continue try: artistid = results[0]['id'] except IndexError: logger.info('MusicBrainz query turned up no matches for: %s' % artist) continue # Add to database if it doesn't exist if artistid != various_artists_mbid and not is_exists(artistid): addArtisttoDB(artistid) # Update track count regardless of whether it already exists if artistid != various_artists_mbid: myDB = db.DBConnection() havetracks = len(myDB.select('SELECT TrackTitle from have WHERE ArtistName like ?', [artist['ArtistName']])) controlValueDict = {"ArtistID": artistid} newValueDict = {"HaveTracks": havetracks} myDB.upsert("artists", newValueDict, controlValueDict) # Update the similar artist tag cloud: logger.info('Updating artist information from Last.fm') try: lastfm.getSimilar() except Exception, e: logger.warn('Failed to update arist information from Last.fm: %s' % e)
def artistlist_to_mbids(artistlist, forced=False): for artist in artistlist: if not artist and artist != ' ': continue # If adding artists through Manage New Artists, they're coming through as non-unicode (utf-8?) # and screwing everything up if not isinstance(artist, unicode): try: artist = artist.decode('utf-8', 'replace') except Exception: logger.warn( "Unable to convert artist to unicode so cannot do a database lookup" ) continue results = mb.findArtist(artist, limit=1) if not results: logger.info('No results found for: %s' % artist) continue try: artistid = results[0]['id'] except IndexError: logger.info('MusicBrainz query turned up no matches for: %s' % artist) continue # Check if it's blacklisted/various artists (only check if it's not forced, e.g. through library scan auto-add.) # Forced example = Adding an artist from Manage New Artists myDB = db.DBConnection() if not forced: bl_artist = myDB.action('SELECT * FROM blacklist WHERE ArtistID=?', [artistid]).fetchone() if bl_artist or artistid in blacklisted_special_artists: logger.info( "Artist ID for '%s' is either blacklisted or Various Artists. To add artist, you must " "do it manually (Artist ID: %s)" % (artist, artistid)) continue # Add to database if it doesn't exist if not is_exists(artistid): addArtisttoDB(artistid) # Just update the tracks if it does # not sure this is correct and we're updating during scanning in librarysync # else: # havetracks = len( # myDB.select('SELECT TrackTitle from tracks WHERE ArtistID=?', [artistid])) + len( # myDB.select('SELECT TrackTitle from have WHERE ArtistName like ?', [artist])) # myDB.action('UPDATE artists SET HaveTracks=? WHERE ArtistID=?', [havetracks, artistid]) # Delete it from the New Artists if the request came from there if forced: myDB.action('DELETE from newartists WHERE ArtistName=?', [artist]) # Update the similar artist tag cloud: logger.info('Updating artist information from Last.fm') try: lastfm.getSimilar() except Exception as e: logger.warn('Failed to update artist information from Last.fm: %s' % e)