Package se.despotify.client.protocol.channel

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


        playlist.getRevision() + 1, playlist.getTracks().size(),
        playlist.getChecksum(), playlist.isCollaborative() ? 1 : 0
    );

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

    /* Create channel and buffer. */
    Channel channel  = new Channel("Change-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(playlist.getByteUUID()); /* 16 bytes */
    buffer.put((byte)0x00); // 0x00 for adding tracks, 0x02 for the rest?
    buffer.putInt(playlist.getRevision().intValue());
    buffer.putInt(playlist.getTracks().size());
    buffer.putInt(playlist.getChecksum().intValue()); /* -1: Create 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, value ? "set playlist collaborative flag true" : "set playlist collaborative flag false");

    /* Get response. */
    byte[] data = callback.getData(value ? "set playlist collaborative flag true response" : "set playlist collaborative flag false reponse");
    connection.close();


    xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><playlist>" +
            new String(data, Charset.forName("UTF-8")) +
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(connectionManager);
    }
    PlaylistContainer playlists = user.getPlaylists();

    playlists.getItems().add(playlist);

    if (position == null) {
      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.getByteUUID()) + "02",
            new Date().getTime() / 1000,
            user.getId(),
            // 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. */
    ManagedConnection connection = connectionManager.getManagedConnection();
    connection.getProtocol().sendPacket(PacketType.changePlaylist, buffer, "create playlist");

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

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

  public Boolean send(ConnectionManager connectionManager) 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.getByteUUID()); /// 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. */
    ManagedConnection connection = connectionManager.getManagedConnection();
    connection.getProtocol().sendPacket(PacketType.getPlaylist, buffer, "get playlist");

    /* Get data and inflate it. */
    data = callback.getData("get playlist response");
    connection.close();
   
    if (data.length == 0) {
      throw new ReceivedEmptyResponseException();
    }
View Full Code Here

  public Artist send(ConnectionManager connectionManager) throws DespotifyException {

    Date now = new Date();

    /* 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.getByteUUID());
    buffer.putInt(0); // unknown


    buffer.flip();

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

    /* Send packet. */
    ManagedConnection connection = connectionManager.getManagedConnection();
//    timeRequest.start();
    connection.getProtocol().sendPacket(PacketType.browse, buffer, "load artist");

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



View Full Code Here

  @Override
  public Album send(ConnectionManager connectionManager) 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.getByteUUID());
    buffer.putInt(0); // unknown


    buffer.flip();

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

    /* Send packet. */
    ManagedConnection connection = connectionManager.getManagedConnection();
    connection.getProtocol().sendPacket(PacketType.browse, buffer, "load album");

//    INFO  Protocol - sending load album, 26 bytes:
//        1   3    5  7   |9   11  13  15  |17  19  21  23  |25  27  29  31  |           1111111112222222222333
//          2   4   6   8 |  10  12  14  16|  18  20  22  24|  26  28  31  32| 12345678901234567890123456789012
//        ----------------|----------------|----------------|----------------|----------------------------------
//        30001700000202f8 df4ad52d449caca8 c6a25d2eca080000 0000             [0????????J?-D?????].??????]


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

    data = GZIP.inflate(data);

    if (log.isInfoEnabled()) {
View Full Code Here

  public Boolean send(Connection connection) throws DespotifyException {
    /* Data buffer. */
    byte[] data;

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

    /* Create channel and buffer. */
    Channel channel = new Channel("Image-Channel", Channel.Type.TYPE_IMAGE, callback);
    ByteBuffer buffer  = ByteBuffer.allocate(2 + 20);

    /* Append channel id and image hash. */
    buffer.putShort((short)channel.getId());
    buffer.put(image.getByteUUID());
    buffer.flip();

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

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

      /* Get data. */
    image.setBytes(callback.getData("load image response"));

    image.setLoaded(new Date());

    return true;

View Full Code Here

   * @param track    A {@link se.despotify.domain.media.Track} object identifying the track to be played.
   * @param listener event listener
   */
  public void play(Track track, PlaybackListener listener) {
    /* Create channel callback */
    ChannelCallback callback = new ChannelCallback();

    /* Send play request (token notify + AES key). */
    try {
      connection.getProtocol().sendPlayRequest(callback, track);
    }
    catch (DespotifyException e) {
      return;
    }

    /* Get AES key. */
    byte[] key = callback.getData("play response");

    /* Create channel player. */
    player = new ChannelPlayer(connection.getProtocol(), track, key, listener);
    player.volume(volume);

View Full Code Here

  public Boolean send(DespotifyManager connectionManager) throws DespotifyException {
    /* Data buffer. */
    byte[] data;

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

    /* Create channel and buffer. */
    Channel channel = new Channel("Image-Channel", Channel.Type.TYPE_IMAGE, callback);
    ByteBuffer buffer  = ByteBuffer.allocate(2 + 20);

    /* Append channel id and image hash. */
    buffer.putShort((short)channel.getId());
    buffer.put(image.getByteUUID());
    buffer.flip();

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

    /* Send packet. */
    ManagedConnection connection = connectionManager.getManagedConnection();
    connection.getProtocol().sendPacket(PacketType.image, buffer, "load image");
    connection.close();

      /* Get data. */
    image.setBytes(callback.getData("load image response"));

    image.setLoaded(new Date());

    return true;

View Full Code Here

  public Artist send(DespotifyManager connectionManager) throws DespotifyException {

    Date now = new Date();

    /* 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.getByteUUID());
    buffer.putInt(0); // unknown


    buffer.flip();

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

    /* Send packet. */
    ManagedConnection connection = connectionManager.getManagedConnection();
    connection.getProtocol().sendPacket(PacketType.browse, buffer, "load artist");

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


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

  @Override
  public Album send(DespotifyManager connectionManager) 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.getByteUUID());
    buffer.putInt(0); // unknown


    buffer.flip();

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

    /* Send packet. */
    ManagedConnection connection = connectionManager.getManagedConnection();
    connection.getProtocol().sendPacket(PacketType.browse, buffer, "load album");

//    INFO  Protocol - sending load album, 26 bytes:
//        1   3    5  7   |9   11  13  15  |17  19  21  23  |25  27  29  31  |           1111111112222222222333
//          2   4   6   8 |  10  12  14  16|  18  20  22  24|  26  28  31  32| 12345678901234567890123456789012
//        ----------------|----------------|----------------|----------------|----------------------------------
//        30001700000202f8 df4ad52d449caca8 c6a25d2eca080000 0000             [0????????J?-D?????].??????]


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

    if (log.isInfoEnabled()) {
      log.info("load album response, " + 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.