Ejemplo n.º 1
0
def get_tracks(artist_name, track_name):
    try:
        print >>sys.stderr, 'EN searching for', artist_name, track_name, '\r'
        tracks = []
        artists = artist_api.search_artists(artist_name)
        for artist in artists:
            print >>sys.stderr, 'EN artist', artist.name, '\r'
            for audio in artist.audio(1000):
                if 'title' in audio and fuzzy_match(track_name, audio['title']):
                    print >>sys.stderr, 'EN audio', audio['title'], '\r'
                    if is_live(audio['url']):
                        track = {}
                        track['artist'] = audio['artist']
                        track['track'] = audio['title']
                        track['album'] = audio['release']
                        track['url'] = audio['url']
                        track['duration'] = audio['length']
                        # Is the best source 'echonest' or the blog
                        # where the track was found?
                        track['source'] = 'echo nest'

                        # BUG: need a better score
                        track['score'] = 0.99
                        tracks.append(track)
                        # if we found one we are done:
                        print >>sys.stderr, 'EN found track', track['url'] , '\r'
                        return tracks;
    except:
        print >>sys.stderr, 'EN had an error', '\r'
    print >>sys.stderr, 'EN found nothing', '\r'
    return tracks
Ejemplo n.º 2
0
def main(artist_name):	
    alist = artist.search_artists(artist_name)
    if (len(alist) > 0):
        print 'Artists similar to', alist[0].name
        for sim in alist[0].similar():
            print " ", sim.name
    else :
        print "Can't find ", artist_name
Ejemplo n.º 3
0
 def find_hotness(self, cmd, k=0):
     k = k+1
     try: 
         alist = artist.search_artists(cmd)
     except:
         self.connection.privmsg(self.channel, "No matching artist")
         return
     if len(alist) == 0 or k > 5:
         self.connection.privmsg(self.channel, "No matching artist")
         return
     return alist[0].hotttnesss()
Ejemplo n.º 4
0
def main(artist_name):	
    alist = artist.search_artists(artist_name)
    if (len(alist) > 0):
        a = alist[0]

        print "Name:", a.name
        print "id:", a.identifier
        print "Familiarity:", a.familiarity()
        print "Hotttnesss:", a.hotttnesss()

        print "Similars:"
        for sim in a.similar():
            print "   ", sim.name

        print "Audio:"
        for audio in a.audio():
            if 'url' in audio:
                print "   ", audio['url']

        print "Blogs:"
        for blog in a.blogs():
            if 'name' in blog:
                print "   ", blog['name']

        print "News:"
        for news in a.news():
            if 'name' in news:
                print "   ", news['name']

        print "Reviews:"
        for review in a.reviews():
            if 'name' in review:
                print "   ", review['name']

        print "URLs:"
        for (name, url) in a.urls.items():
            print "   ", name, url[0:30];

        print "Videos:"
        for v in a.video():
            if 'site' in v and 'title' in v:
                print "   ", v['site'],  v['title']
    else :
        print "Can't find ", artist_name
Ejemplo n.º 5
0
    for audio in audio_list:
        if is_live(audio['url']):
            return audio
    return None


def is_live(url):
    try:
        socket.setdefaulttimeout(5)
        f = urllib.urlopen(url)
        is_audio = f.info().gettype().find("audio") >= 0
        f.close()
        return is_audio
    except IOError:
        return False


if __name__ == '__main__':
    if len(sys.argv) >= 3:
        max = int(sys.argv[1])
        args = sys.argv[2:]
        name = ' '.join(args)
        alist = artist.search_artists(name)
        if (len(alist) > 0):
            wander(alist[0], max)
        else:
            print "Can't find ", name
    else:
        print usage
        sys.exit(-1)
def mine(sqlite_db,maxartists=10000,verbose=False,nsims=100):
    """
    Mine EchoNest for artist name
    Method is simple: starts from the Beatles, get similar artists,
    mine similar artists.
    nsims - number of similar artists to ask for at Echo Nest, between
    1 and 100
    """

    assert nsims > 0 and nsims <= 100,'wrong nsims (# similar): %d'%nsims

    # start time
    tstart = time.time()

    # connects to the DB, creates it if necessary
    connection = sqlite.connect(sqlite_db)
    # gets cursor
    cursor = connection.cursor()

    # count iterations before commit
    cnt_commit = 0
    iter_between_commits = 10

    # db empty? create table, add Beatles
    try:
        cursor.execute('SELECT * FROM artists WHERE name="The Beatles"')
    except sqlite3.OperationalError:
        cursor.execute('CREATE TABLE artists (id INTEGER PRIMARY KEY,name VARCHAR(50), checked INTEGER)')
        cursor.execute('INSERT INTO artists VALUES (null, "The Beatles",0)')

    try:
        while True:
            # check if too many artists
            query = 'SELECT COUNT(id) FROM artists'
            cursor.execute(query)
            nArtists = int(cursor.fetchone()[0])
            if nArtists > maxartists:
                print 'db has',nArtists,', we want',maxartists,', we stop.'
                break
            
            # get an artist not checked
            query = 'SELECT name FROM artists WHERE checked=0 ORDER BY RANDOM() LIMIT 1'
            cursor.execute(query)
            unchecked = cursor.fetchone()
            if len(unchecked) == 0:
                print "we stop, all artists checked"
                break
            unchecked_artist = unchecked[0]
            if verbose:
                print '#artists:',nArtists,', new query artist:',unchecked_artist

            # find similar artists
            try:
                aEN = artistEN.search_artists(unchecked_artist)[0]
                asim = aEN.similar(rows=nsims)
            except pyechonest.util.EchoNestAPIError:
                print 'EchoNestAPIError, wait a minute and continue'
                time.sleep(60)
                continue
            
            # add them to the database
            for a in asim:
                # artist name
                aname = a.name.replace('"','')
                # already in?
                query = 'SELECT name FROM artists WHERE name='
                query += '"' + aname + '"'
                cursor.execute(query)
                found = cursor.fetchmany(2)
                if len(found) == 0:
                    query = 'INSERT INTO artists VALUES (null, "'
                    query += aname + '",0)'
                    cursor.execute(query)

            # check in the query artist
            query = 'UPDATE artists SET checked=1 WHERE name='
            query += '"' + unchecked_artist + '"'
            cursor.execute(query)

            # commit
            cnt_commit += 1
            if cnt_commit % iter_between_commits == 0:
                if verbose:
                    print 'commiting...'
                connection.commit()

    # easy case, user terminates the program
    except KeyboardInterrupt:
        print "ERROR:", sys.exc_info()[0]        
        connection.close()
        return
    # try to get debug information
    except:
        print "ERROR:", sys.exc_info()[0]
        print 'last query=',query
        connection.close()
        return
    

    # finish correctly
    connection.commit()
    connection.close()
    print 'EchoNest artist name mining finished correctly'
    print 'program ran for',time.time()-tstart,'seconds'
Ejemplo n.º 7
0
def mine(sqlite_db, maxartists=10000, verbose=False, nsims=100):
    """
    Mine EchoNest for artist name
    Method is simple: starts from the Beatles, get similar artists,
    mine similar artists.
    nsims - number of similar artists to ask for at Echo Nest, between
    1 and 100
    """

    assert nsims > 0 and nsims <= 100, 'wrong nsims (# similar): %d' % nsims

    # start time
    tstart = time.time()

    # connects to the DB, creates it if necessary
    connection = sqlite.connect(sqlite_db)
    # gets cursor
    cursor = connection.cursor()

    # count iterations before commit
    cnt_commit = 0
    iter_between_commits = 10

    # db empty? create table, add Beatles
    try:
        cursor.execute('SELECT * FROM artists WHERE name="The Beatles"')
    except sqlite3.OperationalError:
        cursor.execute(
            'CREATE TABLE artists (id INTEGER PRIMARY KEY,name VARCHAR(50), checked INTEGER)'
        )
        cursor.execute('INSERT INTO artists VALUES (null, "The Beatles",0)')

    try:
        while True:
            # check if too many artists
            query = 'SELECT COUNT(id) FROM artists'
            cursor.execute(query)
            nArtists = int(cursor.fetchone()[0])
            if nArtists > maxartists:
                print 'db has', nArtists, ', we want', maxartists, ', we stop.'
                break

            # get an artist not checked
            query = 'SELECT name FROM artists WHERE checked=0 ORDER BY RANDOM() LIMIT 1'
            cursor.execute(query)
            unchecked = cursor.fetchone()
            if len(unchecked) == 0:
                print "we stop, all artists checked"
                break
            unchecked_artist = unchecked[0]
            if verbose:
                print '#artists:', nArtists, ', new query artist:', unchecked_artist

            # find similar artists
            try:
                aEN = artistEN.search_artists(unchecked_artist)[0]
                asim = aEN.similar(rows=nsims)
            except pyechonest.util.EchoNestAPIError:
                print 'EchoNestAPIError, wait a minute and continue'
                time.sleep(60)
                continue

            # add them to the database
            for a in asim:
                # artist name
                aname = a.name.replace('"', '')
                # already in?
                query = 'SELECT name FROM artists WHERE name='
                query += '"' + aname + '"'
                cursor.execute(query)
                found = cursor.fetchmany(2)
                if len(found) == 0:
                    query = 'INSERT INTO artists VALUES (null, "'
                    query += aname + '",0)'
                    cursor.execute(query)

            # check in the query artist
            query = 'UPDATE artists SET checked=1 WHERE name='
            query += '"' + unchecked_artist + '"'
            cursor.execute(query)

            # commit
            cnt_commit += 1
            if cnt_commit % iter_between_commits == 0:
                if verbose:
                    print 'commiting...'
                connection.commit()

    # easy case, user terminates the program
    except KeyboardInterrupt:
        print "ERROR:", sys.exc_info()[0]
        connection.close()
        return
    # try to get debug information
    except:
        print "ERROR:", sys.exc_info()[0]
        print 'last query=', query
        connection.close()
        return

    # finish correctly
    connection.commit()
    connection.close()
    print 'EchoNest artist name mining finished correctly'
    print 'program ran for', time.time() - tstart, 'seconds'
Ejemplo n.º 8
0
    for audio in audio_list:
        if is_live(audio["url"]):
            return audio
    return None


def is_live(url):
    try:
        socket.setdefaulttimeout(5)
        f = urllib.urlopen(url)
        is_audio = f.info().gettype().find("audio") >= 0
        f.close()
        return is_audio
    except IOError:
        return False


if __name__ == "__main__":
    if len(sys.argv) >= 3:
        max = int(sys.argv[1])
        args = sys.argv[2:]
        name = " ".join(args)
        alist = artist.search_artists(name)
        if len(alist) > 0:
            wander(alist[0], max)
        else:
            print "Can't find ", name
    else:
        print usage
        sys.exit(-1)