@Test public void test() throws Exception { Artist dolly = store.getArtist(SpotifyURI.toHex("32vWCbZh0xZ4o9gkz4PsEU")); manager.send(new LoadArtist(store, dolly)); for (Artist artist : defaultArtists) { manager.send(new LoadArtist(store, artist)); } MemoryStore store = new MemoryStore(); Artist artist; artist = store.getArtist("d00d9e7b82894fb8851a109c82568eb5"); manager.send(new LoadArtist(store, artist)); artist.accept(new VisitorAdapter() { @Override public void visit(Artist artist) { assertEquals("d00d9e7b82894fb8851a109c82568eb5", artist.getId()); assertEquals("spotify:artist:6kACVPfCOnqzgfEF5ryl0x", artist.getSpotifyURI()); assertEquals("http: assertEquals("Johnny Cash", artist.getName()); } }); artist = store.getArtist("4f9873e19e5a4b4096c216c98bcdb010"); manager.send(new LoadArtist(store, artist)); artist.accept(new VisitorAdapter() { @Override public void visit(Artist artist) { assertEquals("4f9873e19e5a4b4096c216c98bcdb010", artist.getId()); assertEquals("spotify:artist:2qc41rNTtdLK0tV3mJn2Pm", artist.getSpotifyURI()); assertEquals("http: assertEquals("Ryan Adams", artist.getName()); } }); artist = store.getArtist("db614c7060fc47baa7be732d88ae446d"); manager.send(new LoadArtist(store, artist)); artist.accept(new VisitorAdapter() { @Override public void visit(Artist artist) { assertEquals("db614c7060fc47baa7be732d88ae446d", artist.getId()); assertEquals("spotify:artist:6FXMGgJwohJLUSr5nVlf9X", artist.getSpotifyURI()); assertEquals("http: assertEquals("Massive Attack", artist.getName()); } }); artist = store.getArtist("f4d5d82d09124feda0633a2671f8c81a"); manager.send(new LoadArtist(store, artist)); artist.accept(new VisitorAdapter() { @Override public void visit(Artist artist) { assertEquals("f4d5d82d09124feda0633a2671f8c81a", artist.getId()); assertEquals("spotify:artist:7rZR0ugcLEhNrFYOrUtZii", artist.getSpotifyURI()); assertEquals("http: assertEquals("Miles Davis", artist.getName()); } }); artist = store.getArtist("f6150726a8e94c89a7cf336d3f72be9c"); manager.send(new LoadArtist(store, artist)); artist.accept(new VisitorAdapter() { @Override public void visit(Artist artist) { assertEquals("f6150726a8e94c89a7cf336d3f72be9c", artist.getId()); assertEquals("spotify:artist:7ulIMfVKiXh8ecEpAVHIAY", artist.getSpotifyURI()); assertEquals("http: assertEquals("Electrelane", artist.getName()); } }); }
@Override public Artist send(DespotifyManager connectionManager) throws DespotifyException { Date now = new Date(); ChannelCallback callback = new ChannelCallback(); 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); buffer.flip(); Channel.register(channel); ManagedConnection connection = connectionManager.getManagedConnection(); connection.getProtocol().sendPacket(PacketType.browse, buffer, "load artist"); 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)); } if (data.length == 0) { if ("Various Artists".equals(artist.getName())) { artist.setLoaded(now); } else { throw new ReceivedEmptyResponseException("This might be a real problem while communicting with Spotify, it can also be that you tried to load an artist representing 'Various Artists' Spotify will return an empty result. The official client does not seem to ever load such an artist."); } } else { data = Arrays.copyOfRange(data, 0, data.length - 1); try { XMLStreamReader xmlr = ResponseUnmarshaller.createReader(new InputStreamReader(new ByteArrayInputStream(data), Charset.forName("UTF-8"))); ResponseUnmarshaller responseUnmarshaller = new ResponseUnmarshaller(store, xmlr); responseUnmarshaller.skip(); if (!"artist".equals(xmlr.getLocalName())) { throw new DespotifyException("Expected document root to be of type <artist>"); } Artist artist = responseUnmarshaller.unmarshallArtist(new Date()); if (!this.artist.equals(artist)) { throw new DespotifyException("Artist in response has different UUID than the requested artist!"); } } catch (XMLStreamException e) { throw new DespotifyException(e); } } return (Artist) store.persist(artist); }
LoadArtist extends Command<Artist> { @Override public Artist send(DespotifyManager connectionManager) throws DespotifyException { Date now = new Date(); ChannelCallback callback = new ChannelCallback(); 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); buffer.flip(); Channel.register(channel); ManagedConnection connection = connectionManager.getManagedConnection(); connection.getProtocol().sendPacket(PacketType.browse, buffer, "load artist"); 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)); } if (data.length == 0) { if ("Various Artists".equals(artist.getName())) { artist.setLoaded(now); } else { throw new ReceivedEmptyResponseException("This might be a real problem while communicting with Spotify, it can also be that you tried to load an artist representing 'Various Artists' Spotify will return an empty result. The official client does not seem to ever load such an artist."); } } else { data = Arrays.copyOfRange(data, 0, data.length - 1); try { XMLStreamReader xmlr = ResponseUnmarshaller.createReader(new InputStreamReader(new ByteArrayInputStream(data), Charset.forName("UTF-8"))); ResponseUnmarshaller responseUnmarshaller = new ResponseUnmarshaller(store, xmlr); responseUnmarshaller.skip(); if (!"artist".equals(xmlr.getLocalName())) { throw new DespotifyException("Expected document root to be of type <artist>"); } Artist artist = responseUnmarshaller.unmarshallArtist(new Date()); if (!this.artist.equals(artist)) { throw new DespotifyException("Artist in response has different UUID than the requested artist!"); } } catch (XMLStreamException e) { throw new DespotifyException(e); } } return (Artist) store.persist(artist); } }
LoadArtist extends Command<Artist> { @Override public Artist send(DespotifyManager connectionManager) throws DespotifyException { Date now = new Date(); ChannelCallback callback = new ChannelCallback(); 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); buffer.flip(); Channel.register(channel); ManagedConnection connection = connectionManager.getManagedConnection(); connection.getProtocol().sendPacket(PacketType.browse, buffer, "load artist"); 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)); } if (data.length == 0) { if ("Various Artists".equals(artist.getName())) { artist.setLoaded(now); } else { throw new ReceivedEmptyResponseException("This might be a real problem while communicting with Spotify, it can also be that you tried to load an artist representing 'Various Artists' Spotify will return an empty result. The official client does not seem to ever load such an artist."); } } else { data = Arrays.copyOfRange(data, 0, data.length - 1); try { XMLStreamReader xmlr = ResponseUnmarshaller.createReader(new InputStreamReader(new ByteArrayInputStream(data), Charset.forName("UTF-8"))); ResponseUnmarshaller responseUnmarshaller = new ResponseUnmarshaller(store, xmlr); responseUnmarshaller.skip(); if (!"artist".equals(xmlr.getLocalName())) { throw new DespotifyException("Expected document root to be of type <artist>"); } Artist artist = responseUnmarshaller.unmarshallArtist(new Date()); if (!this.artist.equals(artist)) { throw new DespotifyException("Artist in response has different UUID than the requested artist!"); } } catch (XMLStreamException e) { throw new DespotifyException(e); } } return (Artist) store.persist(artist); } LoadArtist(Store store, Artist artist); }
LoadArtist extends Command<Artist> { @Override public Artist send(DespotifyManager connectionManager) throws DespotifyException { Date now = new Date(); ChannelCallback callback = new ChannelCallback(); 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); buffer.flip(); Channel.register(channel); ManagedConnection connection = connectionManager.getManagedConnection(); connection.getProtocol().sendPacket(PacketType.browse, buffer, "load artist"); 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)); } if (data.length == 0) { if ("Various Artists".equals(artist.getName())) { artist.setLoaded(now); } else { throw new ReceivedEmptyResponseException("This might be a real problem while communicting with Spotify, it can also be that you tried to load an artist representing 'Various Artists' Spotify will return an empty result. The official client does not seem to ever load such an artist."); } } else { data = Arrays.copyOfRange(data, 0, data.length - 1); try { XMLStreamReader xmlr = ResponseUnmarshaller.createReader(new InputStreamReader(new ByteArrayInputStream(data), Charset.forName("UTF-8"))); ResponseUnmarshaller responseUnmarshaller = new ResponseUnmarshaller(store, xmlr); responseUnmarshaller.skip(); if (!"artist".equals(xmlr.getLocalName())) { throw new DespotifyException("Expected document root to be of type <artist>"); } Artist artist = responseUnmarshaller.unmarshallArtist(new Date()); if (!this.artist.equals(artist)) { throw new DespotifyException("Artist in response has different UUID than the requested artist!"); } } catch (XMLStreamException e) { throw new DespotifyException(e); } } return (Artist) store.persist(artist); } LoadArtist(Store store, Artist artist); @Override Artist send(DespotifyManager connectionManager); }
LoadArtist extends Command<Artist> { @Override public Artist send(DespotifyManager connectionManager) throws DespotifyException { Date now = new Date(); ChannelCallback callback = new ChannelCallback(); 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); buffer.flip(); Channel.register(channel); ManagedConnection connection = connectionManager.getManagedConnection(); connection.getProtocol().sendPacket(PacketType.browse, buffer, "load artist"); 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)); } if (data.length == 0) { if ("Various Artists".equals(artist.getName())) { artist.setLoaded(now); } else { throw new ReceivedEmptyResponseException("This might be a real problem while communicting with Spotify, it can also be that you tried to load an artist representing 'Various Artists' Spotify will return an empty result. The official client does not seem to ever load such an artist."); } } else { data = Arrays.copyOfRange(data, 0, data.length - 1); try { XMLStreamReader xmlr = ResponseUnmarshaller.createReader(new InputStreamReader(new ByteArrayInputStream(data), Charset.forName("UTF-8"))); ResponseUnmarshaller responseUnmarshaller = new ResponseUnmarshaller(store, xmlr); responseUnmarshaller.skip(); if (!"artist".equals(xmlr.getLocalName())) { throw new DespotifyException("Expected document root to be of type <artist>"); } Artist artist = responseUnmarshaller.unmarshallArtist(new Date()); if (!this.artist.equals(artist)) { throw new DespotifyException("Artist in response has different UUID than the requested artist!"); } } catch (XMLStreamException e) { throw new DespotifyException(e); } } return (Artist) store.persist(artist); } LoadArtist(Store store, Artist artist); @Override Artist send(DespotifyManager connectionManager);  }