Example #1
0
 static Album albumFromElement(DomElement element, String artistName) {
   if (element == null) return null;
   Album album = new Album(null, null, artistName);
   MusicEntry.loadStandardInfo(album, element);
   if (element.hasChild("id")) {
     album.id = element.getChildText("id");
   }
   if (element.hasChild("artist")) {
     album.artist = element.getChild("artist").getChildText("name");
     if (album.artist == null) album.artist = element.getChildText("artist");
   }
   if (element.hasChild("releasedate")) {
     try {
       album.releaseDate = RELEASE_DATE_FORMAT.parse(element.getChildText("releasedate"));
     } catch (ParseException e) {
       // uh oh
     }
   }
   if (element.hasChild("toptags")) {
     for (DomElement o : element.getChild("toptags").getChildren("tag")) {
       album.tags.add(o.getChildText("name"));
     }
   }
   return album;
 }
Example #2
0
 static Image imageFromElement(DomElement e) {
   Image i = new Image();
   i.title = e.getChildText("title");
   i.url = e.getChildText("url");
   i.format = e.getChildText("format");
   try {
     i.dateAdded = DATE_ADDED_FORMAT.parse(e.getChildText("dateadded"));
   } catch (ParseException e1) {
     e1.printStackTrace();
   }
   DomElement owner = e.getChild("owner");
   if (owner != null) i.owner = owner.getChildText("name");
   DomElement votes = e.getChild("votes");
   if (votes != null) {
     i.thumbsUp = Integer.parseInt(votes.getChildText("thumbsup"));
     i.thumbsDown = Integer.parseInt(votes.getChildText("thumbsdown"));
   }
   DomElement sizes = e.getChild("sizes");
   for (DomElement image : sizes.getChildren("size")) {
     // code copied from ImageHolder.loadImages
     String attribute = image.getAttribute("name");
     ImageSize size;
     if (attribute == null)
       size = ImageSize.MEDIUM; // workaround for image responses without size attr.
     else size = ImageSize.valueOf(attribute.toUpperCase(Locale.ENGLISH));
     i.imageUrls.put(size, image.getText());
   }
   return i;
 }
Example #3
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;
 }