@Test public void test() throws Exception { Playlist playlist; playlist = store.getPlaylist(SpotifyURI.toHex("6wvPFkLGKOVl1v3qRJD6HX")); manager.send(new LoadPlaylist(store, playlist)); assertEquals("despotify apriori", playlist.getName()); assertEquals(7l, playlist.getRevision().longValue()); assertEquals(3794544626l, playlist.getChecksum().longValue()); assertEquals(3794544626l, playlist.calculateChecksum()); assertEquals("kent.finell", playlist.getAuthor()); assertFalse(playlist.isCollaborative()); assertEquals("d65f21be4a744a88ea67d8a83c7a2eb5", playlist.getId()); assertEquals(5, playlist.getTracks().size()); assertEquals("93f98ea75b4748f797668485a3d01bd0", playlist.getTracks().get(0).getId()); assertEquals("spotify:track:4vdV2Eua6RkUoUM51jdH56", playlist.getTracks().get(0).getSpotifyURI()); assertEquals("http: assertNull(playlist.getTracks().get(0).getTitle()); assertNull(playlist.getTracks().get(0).getCover()); assertNull(playlist.getTracks().get(0).getFiles()); assertNull(playlist.getTracks().get(0).getLength()); assertNull(playlist.getTracks().get(0).getPopularity()); assertNull(playlist.getTracks().get(0).getTrackNumber()); assertNull(playlist.getTracks().get(0).getYear()); assertEquals("cf2cd530980e450d855977ba0a80ec6e", playlist.getTracks().get(1).getId()); assertEquals("spotify:track:6iVTOPCmpABvG9jDZ2JozY", playlist.getTracks().get(1).getSpotifyURI()); assertEquals("http: assertNull(playlist.getTracks().get(1).getTitle()); assertNull(playlist.getTracks().get(1).getCover()); assertNull(playlist.getTracks().get(1).getFiles()); assertNull(playlist.getTracks().get(1).getLength()); assertNull(playlist.getTracks().get(1).getPopularity()); assertNull(playlist.getTracks().get(1).getTrackNumber()); assertNull(playlist.getTracks().get(1).getYear()); assertEquals("fc1f1b5860f04a739971fcad9c1cd634", playlist.getTracks().get(2).getId()); assertEquals("spotify:track:7FKhuZtIPchBVNIhFnNL5W", playlist.getTracks().get(2).getSpotifyURI()); assertEquals("http: assertNull(playlist.getTracks().get(2).getTitle()); assertNull(playlist.getTracks().get(2).getCover()); assertNull(playlist.getTracks().get(2).getFiles()); assertNull(playlist.getTracks().get(2).getLength()); assertNull(playlist.getTracks().get(2).getPopularity()); assertNull(playlist.getTracks().get(2).getTrackNumber()); assertNull(playlist.getTracks().get(2).getYear()); assertEquals("7093f50c9ecf428eb780348c076f9f7f", playlist.getTracks().get(3).getId()); assertEquals("spotify:track:3qqKWUVfiLMrNPacFRzTzh", playlist.getTracks().get(3).getSpotifyURI()); assertEquals("http: assertNull(playlist.getTracks().get(3).getTitle()); assertNull(playlist.getTracks().get(3).getCover()); assertNull(playlist.getTracks().get(3).getFiles()); assertNull(playlist.getTracks().get(3).getLength()); assertNull(playlist.getTracks().get(3).getPopularity()); assertNull(playlist.getTracks().get(3).getTrackNumber()); assertNull(playlist.getTracks().get(3).getYear()); assertEquals("48daf12f96f84793a526b579aa4d1f66", playlist.getTracks().get(4).getId()); assertEquals("spotify:track:2dtvgPd3vsotKXtGk4dWlg", playlist.getTracks().get(4).getSpotifyURI()); assertEquals("http: assertNull(playlist.getTracks().get(4).getTitle()); assertNull(playlist.getTracks().get(4).getCover()); assertNull(playlist.getTracks().get(4).getFiles()); assertNull(playlist.getTracks().get(4).getLength()); assertNull(playlist.getTracks().get(4).getPopularity()); assertNull(playlist.getTracks().get(4).getTrackNumber()); assertNull(playlist.getTracks().get(4).getYear()); }
@Override public Boolean send(Connection connection) throws DespotifyException { byte[] data; 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(playlist.getByteUUID()); buffer.put((byte) 0x02); buffer.putInt(-1); buffer.putInt(0); buffer.putInt(-1); buffer.put((byte) 0x01); buffer.flip(); Channel.register(channel); connection.getProtocol().sendPacket(PacketType.getPlaylist, buffer, "get playlist"); data = callback.getData("get playlist response"); 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>"; XMLElement playlistElement = XML.load(xml); if (log.isDebugEnabled()) { log.debug(xml); } Playlist.fromXMLElement(playlistElement, store, playlist); if (playlist.getTracks() != null && playlist.getChecksum() != playlist.calculateChecksum()) { throw new ChecksumException(playlist.getChecksum(), playlist.calculateChecksum()); } playlist.setLoaded(new Date()); return true; }
LoadPlaylist extends Command<Boolean> { @Override public Boolean send(Connection connection) throws DespotifyException { byte[] data; 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(playlist.getByteUUID()); buffer.put((byte) 0x02); buffer.putInt(-1); buffer.putInt(0); buffer.putInt(-1); buffer.put((byte) 0x01); buffer.flip(); Channel.register(channel); connection.getProtocol().sendPacket(PacketType.getPlaylist, buffer, "get playlist"); data = callback.getData("get playlist response"); 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>"; XMLElement playlistElement = XML.load(xml); if (log.isDebugEnabled()) { log.debug(xml); } Playlist.fromXMLElement(playlistElement, store, playlist); if (playlist.getTracks() != null && playlist.getChecksum() != playlist.calculateChecksum()) { throw new ChecksumException(playlist.getChecksum(), playlist.calculateChecksum()); } playlist.setLoaded(new Date()); return true; } }
LoadPlaylist extends Command<Boolean> { @Override public Boolean send(Connection connection) throws DespotifyException { byte[] data; 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(playlist.getByteUUID()); buffer.put((byte) 0x02); buffer.putInt(-1); buffer.putInt(0); buffer.putInt(-1); buffer.put((byte) 0x01); buffer.flip(); Channel.register(channel); connection.getProtocol().sendPacket(PacketType.getPlaylist, buffer, "get playlist"); data = callback.getData("get playlist response"); 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>"; XMLElement playlistElement = XML.load(xml); if (log.isDebugEnabled()) { log.debug(xml); } Playlist.fromXMLElement(playlistElement, store, playlist); if (playlist.getTracks() != null && playlist.getChecksum() != playlist.calculateChecksum()) { throw new ChecksumException(playlist.getChecksum(), playlist.calculateChecksum()); } playlist.setLoaded(new Date()); return true; } LoadPlaylist(Store store, Playlist playlist); }
LoadPlaylist extends Command<Boolean> { @Override public Boolean send(Connection connection) throws DespotifyException { byte[] data; 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(playlist.getByteUUID()); buffer.put((byte) 0x02); buffer.putInt(-1); buffer.putInt(0); buffer.putInt(-1); buffer.put((byte) 0x01); buffer.flip(); Channel.register(channel); connection.getProtocol().sendPacket(PacketType.getPlaylist, buffer, "get playlist"); data = callback.getData("get playlist response"); 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>"; XMLElement playlistElement = XML.load(xml); if (log.isDebugEnabled()) { log.debug(xml); } Playlist.fromXMLElement(playlistElement, store, playlist); if (playlist.getTracks() != null && playlist.getChecksum() != playlist.calculateChecksum()) { throw new ChecksumException(playlist.getChecksum(), playlist.calculateChecksum()); } playlist.setLoaded(new Date()); return true; } LoadPlaylist(Store store, Playlist playlist); @Override Boolean send(Connection connection); }
LoadPlaylist extends Command<Boolean> { @Override public Boolean send(Connection connection) throws DespotifyException { byte[] data; 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(playlist.getByteUUID()); buffer.put((byte) 0x02); buffer.putInt(-1); buffer.putInt(0); buffer.putInt(-1); buffer.put((byte) 0x01); buffer.flip(); Channel.register(channel); connection.getProtocol().sendPacket(PacketType.getPlaylist, buffer, "get playlist"); data = callback.getData("get playlist response"); 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>"; XMLElement playlistElement = XML.load(xml); if (log.isDebugEnabled()) { log.debug(xml); } Playlist.fromXMLElement(playlistElement, store, playlist); if (playlist.getTracks() != null && playlist.getChecksum() != playlist.calculateChecksum()) { throw new ChecksumException(playlist.getChecksum(), playlist.calculateChecksum()); } playlist.setLoaded(new Date()); return true; } LoadPlaylist(Store store, Playlist playlist); @Override Boolean send(Connection connection);  }