Examples of DespotifyException


Examples of se.despotify.exceptions.DespotifyException

  @Override
  public Boolean send(Connection connection) throws DespotifyException {

    if (!playlist.isCollaborative() && !playlist.getAuthor().equals(user.getId())) {
      throw new DespotifyException("Playlist must be collaborative or owned by the current user!");
    }

    if (user.getPlaylists() == null) {
      new LoadUserPlaylists(store, user).send(connection);
    }
View Full Code Here

Examples of se.despotify.exceptions.DespotifyException

    }

    // todo probably don't destoy collaborative that is not owned by user? or?

    if (!sendDelete(connection.getProtocol(), position)) {
      throw new DespotifyException();
    }
    if (!sendDestroy(connection.getProtocol(), position)) {
      throw new DespotifyException();
    }
    return true;
  }
View Full Code Here

Examples of se.despotify.exceptions.DespotifyException

   */
  @Override
  public Track send(ConnectionManager connectionManager) throws DespotifyException {

    if (!playlist.isCollaborative() && !playlist.getAuthor().equals(user.getId())) {
      throw new DespotifyException("Playlist must be collaborative or owned by the current user!");
    }

    if (user.getPlaylists() == null) {
      new LoadUserPlaylists(store, user).send(connectionManager);
    }
View Full Code Here

Examples of se.despotify.exceptions.DespotifyException

   * @return Value as retuned by the executed matcher.
   */
  public static <T> T match(String URL, Visitor<T> matcher) {
    Matcher patternMatcher = pattern.matcher(URL);
    if (!patternMatcher.matches()) {
      throw new DespotifyException("Not a valid URL: " + URL);
    }

    URLtype urlType = patternMatcher.group(2) != null ? URLtype.httpURL : URLtype.spotifyURL;

    if (patternMatcher.group(5) != null) {
View Full Code Here

Examples of se.despotify.exceptions.DespotifyException

    playlist.setName(playlistName);
    playlist.setId(hexUUID);
    if (new CreatePlaylistWithReservedUUID(store, user, playlist).send(connectionManager)) {
      return (Playlist)store.persist(playlist);
    } else {
      throw new DespotifyException();
    }
  }
View Full Code Here

Examples of se.despotify.exceptions.DespotifyException

      new LoadPlaylist(store, playlist).send(connectionManager);
    }


    if (!playlist.isCollaborative() && !playlist.getAuthor().equals(user.getId())) {
      throw new DespotifyException("Playlist must be collaborative or owned by the current user!");
    }

    if (user.getPlaylists() == null) {
      new LoadUserPlaylists(store, user).send(connectionManager);
    }

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


    long previousChecksum = playlist.calculateChecksum();

    if (position != null && position != playlist.getTracks().size()) {
      throw new IllegalArgumentException("position not implemented!");
    }
   
    if (position == null) {
      position = playlist.size();
    }
    playlist.getTracks().add(position, track);

    playlist.setChecksum(playlist.calculateChecksum());

    String xml = String.format(
        "<change><ops><add><i>%s</i><items>%s</items></add></ops><time>%d</time><user>%s</user></change>" +
            "<version>%010d,%010d,%010d,%d</version>",
        position,
        track.getId() + "01", // hex uuid tag
        new Date().getTime() / 1000,
        user.getId(),
        playlist.getRevision() + 1,
        playlist.getTracks().size(),
        playlist.getChecksum(),
        playlist.isCollaborative() ? 1 : 0
    );

    /* Create channel callback */
    ChannelCallback callback = new ChannelCallback();

    Channel channel = new Channel("Change-Playlist-Channel", Channel.Type.TYPE_PLAYLIST, callback);
    byte[] xmlBytes = xml.getBytes();
    ByteBuffer buffer = ByteBuffer.allocate(2 + 16 + 1 + 4 + 4 + 4 + 1 + 1 + xmlBytes.length);

    /* Append channel id, playlist id and some bytes... */
    buffer.putShort((short) channel.getId());
    buffer.put(playlist.getByteUUID());
    buffer.put((byte) 0x02); // track UUID type tag

    buffer.putInt(playlist.getRevision().intValue());
    buffer.putInt(playlist.getTracks().size() - 1);
    buffer.putInt((int)previousChecksum); // -1 only seen when creating new playlist.
    buffer.put((byte) (playlist.isCollaborative() ? 0x01 : 0x00));
    buffer.put((byte) 0x03); // unknown
    buffer.put(xmlBytes);
    buffer.flip();

    /* Register channel. */
    Channel.register(channel);

    /* Send packet. */
    ManagedConnection connection = connectionManager.getManagedConnection();
    connection.getProtocol().sendPacket(PacketType.changePlaylist, buffer, "add track to playlist");

    /* Get response. */
    byte[] data = callback.getData("add track to playlist, updated playlist response");
    connection.close();
   

    xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<playlist>\n" +
        new String(data, Charset.forName("UTF-8")) +
        "\n</playlist>";
    log.debug(xml);
    XMLElement response = XML.load(xml);

    if (response.hasChild("confirm")) {
      // <version>0000000002,0000000001,1326385279,0</version>
      String[] versionTagValues = response.getChild("confirm").getChildText("version").split(",", 4);

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

      if (playlist.size() != Long.parseLong(versionTagValues[1])) {
        throw new RuntimeException("Size mismatch");
      }
      if(playlist.getChecksum() != playlist.calculateChecksum()) {
        throw new ChecksumException(playlist.getChecksum(), playlist.calculateChecksum());
      }
      if(playlist.isCollaborative() != (Integer.parseInt(versionTagValues[3]) == 1)) {
        throw new RuntimeException();
      }

      store.persist(playlist);

      return true;
    } else {
      playlist.getTracks().remove(position.intValue());
      throw new DespotifyException("Unknown server response:\n" + xml);
    }

  }
View Full Code Here

Examples of se.despotify.exceptions.DespotifyException

    // todo probably don't destoy collaborative that is not owned by user? or?

    ManagedConnection connection = connectionManager.getManagedConnection();
    if (!sendDelete(connection.getProtocol(), position)) {
      connection.close();
      throw new DespotifyException();
    }
    if (!sendDestroy(connection.getProtocol(), position)) {
      connection.close();
      throw new DespotifyException();
    }
    connection.close();
    return true;
  }
View Full Code Here

Examples of se.despotify.exceptions.DespotifyException

    /* Get data and inflate it. */
    data = callback.getData("get playlist response");

    if (data.length == 0) {
      throw new DespotifyException("Received an empty response");
    }

    /* Load XML. */
    String xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><playlist>" +
        new String(data, Charset.forName("UTF-8")) +
View Full Code Here

Examples of se.despotify.exceptions.DespotifyException

    try {
      XMLStreamReader xmlr = ResponseUnmarshaller.createReader(new InputStreamReader(new GZIPInputStream(new ByteArrayInputStream(data)), Charset.forName("UTF-8")));
      ResponseUnmarshaller responseUnmarshaller = new ResponseUnmarshaller(store, xmlr);
      responseUnmarshaller.skip();
      if (!"result".equals(xmlr.getLocalName())) {
        throw new DespotifyException("Expected document root to be of type <result>");
      }

      Result result = responseUnmarshaller.unmarshallSearchResult();
      xmlr.close();
      return result;

    } catch (XMLStreamException e) {
      throw new DespotifyException(e);
    } catch (IOException e) {
      throw new DespotifyException(e);
    }


  }
View Full Code Here

Examples of se.despotify.exceptions.DespotifyException

    byte[] data = callback.getData("user playlists response");
    connection.close();
          
    if (data.length == 0) {
      throw new DespotifyException("received an empty response!");
    }

    String xml =
      "<?xml version=\"1.0\" encoding=\"utf-8\" ?><playlist>" +
      new String(data, Charset.forName("UTF-8")) +
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.