Package se.despotify.domain.media

Examples of se.despotify.domain.media.PlaylistContainer


    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><del><i>%s</i><k>%s</k></del></ops><time>%s</time><user>%s</user></change>" +
            "<version>%010d,%010d,%010d,%d</version>",
            // change
            position,
            1, // unknown
            new Date().getTime() / 1000,
            user.getName(),
            // version
            playlists.getRevision() + 1,
            playlists.getItems().size(),
            playlists.getChecksum(),
            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());
    buffer.putInt(playlists.getItems().size() + 1);
    buffer.putInt((int) playlists.getChecksum());

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


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

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

    Playlist.fromXMLElement(response, store, playlist);

    if (response.hasChild("next-change")) {
      return true;
    } else {
      playlists.getItems().add(position - 1, playlist);
      throw new RuntimeException("Unknown server response:\n" + xml);
    }
  }
View Full Code Here

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

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

    final XMLElement versionParentElement;
    if (response.hasChild("confirm")) {
      versionParentElement = response.getChild("confirm");
    } else if (response.hasChild("")) {
      versionParentElement = response;
    } else {
      throw new RuntimeException("Unknown server response:\n" + xml);
    }

    // <version>0000000007,0000000002,3701476273,0</version>
    String[] versionTagValues = versionParentElement.getChildText("version").split(",", 4);

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

    if (playlists.getItems().size() != Long.parseLong(versionTagValues[1])) {
      throw new RuntimeException("Size missmatch");
    }

    if (playlists.calculateChecksum() != playlists.getChecksum()) {
      throw new ChecksumException(playlists.calculateChecksum(), playlists.getChecksum());
    }
    if (playlist.isCollaborative() != (Integer.parseInt(versionTagValues[3]) == 1)) {
      throw new RuntimeException("Collaborative flag missmatch");
    }

View Full Code Here

    }

    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;
View Full Code Here

  @Test
  public void testGetPlaylists() throws Exception {

    new LoadUserPlaylists(store, user).send(connection.getProtocol());
    PlaylistContainer playlists  = user.getPlaylists();
    assertNotNull(playlists);
    assertEquals(username, playlists.getAuthor());
    for (Playlist playlist : playlists) {     
      assertEquals(16, playlist.getUUID().length);
      testGetPlaylist(playlist);
    }
View Full Code Here

  @Test
  public void testAddPlaylistsToUser() {

    User user = new User();
    user.setPlaylists(new PlaylistContainer());

    assertEquals(1, user.getPlaylists().calculateChecksum());

    /*
    3600cd0000566796 2d4c1764d12cd68b 86a4394916020000 000000000000ffff [6????Vg?-L?d?,????9I????????????]
View Full Code Here

    }

    XMLElement playlistElement = XML.load(xml);

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

    if (playlistElement.hasChild("next-change")) {
      user.getPlaylists().setLoaded(new Date());
View Full Code Here

    if (user.getPlaylists() == null) {
      log.warn("user playlists not loaded yet! should it be? loading..");
      new LoadUserPlaylists(store, user).send(connection);
    }
    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.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. */
    connection.getProtocol().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>";

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

    final XMLElement versionParentElement;
    if (response.hasChild("confirm")) {
      versionParentElement = response.getChild("confirm");
    } else if (response.hasChild("")) {
      versionParentElement = response;
    } else {
      throw new RuntimeException("Unknown server response:\n" + xml);
    }

    // <version>0000000007,0000000002,3701476273,0</version>
    String[] versionTagValues = versionParentElement.getChildText("version").split(",", 4);

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

    if (playlists.getItems().size() != Long.parseLong(versionTagValues[1])) {
      throw new RuntimeException("Size missmatch");
    }

    if (playlists.calculateChecksum() != playlists.getChecksum()) {
      throw new ChecksumException(playlists.calculateChecksum(), playlists.getChecksum());
    }
    if (playlist.isCollaborative() != (Integer.parseInt(versionTagValues[3]) == 1)) {
      throw new RuntimeException("Collaborative flag missmatch");
    }

View Full Code Here

    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><del><i>%s</i><k>%s</k></del></ops><time>%s</time><user>%s</user></change>" +
            "<version>%010d,%010d,%010d,%d</version>",
            // change
            position,
            1, // number of playlists to delete with start at attribute "position"
            new Date().getTime() / 1000,
            user.getId(),
            // version
            playlists.getRevision() + 1,
            playlists.getItems().size(),
            playlists.getChecksum(),
            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());
    buffer.putInt(playlists.getItems().size() + 1);
    buffer.putInt((int) playlists.getChecksum());

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

    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.getId(),
            // 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.getByteUUID());
    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>";

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

    Playlist.fromXMLElement(response, store, playlist);

    if (response.hasChild("next-change")) {
      return true;
    } else {
      playlists.getItems().add(position - 1, playlist);
      throw new RuntimeException("Unknown server response:\n" + xml);
    }
  }
View Full Code Here

TOP

Related Classes of se.despotify.domain.media.PlaylistContainer

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.