示例#1
0
def upload_and_get_echonest_id(mp3name):
    ECHONEST_API_KEY = get_config_key("ECHONEST_API_KEY")
    cmd = 'curl -F "api_key={0}" -F "filetype=mp3" -F "track=@{1}" "http://developer.echonest.com/api/v4/track/upload"'.format(
        ECHONEST_API_KEY, mp3name
    )
    devnull = open(os.devnull, "w")
    return get_id_from_echonest_json_string(subprocess.check_output(cmd, shell=True, stderr=devnull))
import os
import numpy as np
import sqlite3
import iterate_songs

from time import time
import time as t
import sys
from util import get_config_key

ORDER = get_config_key("POLY_ORDER")
INSERT_BATCH_SIZE = get_config_key("INSERT_BATCH_SIZE")
INSERT_STMT = 'INSERT OR REPLACE INTO SONGS (title, artist, id, startTime, endTime, features) VALUES  (?, ?, ?, ?, ?, ?);'

USG_MSG = "usage: python compute_timbre_feat.py analysis_root_path output_db_path"


def features_as_str(feature_vector):
    return ','.join(map(str, feature_vector))


def unicode_if_str(obj, encoding):
    if isinstance(obj, str):
        return unicode(obj, encoding)
    else:
        return obj


def gen_song_tuples(root_path):
    # Parameters
    # root_path: string -- path to MillionSongSubset's data folder
示例#3
0
import subprocess
import os
import json
import sys
import urllib2
import util
from util import get_config_key

ECHONEST_API_KEY = get_config_key("ECHONEST_API_KEY")


def upload_and_get_echonest_id(mp3name):
    ECHONEST_API_KEY = get_config_key("ECHONEST_API_KEY")
    cmd = 'curl -F "api_key={0}" -F "filetype=mp3" -F "track=@{1}" "http://developer.echonest.com/api/v4/track/upload"'.format(
        ECHONEST_API_KEY, mp3name
    )
    devnull = open(os.devnull, "w")
    return get_id_from_echonest_json_string(subprocess.check_output(cmd, shell=True, stderr=devnull))


def get_id_from_echonest_json_string(json_str):
    return json.loads(json_str)["response"]["track"]["id"]


def get_profile(id):
    get_req = "http://developer.echonest.com/api/v4/track/profile?api_key={0}&format=json&id={1}&bucket=audio_summary".format(
        ECHONEST_API_KEY, id
    )
    json = urllib2.urlopen(get_req).read()
    return json