Esempio n. 1
0
  public void fillInEchoNestInfo() throws IOException, EchoNestException {
    if (artist == null || title == null) {
      JSONObject songProfile = null;
      try {
        songProfile =
            EchoNestQuery.get("song", "profile", "id=" + EchoNestId + "&bucket=audio_summary");
      } catch (EchoNestException e) {
      }

      JSONObject song = songProfile.optJSONArray("songs").optJSONObject(0);

      artist = new Artist(song.optString("artist_name"), song.optString("artist_id"));
      title = song.optString("title");
      duration = song.optJSONObject("audio_summary").optInt("duration");
    } else if (EchoNestId == null) {
      String artistName = URLEncoder.encode(artist.getName(), "UTF-8");
      String title = URLEncoder.encode(this.title, "UTF-8");

      JSONObject songSearch = null;
      try {
        songSearch =
            EchoNestQuery.get(
                "song",
                "search",
                "artist="
                    + artistName
                    + "&title="
                    + title
                    + "&results=1"
                    + "&bucket=audio_summary");
      } catch (EchoNestException e) {
      }

      JSONArray songs = songSearch.optJSONArray("songs");
      if (songs.length() == 0) throw new EchoNestException(6, "No items found.");

      JSONObject song = songs.optJSONObject(0);

      artist = new Artist(song.optString("artist_name"), song.optString("artist_id"));
      EchoNestId = song.optString("id");
      duration = song.optJSONObject("audio_summary").optInt("duration");
    } else if (duration == -1) {
      JSONObject songProfile = null;
      try {
        songProfile =
            EchoNestQuery.get("song", "profile", "id=" + EchoNestId + "&bucket=audio_summary");
      } catch (EchoNestException e) {
      }

      duration =
          songProfile
              .optJSONArray("songs")
              .optJSONObject(0)
              .optJSONObject("audio_summary")
              .optInt("duration");
    }
  }
Esempio n. 2
0
  public boolean equals(Object songObj) {
    if (!(songObj instanceof Song)) return false;

    Song song = (Song) songObj;
    return (artist.equals(song.getArtist()) && title.equalsIgnoreCase(song.getTitle()));
  }
Esempio n. 3
0
 public String toString() {
   return artist.toString() + " - " + getTitle();
 }