Esempio n. 1
0
 /**
  * Get a list of valid countries and {@link de.umass.lastfm.Geo.Metro}s for use in the other
  * webservices.
  *
  * @param country Optionally restrict the results to those Metros from a particular country, as
  *     defined by the ISO 3166-1 country names standard
  * @param apiKey A Last.fm API key
  * @return a List of {@link de.umass.lastfm.Geo.Metro}s
  */
 public static Collection<Metro> getMetros(String country, String apiKey) {
   Map<String, String> params = new HashMap<String, String>();
   MapUtilities.nullSafePut(params, "country", country);
   Result result = Caller.getInstance().call("geo.getMetros", apiKey, params);
   if (!result.isSuccessful()) return Collections.emptyList();
   Collection<DomElement> children = result.getContentElement().getChildren("metro");
   Collection<Metro> metros = new ArrayList<Metro>(children.size());
   for (DomElement child : children) {
     metros.add(new Metro(child.getChildText("name"), child.getChildText("country")));
   }
   return metros;
 }
 public User createItemFromElement(DomElement element) {
   User user = new User(element.getChildText("name"), element.getChildText("url"));
   user.id = element.getChildText("id");
   if (element.hasChild("realname")) user.realname = element.getChildText("realname");
   ImageHolder.loadImages(user, element);
   user.language = element.getChildText("lang");
   user.country = element.getChildText("country");
   if (element.hasChild("age")) {
     try {
       user.age = Integer.parseInt(element.getChildText("age"));
     } catch (NumberFormatException e) {
       // no age
     }
   }
   user.gender = element.getChildText("gender");
   user.subscriber = "1".equals(element.getChildText("subscriber"));
   if (element.hasChild("playcount")) { // extended user information
     try {
       user.playcount = Integer.parseInt(element.getChildText("playcount"));
     } catch (NumberFormatException e) {
       // no playcount
     }
   }
   if (element.hasChild("playlists")) { // extended user information
     try {
       user.numPlaylists = Integer.parseInt(element.getChildText("playlists"));
     } catch (NumberFormatException e) {
       // no playlists
     }
   }
   return user;
 }
Esempio n. 3
0
    public Playlist createItemFromElement(DomElement element) {
      Playlist playlist = new Playlist();

      if (element.hasChild("id")) playlist.id = Integer.parseInt(element.getChildText("id"));

      playlist.title = element.getChildText("title");

      if (element.hasChild("size")) playlist.size = Integer.parseInt(element.getChildText("size"));

      playlist.creator = element.getChildText("creator");
      playlist.annotation = element.getChildText("annotation");

      DomElement trackList = element.getChild("trackList");
      if (trackList != null) {
        for (DomElement te : trackList.getChildren("track")) {
          Track t =
              new Track(
                  te.getChildText("title"),
                  te.getChildText("identifier"),
                  te.getChildText("creator"));
          t.album = te.getChildText("album");
          t.duration = Integer.parseInt(te.getChildText("duration")) / 1000;
          t.imageUrls.put(ImageSize.LARGE, te.getChildText("image"));
          t.imageUrls.put(ImageSize.ORIGINAL, te.getChildText("image"));
          t.location = te.getChildText("location");
          for (DomElement ext : te.getChildren("extension")) {
            if ("http://www.last.fm".equals(ext.getAttribute("application"))) {
              for (DomElement child : ext.getChildren()) {
                t.lastFmExtensionInfos.put(child.getTagName(), child.getText());
              }
            }
          }
          playlist.tracks.add(t);
        }

        if (playlist.size == 0) playlist.size = playlist.tracks.size();
      }

      return playlist;
    }