Package se.despotify.client.protocol.channel

Examples of se.despotify.client.protocol.channel.ChannelCallback


  @Override
  public Boolean send(Protocol protocol) throws DespotifyException {

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

    /* Send browse request. */

    /* Create channel and buffer. */
    Channel channel = new Channel("Browse-Channel", Channel.Type.TYPE_BROWSE, callback);
    ByteBuffer buffer = ByteBuffer.allocate(2 + 1 + 16 + 4);


    buffer.putShort((short) channel.getId());
    buffer.put((byte) BrowseType.artist.getValue());
    buffer.put(artist.getUUID());
    buffer.putInt(0); // unknown


    buffer.flip();

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

    /* Send packet. */
    protocol.sendPacket(PacketType.browse, buffer, "load artist");


    /* Get data and inflate it. */
    byte[] data = GZIP.inflate(callback.getData("gzipped load artist response"));

    if (log.isInfoEnabled()) {
      log.info("load artist response, " + data.length + " uncompressed bytes:\n" + Hex.log(data, log));
    }

View Full Code Here


        protocol.getSession().getUsername(),
        collaborative ? 1 : 0
    );

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


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

    /* Append channel id, playlist id and some bytes... */
    buffer.putShort((short) channel.getId());
    buffer.put(requestedPlaylistUUID);
    buffer.put((byte) 0x02); // uuid playlist marker?
    buffer.putInt(0); // playlist revision?
    buffer.putInt(0); // playlist tracks size?
    buffer.putInt(-1); // playlist checksum? -1 when create uuid
    buffer.put((byte) 0x01); // normally means collaborate, not sure whats with this here
    buffer.put((byte) 0x03); // unknown
    buffer.put(xmlBytes);
    buffer.flip();

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

    /* Send packet. */
    protocol.sendPacket(PacketType.changePlaylist, buffer, "create playlist UUID");

    /* Get response. */
    byte[] data = callback.getData("create playlist uuid reponse");

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

View Full Code Here

  public Boolean send(Protocol protocol) throws DespotifyException {
    byte[] data;


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

    /* Create channel and buffer. */
    Channel channel = new Channel("Playlist-Channel", Channel.Type.TYPE_PLAYLIST, callback);
    ByteBuffer buffer = ByteBuffer.allocate(2 + 16 + 1 + 4 + 4 + 4 + 1);

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

    // todo if getTracks() == null..
    buffer.putInt(-1); // playlist history. -1: current. 0: changes since version 0, 1: since version 1, etc.

    buffer.putInt(0); // unknown
    buffer.putInt(-1); // checksum?
    buffer.put((byte) 0x01);
    buffer.flip();
    /* Register channel. */
    Channel.register(channel);

    /* Send packet. */
    protocol.sendPacket(PacketType.getPlaylist, buffer, "get playlist");

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

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

View Full Code Here

    if (playlist.isCollaborative() == null) {
      playlist.setCollaborative(false);
    }

    ChannelCallback callback = new ChannelCallback();

    /* Create channel and buffer. */
    Channel channel = new Channel("Create-Playlist-Channel", Channel.Type.TYPE_PLAYLIST, callback);

    if (user.getPlaylists() == null) {
      log.warn("user playlists not loaded yet! should it be? loading..");
      new LoadUserPlaylists(store, user).send(protocol);
    }
    PlaylistContainer playlists = user.getPlaylists();

    playlists.getItems().add(playlist);

    int position = playlists.getItems().size() - 1;

    String xml = String.format
        ("<change><ops><add><i>%s</i><items>%s</items></add></ops><time>%s</time><user>%s</user></change>" +
            "<version>%010d,%010d,%010d,%d</version>",
            // change
            position,
            Hex.toHex(playlist.getUUID()) + "02",
            new Date().getTime() / 1000,
            user.getName(),
            // version
            playlists.getRevision() + 1,         // new revision of user playlists
            playlists.getItems().size(),         // new size of user playlists
            playlists.calculateChecksum(),       // new checksum of user playlists
            playlist.isCollaborative() ? 1 : 0
        );

    byte[] xmlBytes = xml.getBytes();
    ByteBuffer buffer = ByteBuffer.allocate(2 + 16 + 1 + 4 + 4 + 4 + 1 + 1 + xmlBytes.length);

    buffer.putShort((short) channel.getId());
    buffer.put(Hex.toBytes("00000000000000000000000000000000")); // UUID? not used
    buffer.put((byte) 0x00); // type? not used
    buffer.putInt((int) playlists.getRevision()); // previous revision of user playlists
    buffer.putInt(position);
    buffer.putInt((int) playlists.getChecksum()); // previous checksum of user playlists

    buffer.put((byte) (playlist.isCollaborative() ? 0x01 : 0x00));
    buffer.put((byte) 0x03); // unknown
    buffer.put(xmlBytes);
    buffer.flip();

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

    /* Send packet. */
    protocol.sendPacket(PacketType.changePlaylist, buffer, "create playlist");

    /* Get response. */
    byte[] data = callback.getData("create playlist response");

    xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<playlists>\n" +
        new String(data, Charset.forName("UTF-8")) +
        "\n</playlists>";

View Full Code Here

        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);

    buffer.putShort((short) channel.getId());
    buffer.put(playlist.getUUID());
    buffer.put((byte) 0x02); // track UUID type tag

    buffer.putInt(playlist.getRevision().intValue());
    buffer.putInt(position); // uncertain
    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. */
    protocol.sendPacket(PacketType.changePlaylist, buffer, "remove track from playlist");

    /* Get response. */
    byte[] data = callback.getData("remove track from playlist ack");

    xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<playlist>\n" +
        new String(data, Charset.forName("UTF-8")) +
        "\n</playlist>";
    if (log.isDebugEnabled()) {
View Full Code Here

        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.getUUID());
    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. */
    protocol.sendPacket(PacketType.changePlaylist, buffer, "add track to playlist");

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

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

   * @return
   * @throws se.despotify.exceptions.DespotifyException
   */
  public boolean sendDelete(Protocol protocol, int position) throws DespotifyException {

    ChannelCallback callback = new ChannelCallback();

    /* Create channel and buffer. */
    Channel channel = new Channel("Create-Playlist-Channel", Channel.Type.TYPE_PLAYLIST, callback);

    PlaylistContainer playlists = user.getPlaylists();
View Full Code Here

  }

  public Boolean sendDestroy(Protocol protocol, int position) throws DespotifyException {


    ChannelCallback callback = new ChannelCallback();

    /* Create channel and buffer. */
    Channel channel = new Channel("Create-Playlist-Channel", Channel.Type.TYPE_PLAYLIST, callback);

    PlaylistContainer playlists = user.getPlaylists();


    String xml = String.format
        ("<change><ops><destroy/></ops><time>%s</time><user>%s</user></change>" +
            "<version>%010d,%010d,%010d,%d</version>",
            new Date().getTime() / 1000,
            user.getName(),
            // version
            playlist.getRevision() + 1,
            playlist.getTracks().size(),
            playlist.getChecksum(),
            playlist.isCollaborative() ? 1 : 0
        );

    byte[] xmlBytes = xml.getBytes();
    ByteBuffer buffer = ByteBuffer.allocate(2 + 16 + 1 + 4 + 4 + 4 + 1 + 1 + xmlBytes.length);

    //  3600bd00000000 000000000000000000 000000000000 00000426 0000001a a63f [6????????????????????????&??????]
    //  d3a7 00 03 3c636861 6e67653e3c6f7073 3e3c64656c3e3c69 3e32313c2f693e3c [????<change><ops><del><i>21</i><]


    buffer.putShort((short) channel.getId());
    buffer.put(playlist.getUUID());
    buffer.put((byte) 0x02); // playlist type UUID tag
    buffer.putInt((int) playlist.getRevision().longValue());
    buffer.putInt(playlist.getTracks().size());
    buffer.putInt((int) playlists.getChecksum());

    buffer.put((byte) (playlist.isCollaborative() ? 0x01 : 0x00));
    buffer.put((byte) 0x03); // unknown
    buffer.put(xmlBytes);
    buffer.flip();

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

    /* Send packet. */
    protocol.sendPacket(PacketType.changePlaylist, buffer, "destroy playlist");

    /* Get response. */
    byte[] data = callback.getData("destroy playlist response");

    xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<playlists>\n" +
        new String(data, Charset.forName("UTF-8")) +
        "\n</playlists>";

View Full Code Here

  @Override
  public Boolean send(Protocol protocol) throws DespotifyException {

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

    /* Send browse request. */

    /* Create channel and buffer. */
    Channel channel = new Channel("Browse-Channel", Channel.Type.TYPE_BROWSE, callback);
    ByteBuffer buffer = ByteBuffer.allocate(2 + 1 + 16 + 4);


    buffer.putShort((short) channel.getId());
    buffer.put((byte) BrowseType.album.getValue());
    buffer.put(album.getUUID());
    buffer.putInt(0); // unknown


    buffer.flip();

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

    /* Send packet. */
    protocol.sendPacket(PacketType.browse, buffer, "load album");


    /* Get data and inflate it. */
    byte[] data = GZIP.inflate(callback.getData("gzipped load album response"));

    if (log.isInfoEnabled()) {
      log.info("load album response, " + data.length + " uncompressed bytes:\n" + Hex.log(data, log));
    }

View Full Code Here

    this.maxResults = maxResults;
  }

  public Result send(Connection connection) throws DespotifyException {
    /* Create channel callback */
    ChannelCallback callback = new ChannelCallback();

    byte[] utf8Bytes = query.getBytes(Charset.forName("UTF8"));

    /* Create channel and buffer. */
    Channel channel = new Channel("Search-Channel", Channel.Type.TYPE_SEARCH, callback);
    ByteBuffer buffer = ByteBuffer.allocate(2 + 4 + 4 + 2 + 1 + utf8Bytes.length);

    /* Check offset and limit. */
    if (offset < 0) {
      throw new IllegalArgumentException("Offset needs to be >= 0");
    } else if ((maxResults < 0 && maxResults != -1) || maxResults == 0) {
      throw new IllegalArgumentException("Limit needs to be either -1 for no limit or > 0");
    }

    /* Append channel id, some values, query length and query. */
    buffer.putShort((short) channel.getId());
    buffer.putInt(offset); /* Result offset. */
    buffer.putInt(maxResults); /* Reply limit. */
    buffer.putShort((short) 0x0000);
    buffer.put((byte) utf8Bytes.length);
    buffer.put(utf8Bytes);
    buffer.flip();

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

    /* Send packet. */
    connection.getProtocol().sendPacket(PacketType.search, buffer, "search");

    /* Get data and inflate it. */
    byte[] data = GZIP.inflate(callback.getData("gzipped search response"));

    if (log.isInfoEnabled()) {
      log.info("received search response packet, " + data.length + " uncompressed bytes:\n" + Hex.log(data, log));
    }

View Full Code Here

TOP

Related Classes of se.despotify.client.protocol.channel.ChannelCallback

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.