Package se.despotify.util

Examples of se.despotify.util.XMLElement


    if (log.isDebugEnabled()) {
      log.debug(xml);
    }

    XMLElement playlistElement = XML.load(xml);

    if (user.getPlaylists() == null) {
      user.setPlaylists(new PlaylistContainer());
    }
    PlaylistContainer.fromXMLElement(playlistElement, store, user.getPlaylists());

    if (playlistElement.hasChild("next-change")) {
      return true;
    } else {
      throw new RuntimeException("Unknown server response:\n" + xml);
    }
View Full Code Here



    if (log.isDebugEnabled()) {
      log.debug(xml);
    }
    XMLElement playlistElement = XML.load(xml);

    if (playlistElement.hasChild("confirm")) {
      /* Split version string into parts. */
      String[] parts = playlistElement.getChild("confirm").getChildText("version").split(",", 4);

      /* Set values. */
      playlist.setRevision(Long.parseLong(parts[0]));
      playlist.setChecksum(Long.parseLong(parts[2]));
      playlist.setCollaborative(Integer.parseInt(parts[3]) == 1);
View Full Code Here

            new String(data, Charset.forName("UTF-8")) +
            "</playlist>";
    if (log.isDebugEnabled()) {
      log.debug(xml);
    }
    XMLElement playlistElement = XML.load(xml);


    if (playlistElement.hasChild("confirm")) {
      /* Split version string into parts. */
      String[] parts = playlistElement.getChild("confirm").getChildText("version").split(",", 4);

      /* Set values. */
      playlist.setRevision(Long.parseLong(parts[0]));
      playlist.setChecksum(Long.parseLong(parts[2]));
      playlist.setCollaborative(Integer.parseInt(parts[3]) == 1);
View Full Code Here

    } else if (packetType == PacketType.productInformation) {
      /* Payload is uncompressed XML. */

      String xml = new String(payload, Charset.forName("UTF-8"));
      XMLElement root = XML.load(xml);
      productType = ProductType.valueOf(root.getChild("product").getChild("type").getText());
      if (!allowProductType(productType)) {
        // todo more generic message
        log.error("Sorry, you need a premium account to use Despotify (this is a restriction by Spotify).\nTry setting property despotify.allowProductType = true");
        System.exit(0);
      }
View Full Code Here

          track.setDiscNumber(discNumber);
          tracks.add(track);
        }
      }

      XMLElement restrictionsNode = albumElement.getChild("restrictions");
      if (restrictionsNode != null) {
        album.restrictions = Restrictions.fromXMLElement(restrictionsNode);
      }

      if (albumElement.hasChild("copyright")) {
View Full Code Here

      artist.name = artistNode.getChildText("name");
    }

    /* Set portrait. */
    if (artistNode.hasChild("portrait")) {
      XMLElement portraitNode  = artistNode.getChild("portrait");
      if (!"".equals(portraitNode.getText().trim())) {
        artist.portrait = Image.fromXMLElement(portraitNode, store);
      }
    }

    /* Set popularity. */
    if (artistNode.hasChild("popularity")) {
      artist.popularity = Float.parseFloat(artistNode.getChildText("popularity"));
    }

    XMLElement biosNode = artistNode.getChild("bios");
    if (biosNode != null) {

      List<Biography> biographies = new ArrayList<Biography>();

      for (XMLElement bioNode : biosNode.getChildren()) {
        if (!"bio".equals(bioNode.getElement().getNodeName())) {
          log.warn("Unknown bios child node " + bioNode.getElement().getNodeName());
        } else {
          Biography biography = new Biography();
          biography.setText(bioNode.getChildText("text"));
          if (bioNode.hasChild("portraits")) {
            biography.setPortraits(new ArrayList<Image>());
            for (XMLElement portraitNode : bioNode.getChild("portraits").getChildren()) {
              biography.getPortraits().add(Image.fromXMLElement(portraitNode, store));
            }
          }
          biographies.add(biography);
        }
        artist.biographies = biographies;
      }
    }

    if (artistNode.hasChild("years-active")) {
      artist.yearsActive = new ArrayList<String>(Arrays.asList(artistNode.getChildText("years-active").split(",")));
    }

    if (artistNode.hasChild("genres")) {
      artist.genres = new ArrayList<String>(Arrays.asList(artistNode.getChildText("genres").split(",")));
    }

    XMLElement albumsNode = artistNode.getChild("albums");
    if (albumsNode != null) {
      List<Album> albums = new ArrayList<Album>();
      for (XMLElement albumNode : albumsNode.getChildren())  {
        albums.add(Album.fromXMLElement(albumNode, store));
      }
      artist.albums = albums;
    }

View Full Code Here


  public static PlaylistContainer fromXMLElement(XMLElement playlistsElement, Store store, PlaylistContainer playlists){

    /* Get "change" element. */
    XMLElement changeElement = playlistsElement.getChild("next-change").getChild("change");
   
    if (changeElement.hasChild("user")) {
      playlists.author = changeElement.getChildText("user").trim();
    }
   
    /* Get items (comma separated list). */
    if(changeElement.getChild("ops").hasChild("add")){
      String items = changeElement.getChild("ops").getChild("add").getChildText("items");
     
      for(String playlistUUID : items.split(",")){
        playlistUUID = playlistUUID.trim();
        if (playlistUUID.length() == 34 && playlistUUID.endsWith("02")) {
          playlistUUID = playlistUUID.substring(0, 32);
        }
        Playlist playlist = store.getPlaylist(playlistUUID);
        if (!playlists.getItems().contains(playlist)) {
          playlists.getItems().add(playlist);
        }
        // todo remove deleted?
      }
    }
   
    /* Get "version" element. */
    XMLElement versionElement = playlistsElement.getChild("next-change").getChild("version");
   
    /* Split version string into parts. */
    String[] versionTagValues = versionElement.getText().split(",", 4);

    playlists.setRevision(Long.parseLong(versionTagValues[0]));
    playlists.setChecksum(Long.parseLong(versionTagValues[2]));

    if (playlists.getItems().size() != Long.parseLong(versionTagValues[1])) {
View Full Code Here

  }

  public static void fromXMLElement(XMLElement playlistElement, Store store, Playlist playlist) throws DespotifyException {

    /* Get "change" element. */
    XMLElement changeElement = playlistElement.getChild("next-change").getChild("change");
   
    /* Set author. */
    playlist.author = changeElement.getChildText("user");
   
    /* Set name. */
    playlist.name = changeElement.getChild("ops").getChildText("name");
   
    /* Get items (comma separated list). */
    if (changeElement.getChild("ops").hasChild("add")) {
      String items = changeElement.getChild("ops").getChild("add").getChildText("items");

      if (playlist.tracks == null) {
        playlist.tracks = new ArrayList<Track>();
      }



      /* Add track items. */
      int position = 0;
      String[] split = items.split(",");

      List<Track> tracks = new ArrayList<Track>(split.length);


      for (String trackData : split) {
        trackData = trackData.trim();
        final String trackHexUUID;
        if (trackData.length() != 34) {
          if (SpotifyURI.isHex(trackData)) {
            // not sure why playlist UUID is send sometimes. notice it is lacking UUID prefix byte
            if (!trackData.equals(playlist.getHexUUID())) {
              throw new DespotifyException("32 byte hex UUID does not equal the playlist UUID!");
            }
            continue;
          } else {
            throw new RuntimeException(trackData + " is not a valid 32 byte hex UUID!");
          }
        } else if (trackData.length() == 34) {
          trackHexUUID = trackData.substring(0, 32);
          if (!"01".equals(trackData.substring(32, 34))) {
            throw new DespotifyException("Expected hex UUID type suffix 01, got " +  trackData.substring(32, 34));
          }
        } else {
          throw new RuntimeException("track UUID was not 16+1 or 16 byte!");
        }

        Track track = store.getTrack(trackHexUUID);
        tracks.add(track);

        position++; // perhaps we should use this to syncronize any discrepancy
      }

      playlist.setTracks(tracks);
    }
   
    /* Get "version" element. */
    XMLElement versionElement = playlistElement.getChild("next-change").getChild("version");
   
    /* Split version string into parts. */
    String[] parts = versionElement.getText().split(",", 4);
   
    /* Set values. */

    String[] versionTagValues = versionElement.getText().split(",", 4);

    playlist.setRevision(Long.parseLong(versionTagValues[0]));       
    playlist.setChecksum(Long.parseLong(versionTagValues[2]));
    playlist.collaborative = (Integer.parseInt(parts[3]) == 1);

View Full Code Here

    if(trackElement.hasChild("popularity")){
      track.popularity = Float.parseFloat(trackElement.getChildText("popularity"));
    }

   
    XMLElement restrictionsNode = trackElement.getChild("restrictions");
    if (restrictionsNode != null) {
        track.restrictions = Restrictions.fromXMLElement(restrictionsNode);
    }

    return track;
View Full Code Here

    String xml = new String(data, Charset.forName("UTF-8"));
    if (log.isDebugEnabled()) {
      log.debug(xml);
    }
    XMLElement root = XML.load(xml);

    if (root.getElement().getNodeName().equals("artist")) {
      Artist.fromXMLElement(root, store);
    } else {
      throw new DespotifyException("Root element is not named <artist>: " + root.getElement().getNodeName());
    }


    artist.setLoaded(new Date());
View Full Code Here

TOP

Related Classes of se.despotify.util.XMLElement

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.