public static <T> PaginatedResult<T> buildPaginatedResult(Result result, ItemFactory<T> factory) {
    if (!result.isSuccessful()) {
      return new PaginatedResult<T>(0, 0, Collections.<T>emptyList());
    }

    DomElement contentElement = result.getContentElement();
    return buildPaginatedResult(contentElement, contentElement, factory);
  }
示例#2
0
 /**
  * Get the tags applied by an individual user to an album on Last.fm.
  *
  * @param artist The artist name in question
  * @param album The album name in question
  * @param session A Session instance
  * @return a list of tags
  */
 public static Collection<String> getTags(String artist, String album, Session session) {
   Result result =
       Caller.getInstance().call("album.getTags", session, "artist", artist, "album", album);
   if (!result.isSuccessful()) return Collections.emptyList();
   DomElement element = result.getContentElement();
   Collection<String> tags = new ArrayList<String>();
   for (DomElement domElement : element.getChildren("tag")) {
     tags.add(domElement.getChildText("name"));
   }
   return tags;
 }
示例#3
0
 /**
  * Get the metadata for an album on Last.fm using the album name or a musicbrainz id. See
  * playlist.fetch on how to get the album playlist.
  *
  * @param artist Artist's name
  * @param albumOrMbid Album name or MBID
  * @param apiKey The API key
  * @return Album metadata
  */
 public static Album getInfo(String artist, String albumOrMbid, String apiKey) {
   Map<String, String> params = new HashMap<String, String>();
   if (StringUtilities.isMbid(albumOrMbid)) {
     params.put("mbid", albumOrMbid);
   } else {
     params.put("artist", artist);
     params.put("album", albumOrMbid);
   }
   Result result = Caller.getInstance().call("album.getInfo", apiKey, params);
   DomElement element = result.getContentElement();
   return albumFromElement(element);
 }
示例#4
0
文件: Group.java 项目: phoezienk/ucup
 public static PaginatedResult<User> getMembers(String group, int page, String apiKey) {
   Result result =
       Caller.getInstance()
           .call("group.getMembers", apiKey, "group", group, "page", String.valueOf(page));
   if (!result.isSuccessful())
     return new PaginatedResult<User>(0, 0, Collections.<User>emptyList());
   DomElement root = result.getContentElement();
   Collection<DomElement> children = root.getChildren("user");
   List<User> users = new ArrayList<User>(children.size());
   for (DomElement child : children) {
     users.add(User.userFromElement(child));
   }
   page = Integer.parseInt(root.getAttribute("page"));
   int total = Integer.parseInt(root.getAttribute("totalPages"));
   return new PaginatedResult<User>(page, total, users);
 }
示例#5
0
 /**
  * Use the last.fm corrections data to check whether the supplied artist has a correction to a
  * canonical artist. This method returns a new {@link Artist} object containing the corrected
  * data, or <code>null</code> if the supplied Artist was not found.
  *
  * @param artist The artist name to correct
  * @return a new {@link Artist}, or <code>null</code>
  */
 public static final Artist getCorrection(final Context context, final String artist) {
   Result result = null;
   try {
     result = Caller.getInstance(context).call("artist.getCorrection", "<key>", "artist", artist);
     if (!result.isSuccessful()) {
       return null;
     }
     final DomElement correctionElement = result.getContentElement().getChild("correction");
     if (correctionElement == null) {
       return new Artist(artist, null);
     }
     final DomElement artistElem = correctionElement.getChild("artist");
     return FACTORY.createItemFromElement(artistElem);
   } catch (final Exception ignored) {
     return null;
   }
 }
 public static <T> Collection<T> buildCollection(Result result, ItemFactory<T> factory) {
   if (!result.isSuccessful()) return Collections.emptyList();
   return buildCollection(result.getContentElement(), factory);
 }
 public static <T> T buildItem(Result result, ItemFactory<T> factory) {
   if (!result.isSuccessful()) return null;
   return buildItem(result.getContentElement(), factory);
 }