@Test public void testGetPlaylists() throws Exception { manager.send(new LoadUserPlaylists(store, user)); PlaylistContainer playlists = user.getPlaylists(); assertNotNull(playlists); assertEquals(username, playlists.getId()); for (Playlist playlist : playlists) { assertEquals(16, playlist.getByteUUID().length); testGetPlaylist(playlist); } }
@Override public Boolean send(DespotifyManager connectionManager) 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()); buffer.put(Hex.toBytes("00000000000000000000000000000000")); buffer.put((byte)0x00); buffer.putInt(-1); buffer.putInt(0); buffer.putInt(-1); buffer.put((byte)0x00); buffer.flip(); Channel.register(channel); ManagedConnection connection = connectionManager.getManagedConnection(); connection.getProtocol().sendPacket(PacketType.getPlaylist, buffer, "request list of user playlists"); 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")) + "</playlist>"; if (log.isDebugEnabled()) { log.debug(xml); } 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()); return true; } else { throw new RuntimeException("Unknown server response:\n" + xml); } }
LoadUserPlaylists extends Command<Boolean> { @Override public Boolean send(DespotifyManager connectionManager) 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()); buffer.put(Hex.toBytes("00000000000000000000000000000000")); buffer.put((byte)0x00); buffer.putInt(-1); buffer.putInt(0); buffer.putInt(-1); buffer.put((byte)0x00); buffer.flip(); Channel.register(channel); ManagedConnection connection = connectionManager.getManagedConnection(); connection.getProtocol().sendPacket(PacketType.getPlaylist, buffer, "request list of user playlists"); 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")) + "</playlist>"; if (log.isDebugEnabled()) { log.debug(xml); } 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()); return true; } else { throw new RuntimeException("Unknown server response:\n" + xml); } } }
LoadUserPlaylists extends Command<Boolean> { @Override public Boolean send(DespotifyManager connectionManager) 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()); buffer.put(Hex.toBytes("00000000000000000000000000000000")); buffer.put((byte)0x00); buffer.putInt(-1); buffer.putInt(0); buffer.putInt(-1); buffer.put((byte)0x00); buffer.flip(); Channel.register(channel); ManagedConnection connection = connectionManager.getManagedConnection(); connection.getProtocol().sendPacket(PacketType.getPlaylist, buffer, "request list of user playlists"); 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")) + "</playlist>"; if (log.isDebugEnabled()) { log.debug(xml); } 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()); return true; } else { throw new RuntimeException("Unknown server response:\n" + xml); } } LoadUserPlaylists(Store store, User user); }
LoadUserPlaylists extends Command<Boolean> { @Override public Boolean send(DespotifyManager connectionManager) 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()); buffer.put(Hex.toBytes("00000000000000000000000000000000")); buffer.put((byte)0x00); buffer.putInt(-1); buffer.putInt(0); buffer.putInt(-1); buffer.put((byte)0x00); buffer.flip(); Channel.register(channel); ManagedConnection connection = connectionManager.getManagedConnection(); connection.getProtocol().sendPacket(PacketType.getPlaylist, buffer, "request list of user playlists"); 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")) + "</playlist>"; if (log.isDebugEnabled()) { log.debug(xml); } 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()); return true; } else { throw new RuntimeException("Unknown server response:\n" + xml); } } LoadUserPlaylists(Store store, User user); @Override Boolean send(DespotifyManager connectionManager); }
LoadUserPlaylists extends Command<Boolean> { @Override public Boolean send(DespotifyManager connectionManager) 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()); buffer.put(Hex.toBytes("00000000000000000000000000000000")); buffer.put((byte)0x00); buffer.putInt(-1); buffer.putInt(0); buffer.putInt(-1); buffer.put((byte)0x00); buffer.flip(); Channel.register(channel); ManagedConnection connection = connectionManager.getManagedConnection(); connection.getProtocol().sendPacket(PacketType.getPlaylist, buffer, "request list of user playlists"); 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")) + "</playlist>"; if (log.isDebugEnabled()) { log.debug(xml); } 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()); return true; } else { throw new RuntimeException("Unknown server response:\n" + xml); } } LoadUserPlaylists(Store store, User user); @Override Boolean send(DespotifyManager connectionManager);  }