Package com.echonest.api.v4.util

Examples of com.echonest.api.v4.util.Shell


    private Set<Artist> done = new HashSet<Artist>();
    private List<Artist> todo = new ArrayList<Artist>();
    private Track currentTrack;

    public EchonestDevShell() throws EchoNestException {
        en = new EchoNestAPI();
        shell = new Shell();
        shell.setPrompt("nest% ");
        addEchoNestCommands();
    }
View Full Code Here


public class TasteProfileExample {

    private EchoNestAPI en;

    public TasteProfileExample() throws EchoNestException {
        en = new EchoNestAPI();
    }
View Full Code Here

            results = getMapResults(command, usePost, file);
            checkStatus(results);
            ok = true;
            return results;
        } catch (IOException ioe) {
            throw new EchoNestException(ioe);
        } finally {
            if (!ok && traceErrs && !traceSends) {
                System.out.println("send-err-> " + command);
                if (results != null && !traceRecvs) {
                    System.out.println("recv-err-> " + results.toString());
View Full Code Here

            try {
                URI uri = new URI(fullCommand);
                url = uri.toURL();
            } catch (URISyntaxException e) {
                throw new EchoNestException(
                        EchoNestException.CLIENT_SERVER_INCONSISTENCY,
                        "Bad URL " + e);
            } catch (MalformedURLException e) {
                throw new EchoNestException(
                        EchoNestException.CLIENT_SERVER_INCONSISTENCY,
                        "Bad URL " + e);
            }

            if (traceSends) {
                System.out.println("Sending-->     " + url);
            }

            conn = (HttpURLConnection) url.openConnection();
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setAllowUserInteraction(false);
            conn.setUseCaches(false);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Accept", "*/*");
            conn.setRequestProperty("Connection", "Keep-Alive");
            conn.setRequestProperty("Cache-Control", "no-cache");
            conn.setRequestProperty("Content-Type",
                    "multipart/form-data;boundary=" + BOUNDARY);
            DataOutputStream dostream = new DataOutputStream(conn.getOutputStream());
            //DataOutputStream dostream = new DataOutputStream(System.out);
            OutputStreamWriter out = new OutputStreamWriter(dostream, "utf-8");

            Map<String, Object> p = new HashMap<String, Object>(params);

            for (Entry<String, Object> kv : standardParams.getMap().entrySet()) {
                p.put(kv.getKey(), kv.getValue());
            }


            if (false) {
                for (String s : p.keySet()) {
                    System.out.printf("   %s=%s\n", s, p.get(s));
                }
            }
            for (String key : p.keySet()) {
                out.write(PREFIX);
                out.write(BOUNDARY);
                out.write(NEWLINE);
                Object val = p.get(key);

                if (val instanceof File) {

                    File file = (File) val;

                    out
                            .write("Content-Disposition: form-data; name=\"file\";"
                            + " filename=\"" + file.getName() + "\"");
                    out.write(NEWLINE);
                    out.write("Content-Type: application/octet-stream");
                    out.write(NEWLINE);
                    out.write(NEWLINE);
                    out.flush();

                    InputStream is = new FileInputStream(file);
                    int r = 0;
                    byte[] data = new byte[1024];
                    while ((r = is.read(data, 0, data.length)) != -1) {
                        dostream.write(data, 0, r);
                    }
                    is.close();
                    out.write(NEWLINE);
                } else {
                    out.write("Content-Disposition: form-data; name=\""
                            + key + "\"");
                    out.write(NEWLINE);
                    out.write(NEWLINE);
                    out.write(val.toString());
                    //dos.writeUTF(val.toString());
                    out.write(NEWLINE);
                }
            }
            out.write(PREFIX);
            out.write(BOUNDARY);
            out.write(PREFIX);
            out.write(NEWLINE);
            // close streams
            out.flush();
            out.close();

            int code = conn.getResponseCode();

            InputStream is = null;
            if (code >= 300) {
                is = conn.getErrorStream();
            } else {
                is = conn.getInputStream();
            }
            BufferedReader in = new BufferedReader(new InputStreamReader(is,
                    Charset.forName("UTF-8")));

            String line = null;
            StringBuilder results = new StringBuilder();

            while ((line = in.readLine()) != null) {
                results.append(line);
            }

            if (traceRecvs) {
                System.out.println("received-->     " + results.toString());
            }
            in.close();
            String resultString = results.toString();

            try {
                JSONObject jobj = (JSONObject) parser.parse(resultString);
                checkStatus(jobj);
                return (Map) jobj;
            } catch (ParseException e) {
                throw new IOException("Parse Exception", e);
            }
        } catch (IOException ioe) {
            throw new EchoNestException(ioe);
        }
    }
View Full Code Here

        Long scode = (Long) status.get("code");

        int code = scode.intValue();

        if (!version.startsWith(expectedVersion)) {
            throw new EchoNestException(
                    EchoNestException.CLIENT_SERVER_INCONSISTENCY,
                    "Unexpected API version number");
        }

        if (code != 0) {
            throw new EchoNestException(code, message);
        }
    }
View Full Code Here

        }

        System.out.println(" =========  images ======== ");
        List<Image> images = artist.getImages();
        for (int i = 0; i < images.size(); i++) {
            Image image = images.get(i);
            image.dump();
        }

        System.out.println(" =========  news ======== ");
        List<News> newsList = artist.getNews();
        for (int i = 0; i < newsList.size(); i++) {
View Full Code Here

        }

        System.out.println(" =========  news ======== ");
        List<News> newsList = artist.getNews();
        for (int i = 0; i < newsList.size(); i++) {
            News news = newsList.get(i);
            news.dump();
        }

        System.out.println(" =========  reviews ======== ");
        List<Review> reviews = artist.getReviews();
        for (int i = 0; i < reviews.size(); i++) {
View Full Code Here

        }
    }

    public void searchArtistByName(String name, int results)
            throws EchoNestException {
        Params p = new Params();
        p.add("name", name);
        p.add("results", results);

        List<Artist> artists = en.searchArtists(p);
        for (Artist artist : artists) {
            dumpArtist(artist);
            System.out.println();
View Full Code Here

        }
    }

    public void searchSongsByTempo(String artist, int results)
            throws EchoNestException {
        Params p = new Params();
        p.add("artist", artist);
        p.add("bucket", "audio_summary");
        p.add("results", results);
        p.add("sort", "tempo-asc");

        List<Song> songs = en.searchSongs(p);
        for (Song song : songs) {
            System.out.printf("%.0f %s %s\n", song.getTempo(), song
                    .getArtistName(), song.getTitle());
View Full Code Here

            throws EchoNestException {
        ArtistParams ap = new ArtistParams();
        ap.addName(artist);
        List<Artist> artists = en.searchArtists(ap);
        if (artists.size() > 0) {
            Params p = new Params();
            p.add("artist_id", artists.get(0).getID());
            p.add("bucket", "audio_summary");
            p.add("results", results);
            p.add("sort", "tempo-desc");

            List<Song> songs = en.searchSongs(p);
            for (Song song : songs) {
                System.out.printf("%.0f %s %s\n", song.getTempo(), song
                        .getArtistName(), song.getTitle());
View Full Code Here

TOP

Related Classes of com.echonest.api.v4.util.Shell

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.