Ejemplo n.º 1
0
    def seed_catalog(self):
        cur = g.db.execute('select seed_catalog from room where id = ?',
                           (self._id, ))
        result = cur.fetchone()[0]
        if result is not None:
            try:
                return catalog.Catalog(result)
            except EchoNestAPIError:
                pass

        cat = catalog.Catalog(str(self.id()), 'general')
        g.db.execute('update room set seed_catalog = ? where id = ?',
                     (cat.id, self._id))
        g.db.commit()
        return cat
Ejemplo n.º 2
0
def dump_catalog(catalog_name):
    """Songs can be: Unknown, Identified, Found"""

    catalog = echo_nest_catalog.Catalog(catalog_name, type='song')

    found_rdio_tracks = []
    items = catalog.get_item_dicts(buckets=[config.ECHO_NEST_BUCKET, 'tracks'])
    for item in items:
        if 'artist_name' in item:
            print item['artist_name'], '-', item['song_name']

            rdio_track_keys = [
                track['foreign_id'].split(':')[2] for track in item['tracks']
            ]
            if len(item['tracks']):
                print '\t', 'Found'
                print '\t', ', '.join(rdio_track_keys)
                found_rdio_tracks.append(rdio_track_keys[0])
            else:
                print '\t', 'Identified'
        else:
            print item['request']['artist_name'], '-', item['request'][
                'song_name']
            print '\t', 'Unkonwn'
        print

    return found_rdio_tracks
Ejemplo n.º 3
0
def get_user_dictionary(user_id, save_to_file='yes'):
    ''' Retrieves single user dictionary that contains the songs they listened to'''
    cat = catalog.Catalog(user_id)
    c = cat.get_item_dicts()
    if save_to_file == 'yes':
        filename = str(user_id) + '.dict'
        try:
            with open(os.path.join('../DATA/DOWNLOADS/' + filename), 'w') as f:
                f.write(str(c))
        except Exception as e:
            print('Error {}\n    in file {}'.format(e, file))
    return c
Ejemplo n.º 4
0
def check_catalog_status(catalog_name, catalog_ticket):
    """Polls catalog ticket and blocks until it's finished."""
    logger = logging.getLogger('catalog-check')

    catalog = echo_nest_catalog.Catalog(catalog_name, type='song')

    completed = False
    while not completed:
        time.sleep(config.ECHO_NEST_SLEEP)
        catalog_status = catalog.status(catalog_ticket)
        completed = catalog_status['ticket_status'] == 'complete'
        logger.info('Catalog %s, ticket %s, status %s', catalog_name,
                    catalog_ticket, catalog_status['ticket_status'])
Ejemplo n.º 5
0
def update_catalog(catalog_name, tracks):
    """Adds the ``tracks`` to the Echo Nest catalog named ``catalog_name``."""

    logger = logging.getLogger('catalog-updater')

    catalog = echo_nest_catalog.Catalog(catalog_name, type='song')

    items = []
    for artist, album, title in tracks:
        items.append({
            'action': 'update',
            'item': {
                'item_id': '%s%s' % (title, artist),  # TODO: Better hash
                'song_name': title,
                'artist_name': artist,
            }
        })

    catalog_ticket = catalog.update(items)
    logger.info('Updated catalog named "%s" and got ticket "%s"', catalog_name,
                catalog_ticket)

    return catalog_ticket
Ejemplo n.º 6
0
# Uncomment to set the API key explicitly. Otherwise Pyechonest will
# look in the ECHO_NEST_API_KEY environment variable for the key.
#from pyechonest import config
#config.ECHO_NEST_API_KEY='YOUR API KEY'

from pyechonest import catalog

c = catalog.Catalog('example_songs', type='song')

for item in c.read_items(buckets=['audio_summary', 'artist_hotttnesss']):
    print '"%s"' % (item.title, )
    print '    artist_hotttness: %s' % (item.artist_hotttnesss)
    print '    tempo: %s' % (item.audio_summary['tempo'])
    print '    energy: %s' % (item.audio_summary['energy'])
Ejemplo n.º 7
0
def user_LH(query):
    return catalog.Catalog(query).get_item_dicts()