def do_echonest_info(self, line):
     '''
     Display info about the echonest taste profile.
     Usage: echonest_info
     '''
     logger.debug('call function do_echonest_info')
     profile_id = get_profile_id(self.api_key)
     en_info = en_api.echonest_info(self.api_key, profile_id)
     #TODO: create disp function
     print
     print en_info
     print
Example #2
0
 def do_echonest_info(self, line):
     '''
     Display info about the echonest taste profile.
     Usage: echonest_info
     '''
     logger.debug('call function do_echonest_info')
     profile_id = get_profile_id(self.api_key)
     en_info = en_api.echonest_info(self.api_key, profile_id)
     #TODO: create disp function
     print
     print en_info
     print
Example #3
0
def echonest_sync(api_key, profile_id, songs):
    '''Sync songs with echonest tasteprofile'''
    logger.debug('call echonest_sync')
    #TODO: cache the profile ID
    #TODO: create routines for echonest API calls + HTTP Kodi calls
    en_info = en_api.echonest_info(api_key, profile_id)
    if en_info['total'] == 0:
        logger.info("no songs in tasteprofile, full sync")
        songs_id_delta = songs.keys()
    else:
        logger.info("limit sync to delta")
        songs_id_delta = get_profile_delta(songs)
    nb_songs_delta = len(songs_id_delta)
    print
    print "Sync songs to the tasteprofile (this can be very very long)"
    print
    logger.info('delta size: %i', nb_songs_delta)
    logger.debug('delta songs %s', songs_id_delta)
    widgets = [
            'Songs: ', Percentage(),
            ' ', Bar(marker='#',left='[',right=']'),
            ' (', Counter(), ' in ' + str(nb_songs_delta) + ') ',
            ETA()]
    pbar = ProgressBar(widgets=widgets, maxval=nb_songs_delta)
    pbar.start()
    # slicing
    limits = range(0, nb_songs_delta, 30)
    if not limits[-1] == nb_songs_delta:
        limits.append(nb_songs_delta)
    for start, end in zip(limits[:-1], limits[1:]):
        logger.info('Processing song index from  %i to %i ...', start, end)
        pbar.update(start)
        command = []
        songs_index_slice = range(start, end)
        for song_index in songs_index_slice:
            song_id = songs_id_delta[song_index]
            rating = songs[song_id]['rating'] * 2
            mb_song_id = 'musicbrainz:song:' + songs[song_id]['musicbrainztrackid']
            #TODO: use API function
            command.append({
                "action": 'update',
                "item": {
                    "item_id": str(song_id),
                    "song_id": mb_song_id,
                    "rating": rating, 
                    "play_count": songs[song_id]['playcount']
                    }
                })

            songs[song_id]['rating_en'] = songs[song_id]['rating']
            songs[song_id]['playcount_en'] = songs[song_id]['playcount']
        url = 'http://developer.echonest.com/api/v4/tasteprofile/update'
        headers = {'content-type': 'multipart/form-data'}
        payload = {
                'api_key': api_key,
                'id': profile_id,
                'data': json.dumps(command)}
        logger.debug('command: %s', command)
        r = requests.post(url, headers=headers, params=payload)
        if r.status_code == 200:
            logger.debug('return: %s', r.text)
        else:
            logger.error('return: %s', r.text)
        time.sleep(0.51)
    pbar.finish()
    save_songs(songs)
    print
def echonest_sync(api_key, profile_id, songs):
    '''Sync songs with echonest tasteprofile'''
    logger.debug('call echonest_sync')
    #TODO: cache the profile ID
    #TODO: create routines for echonest API calls + HTTP Kodi calls
    en_info = en_api.echonest_info(api_key, profile_id)
    if en_info['total'] == 0:
        logger.info("no songs in tasteprofile, full sync")
        songs_id_delta = songs.keys()
    else:
        logger.info("limit sync to delta")
        songs_id_delta = get_profile_delta(songs)
    nb_songs_delta = len(songs_id_delta)
    print
    print "Sync songs to the tasteprofile (this can be very very long)"
    print
    logger.info('delta size: %i', nb_songs_delta)
    logger.debug('delta songs %s', songs_id_delta)
    widgets = [
        'Songs: ',
        Percentage(), ' ',
        Bar(marker='#', left='[', right=']'), ' (',
        Counter(), ' in ' + str(nb_songs_delta) + ') ',
        ETA()
    ]
    pbar = ProgressBar(widgets=widgets, maxval=nb_songs_delta)
    pbar.start()
    # slicing
    limits = range(0, nb_songs_delta, 30)
    if not limits[-1] == nb_songs_delta:
        limits.append(nb_songs_delta)
    for start, end in zip(limits[:-1], limits[1:]):
        logger.info('Processing song index from  %i to %i ...', start, end)
        pbar.update(start)
        command = []
        songs_index_slice = range(start, end)
        for song_index in songs_index_slice:
            song_id = songs_id_delta[song_index]
            rating = songs[song_id]['rating'] * 2
            mb_song_id = 'musicbrainz:song:' + songs[song_id][
                'musicbrainztrackid']
            #TODO: use API function
            command.append({
                "action": 'update',
                "item": {
                    "item_id": str(song_id),
                    "song_id": mb_song_id,
                    "rating": rating,
                    "play_count": songs[song_id]['playcount']
                }
            })

            songs[song_id]['rating_en'] = songs[song_id]['rating']
            songs[song_id]['playcount_en'] = songs[song_id]['playcount']
        url = 'http://developer.echonest.com/api/v4/tasteprofile/update'
        headers = {'content-type': 'multipart/form-data'}
        payload = {
            'api_key': api_key,
            'id': profile_id,
            'data': json.dumps(command)
        }
        logger.debug('command: %s', command)
        r = requests.post(url, headers=headers, params=payload)
        if r.status_code == 200:
            logger.debug('return: %s', r.text)
        else:
            logger.error('return: %s', r.text)
        time.sleep(0.51)
    pbar.finish()
    save_songs(songs)
    print