Package se.despotify.client.protocol.channel

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


    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 + tracks.length * 16); //+ ((type == BrowseType.artist || type == BrowseType.album)?4:0));

//    if(ids.size() > 1 && type != BrowseType.track){
//      throw new IllegalArgumentException("Only BrowserType.track accepts multiple ids.");
//    }

    /* Append channel id and type. */
    buffer.putShort((short) channel.getId());
    buffer.put((byte)BrowseType.track.getValue());

    /* Append (16 byte) ids. */
    for (Track track : tracks) {
      buffer.put(Arrays.copyOfRange(track.getUUID(), 0, 16));
View Full Code Here


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

    ChannelCallback callback = new ChannelCallback();

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

    buffer.putShort((short)channel.getId()); // channel id
    buffer.put(Hex.toBytes("00000000000000000000000000000000")); // uuid? not used
    buffer.put((byte)0x00); // unknown
    buffer.putInt(-1); // playlist history. -1: current. 0: changes since version 0, 1: since version 1, etc.
    buffer.putInt(0)// unknown
    buffer.putInt(-1); // unknown
View Full Code Here

    /* 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.getUUID()); /* 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. */
 
View Full Code Here

    /* 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.getUUID()); /* 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. */
 
View Full Code Here

      /* 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.getUUID());
    buffer.flip();

    /* Register channel. */
    Channel.register(channel);
View Full Code Here

 
  public void load(final String category, final String hash, final ChannelListener listener){
    /* Load in a separate thread because of piped streams. */
    new Thread(){
      public void run(){
        Channel channel = new Channel(
          "Cached-Substream-Channel", Channel.Type.TYPE_SUBSTREAM, null
        );
       
        listener.channelHeader(channel, null);
        listener.channelData(channel, load(category, hash));
View Full Code Here

  }

  /* Request ads. The response is GZIP compressed XML. */
  public void sendAdRequest(ChannelListener listener, int type) throws DespotifyException {
    /* Create channel and buffer. */
    Channel    channel = new Channel("Ad-Channel", Channel.Type.TYPE_AD, listener);
    ByteBuffer buffer  = ByteBuffer.allocate(2 + 1);

    /* Append channel id and ad type. */
    buffer.putShort((short)channel.getId());
    buffer.put((byte)type);
    buffer.flip();

    /* Register channel. */
    Channel.register(channel);
 
View Full Code Here

  }

  /* Request image using a 20 byte id. The response is a JPG. */
  public void sendImageRequest(ChannelListener listener, String id) throws DespotifyException {
    /* Create channel and buffer. */
    Channel    channel = new Channel("Image-Channel", Channel.Type.TYPE_IMAGE, listener);
    ByteBuffer buffer  = ByteBuffer.allocate(2 + 20);

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

    /* Register channel. */
    Channel.register(channel);
 
View Full Code Here

  }

  /* Search music. The response comes as GZIP compressed XML. */
  public void sendSearchQuery(ChannelListener listener, String query, int offset, int limit) throws DespotifyException {
    /* Create channel and buffer. */
    Channel    channel = new Channel("Search-Channel", Channel.Type.TYPE_SEARCH, listener);
    ByteBuffer buffer  = ByteBuffer.allocate(2 + 4 + 4 + 2 + 1 + query.getBytes().length);

    /* Check offset and limit. */
    if(offset < 0){
      throw new IllegalArgumentException("Offset needs to be >= 0");
    }
    else if((limit < 0 && limit != -1) || limit == 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(limit); /* Reply limit. */
    buffer.putShort((short)0x0000);
    buffer.put((byte)query.length());
    buffer.put(query.getBytes());
 
View Full Code Here

  }

  /* Request AES key for a track. */
  public void sendAesKeyRequest(ChannelListener listener, Track track) throws DespotifyException {
    /* Create channel and buffer. */
    Channel    channel = new Channel("AES-Key-Channel", Channel.Type.TYPE_AESKEY, listener);
    ByteBuffer buffer  = ByteBuffer.allocate(20 + 16 + 2 + 2);

    /* Request the AES key for this file by sending the file id and track id. */
    buffer.put(Hex.toBytes(track.getFiles().get(0))); /* 20 bytes */
    buffer.put(track.getUUID()); /* 16 bytes */
    buffer.putShort((short)0x0000);
    buffer.putShort((short)channel.getId());
    buffer.flip();

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

 
View Full Code Here

TOP

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

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.