#!/usr/bin/python
billy_jean_code = (
    'eJxVlIuNwzAMQ1fxCDL133-xo1rnGqNAEcWy_ERa2aKeZmW9ustWVYrXr'
    'l5bthn_laFkzguNWpklEmoTB74JKYZSPlbJ0sy9fQrsrbEaO9W3bsbaWO'
    'oK7IhkHFaf_ag2d75oOQSZczbz5CKA7XgTIBIXASvFi0A3W8pMUZ7FZTW'
    'TVbujCcADlQ_f_WbdRNJ2vDUwSF0EZmFvAku_CVy440fgiIvArWZZWoJ7'
    'GWd-CVTYC5FCFI8GQdECdROE20UQfLoIUmhLC7IiByF1gzbAs3tsSKcty'
    'C76MPJlHRsZ5qhSQhu_CJFcKtW4EMrHSIrpTGLFqsdItj1H9JYHQYN7W2'
    'nkC6GDPjZTAzL9dx0fS4M1FoROHh9YhLHWdRchQSd_CLTpOHkQQP3xQsA'
    '2-sLOUD7CzxU0GmHVdIxh46Oide0NrNEmjghG44Ax_k2AoDHsiV6WsiD6'
    'OFm8y-0Lyt8haDBBzeMlAnTuuGYIB4WA2lEPAWbdeOabgFN6TQMs6ctLA'
    '5fHyKMBB0veGrjPfP00IAlWNm9n7hEh5PiYYBGKQDP-x4F0CL8HkhoQnR'
    'WN997JyEpnHFR7EhLPQMZmgXS68hsHktEVErranvSSR2VwfJhQCnkuwhB'
    'UcINNY-xu1pmw3PmBqU9-8xu0kiF1ngOa8vwBSSzzNw==')

rock_music_code = (
    'eJw1lwmWJCcMBa_U7HAc1vsfwRFZY8-zKhECpM-XUP_9_f7r_B8mIm5EV'
    'lWUKyLOJy4W6oPG4c9h8MsVIWEcclSoK9qV70u7WhV-Ne2aK7q67tdQN_'
    'yabjBxIyw3WG6gP2F_X25wXPb5cl32XPFYEfn3F3UwGkfU5Zg-URWsiNk'
    'Jw4qFXWP1q7JzbK5tznbthrrh18r_EIliEO8nnHgokxikyLJk-MnIk_sl'
    'o0xdIaRpfULj7bLjxPHrKvQ-i2nW-xywy1Gh41l3s_7lron-ZV3LwpS3E'
    '7qWr2sfsvyxrISowKSk7yodehWlcmQZTuhGMaLquVXAqgjVomicVj2yDv'
    'arHlSPJp7R_jBpXk2LmDTDbxm7pqetK7zQNjUWv3ZdYag9Yufl__Wm0K5'
    'PhVfbvdWh98OQhhc1tB5eyph-bU0eawUXgd0U6OkFzIbJdMUczkqpqRvT'
    'C5hHu-us2C9hX5H9VsJu6dUS3eXFr6XJ0eQx3KbFDgrZpRd_W6LvyqZbr'
    'Lan7emXgElYhCuM_EjRI2ondQXTR7CPQBwRP-bC8fDjBserPYZ6Of7vyr'
    'VrlNeMujLs6q6x_F09vR70DOvp6TOsp5OvfQLD1zUR9mdaPWF_QBJMokA'
    'CI9JGcAHB2yPhJ2I5sRVkQAgaIxWYBFwLwWUWgGDGh9AUQ7up2C47CvwN'
    'pmmILoswJ5iXwZQMsTsLiFQWZwkrJE_7akwqVYFJImFDGs4uha6lqx23R'
    'S3CJLtzzn7pUO5OTAXoBgkWMpkcCklHuWKXAttDORYuJyrJFGpQkEJEpW'
    '4olgL8QtW_-jBpQtdAPLRilYMWoRlMM5imf83w27PycaGhe27X0y5qvSj'
    '0tAtdF_auQ138uvj1o7GuDZhP6WRiCMkQutGspF2dKwaUD-Nq97rlHZOZ'
    'FC4zlxCYzKbgoHRSef2Roufl0y7jsdpJ3_iS__M3TnlQKRkXGJpnMvbW8'
    'kjz_ZUNfLfctUODwGm0-UCUmngLtCstn0OVS7egzDAovxFnQEf96yRPYz'
    'KNSGHl2hvpA4Qn7_DSYD5R0No3j_L_-Ui6fPM59NQoT-zBzR3m3RhyzR1'
    '2037UxXrWhVvAqLMO-5N7dN-aUkGJv6fvA0q9tFZxJfUoLc6ZVOAO5xPX'
    'qz5n4mFq9kMsBXv01GlY89lTykr_xZ87Ff0X_2F_lRzJ_n-f__s4_vnfN'
    '_5RMPKLCSUFCH6DA6G8jfJdcFsPlq7XiXUtKjvKceLdocTWa8trhVPGp0'
    'yvFUq6cbxzCrgTR3rgcv5-_oKLm19SssyUuvuCydsXJZfd30uOqbTpsWV'
    '_t7t1BZ5HPLUVznk3fb8zsZ7gh3jxYmT84RweQfJ-HPh93Z9KWsNbJO1O'
    'lPkWy-3J8noGtCFD0l61lms5eSi51zJ62qmncFAmX0vuNQKe0MUBfVCmU'
    'Gad1KVzdqljciQ4k-a1VvEnH8oYKEeq7bD5HDef8RLv4WwjcQLlmAckUE'
    'sf51PxMkrs2urB2hNnuRdVPhu7FsEA5Xthr53IqPV2o_XoddxHvu8zUfq'
    'IJJT2JLzLGO5-RIH71hqOAhJ-j93C5b6hKM9so1KHyksJroBd2GrNvh9e'
    'rjov98fJ9cwVJ1usszhiCifrzlQZR3qeS_TTilcu0UfyblKcagOHOTvBm'
    '053TuICjJHo2d7f5QkYs_AaJvaL9AMXPuIHuBqyfnw4yMe_DwdDFa8v_m'
    '178Ysf-__jx_5f_CO1NMsXPy_wHQQcod5Zs3AEz8eqcdRYed5pH2fp1LY'
    'UC-7XkHrfg2SnPF-UtHgQJJF8hyYieK9l5ZjhLfeFsi5qJ_dFzkz4zy8t'
    'Y12xQ8tPCet4JRKMGxflqK8XgvG64S7nBZZ7Lo9Hi8znyyBmnOVcxiPeU'
    'Ql9lpkXbQr4MR4pNmCyu8vb3gVQ5BlwqeRdBUPwiJyNkvV7okzi_6KMP-'
    'JPXIxtpHdZjbF4ooTfPzzlc0nep3w-X_fxRvrxblivPt6Zx_1nTx5Dqhm'
    '596Rfty_u3V4VJfvblcg7subSzvIun9_-HZpQlNifMvpGli80s9R1IuE8'
    'eDHswVR--ZLtoMqXL1I94GfMA_5nS_qINYkTdY_HZeK_dbmV2fW_RRp_n'
    'L8yphV4mzqMwc9pISNvLW6T806jIfpCbeRtauA9x8dP94n5x0-6IZVQq9'
    'FoZRpBqssj5-z24Rv1sqO00jz_2DC_rZemKPfg9OkydjGd5MOZj_XyAqX'
    'nyYt_5_34-KsfPz5CLfkYbP_yx0fqcw8fH1EmuiYHf-_tCh_hVaK0jI-H'
    'VGJw_Hjob_Cvg_H4zUVK0mdwA-L08exRH-Pv_vc_vjHo-cc3GMcj--LgF'
    'dycA4YZXqVM9ZvD9uwESiK_fa7cUh_ov_GN9X99H7GsT8-lUx3sUrePy_'
    'oogfLj449vPz5ab9_Hx6_e_vjIgfV8fOS3LELGvizzVh4f8KKRksf_99z'
    'f_uHrt7_92eebJ_XtkUQh85o9fimoPMmz7WZ93bcCGcUM7o_JRT5ejm39'
    '4_w6HXPZLyx6LeofdbBu37ldyxqLBpZjjTQUeLLlbffPqy--y_tb2y8-_'
    'owc_HJu_7POJgoEHCP-TfvROJ_4ZT1eULLDtF6gpBNe1gsvf0y6-C4jIs'
    'DQElfrEwUg9v8AAFXwlA==')

import json
import urllib

def download_code(filename, code):
    print 'generating %s' % filename
    url = ('http://developer.echonest.com/api/v4/song/identify'
           '?api_key=N6E4NIOVYMTHNDM8J'
           '&bucket=tracks&bucket=id:7digital'
           '&code=' + code)
    reply = urllib.urlopen(url).read()
    open(filename, 'wb').write(reply)

def download_id(filename, id):
    print 'generating %s' % filename
    url = ('http://developer.echonest.com/api/v4/song/profile'
           '?api_key=N6E4NIOVYMTHNDM8J'
           '&id=' + id)
    reply = urllib.urlopen(url).read()
    open(filename, 'wb').write(reply)

download_code('billie-jean', billy_jean_code)
download_code('rock-music', rock_music_code)
download_id('break-like-the-wind', 'SOBKZUR12B0B80C2C1')
download_code('no-match', 'fake-code')
download_code('error', '')
# make no-releases from rock music
no_releases_data = json.load(open('rock-music'))
del no_releases_data['response']['songs'][0]['tracks']
json.dump(no_releases_data, open('no-releases', 'wb'))
