Package se.despotify.domain.media

Examples of se.despotify.domain.media.Playlist


  }

  @Override
  public Playlist send(Protocol protocol) throws DespotifyException {
    byte[] playlistUUID = new ReserveRandomPlaylistUUID(store, user, playlistName, collaborative).send(protocol);
    Playlist playlist = store.getPlaylist(playlistUUID);
    playlist.setAuthor(user.getName());
    playlist.setName(playlistName);
    playlist.setUUID(playlistUUID);
    if (new CreatePlaylistWithReservedUUID(store, user, playlist).send(protocol)) {
      return playlist;
    } else {
      throw new DespotifyException();
    }
View Full Code Here



    new LoadUserPlaylists(store, user).send(connection.getProtocol());
    int playlistsFromStart = user.getPlaylists().getItems().size();

    Playlist playlist = new CreatePlaylist(store, user, playlistName, false).send(connection.getProtocol());

    assertEquals(playlistsFromStart + 1, user.getPlaylists().getItems().size());

    long[] checksums = new long[]{
        1461913864l,
        823267316l,
        2339641349l,
        1904484306l,
        3794544626l,
    };

    for (int i = 0; i < checksums.length; i++) {
      log.info("\n\n\n\n\n\n\n           ADD TRACK " + i + "\n\n\n\n\n\n\n\n\n");
      new AddTrackToPlaylist(store, user, playlist, defaultTracks[i], null).send(connection.getProtocol());
      assertEquals(checksums[i], playlist.calculateChecksum());
      assertEquals(checksums[i], playlist.getChecksum().longValue());
      assertEquals(i + 1, playlist.getTracks().size());
      assertEquals(defaultTracks[i], playlist.getTracks().get(i));

      // todo get list using alternative connection and assert the same

    }

    for (int i = checksums.length; i > 1; i--) {
      log.info("\n\n\n\n\n\n\n           REMOVE TRACK " + i + "\n\n\n\n\n\n\n\n\n");
      new RemoveTrackFromPlaylist(store, user, playlist, i).send(connection.getProtocol());
      assertEquals(checksums[i - 2], playlist.calculateChecksum());
      assertEquals(checksums[i - 2], playlist.getChecksum().longValue());
      assertEquals(i - 1, playlist.getTracks().size());

      // todo get list using alternative connection and assert the same

    }
View Full Code Here

    String playlistName = randomPlaylistName();

    new LoadUserPlaylists(store, user).send(connection.getProtocol());
    int originalSize = user.getPlaylists().getItems().size();

    Playlist playlist = new CreatePlaylist(store, user, playlistName, false).send(connection.getProtocol());
    assertEquals(originalSize + 1, user.getPlaylists().getItems().size());
    assertTrue(user.getPlaylists().getItems().contains(playlist));

    new RemovePlaylistFromUser(store, user, playlist).send(connection.getProtocol());
    assertEquals(originalSize, user.getPlaylists().getItems().size());
    assertFalse(user.getPlaylists().getItems().contains(playlist));

    reset();

    new LoadUserPlaylists(store, user).send(connection.getProtocol());
    assertEquals(originalSize, user.getPlaylists().getItems().size());
    for (Playlist playlist2 : user.getPlaylists()) {
      assertNotSame(playlist.getUUID(), playlist2.getUUID());
    }
   

    // todo can we still load it?
View Full Code Here

    String playlistName = randomPlaylistName();
   
    log.info("\n\n\n\n\n\n\n           create playlist named "+playlistName+"\n\n\n\n\n\n\n\n\n");

    Playlist originalPlaylist = new CreatePlaylist(new MemoryStore(), user, playlistName, false).send(connection.getProtocol());


    log.info("\n\n\n\n\n\n\n           load playlist with UUID "+Hex.toHex(originalPlaylist.getUUID())+"\n\n             spotify:user:"+ username + ":playlist:" + SpotifyURI.toURI(Hex.toHex(originalPlaylist.getUUID())) +"\n\n\n\n\n\n\n\n\n");

    // brand new store to make sure we dont pick something up from the cache.
    MemoryStore store = new MemoryStore();
    Playlist loadedPlaylist = store.getPlaylist(originalPlaylist.getUUID());
    new LoadPlaylist(store, loadedPlaylist).send(connection.getProtocol());

    assertTrue("different stores means different instances", loadedPlaylist != originalPlaylist);  
    assertEquals(loadedPlaylist.getChecksum().longValue(), loadedPlaylist.calculateChecksum());
    assertEquals(originalPlaylist.getHexUUID(), loadedPlaylist.getHexUUID());
    // todo assert the rest

  }
View Full Code Here


  @Test
  public void test() throws Exception {

    Playlist playlist;

    try {
      // this playlist contains a bad checksum
      playlist = (Playlist) SpotifyURL.browse("spotify:user:kent.finell:playlist:6Odybr7gR4L9LwO8dBgBwS", store, connection);
      fail("Bad checksum in playlist, should not be valid.");
    } catch (Exception e) {
      e.printStackTrace();
    }


//    MediaTestCaseGenerator.createEqualsTest((Playlist)SpotifyURL.browse("spotify:user:kent.finell:playlist:6wvPFkLGKOVl1v3qRJD6HX", connection));

    playlist = store.getPlaylist(SpotifyURI.toHex("6wvPFkLGKOVl1v3qRJD6HX"));
    new LoadPlaylist(store, playlist).send(connection.getProtocol());

    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.getHexUUID());
    assertEquals(5, playlist.getTracks().size());

    assertEquals("93f98ea75b4748f797668485a3d01bd0", playlist.getTracks().get(0).getHexUUID());
    assertEquals("spotify:track:4vdV2Eua6RkUoUM51jdH56", playlist.getTracks().get(0).getSpotifyURL());
    assertEquals("http://open.spotify.com/track/4vdV2Eua6RkUoUM51jdH56", playlist.getTracks().get(0).getHttpURL());
    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).getHexUUID());
    assertEquals("spotify:track:6iVTOPCmpABvG9jDZ2JozY", playlist.getTracks().get(1).getSpotifyURL());
    assertEquals("http://open.spotify.com/track/6iVTOPCmpABvG9jDZ2JozY", playlist.getTracks().get(1).getHttpURL());
    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).getHexUUID());
    assertEquals("spotify:track:7FKhuZtIPchBVNIhFnNL5W", playlist.getTracks().get(2).getSpotifyURL());
    assertEquals("http://open.spotify.com/track/7FKhuZtIPchBVNIhFnNL5W", playlist.getTracks().get(2).getHttpURL());
    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).getHexUUID());
    assertEquals("spotify:track:3qqKWUVfiLMrNPacFRzTzh", playlist.getTracks().get(3).getSpotifyURL());
    assertEquals("http://open.spotify.com/track/3qqKWUVfiLMrNPacFRzTzh", playlist.getTracks().get(3).getHttpURL());
    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).getHexUUID());
    assertEquals("spotify:track:2dtvgPd3vsotKXtGk4dWlg", playlist.getTracks().get(4).getSpotifyURL());
    assertEquals("http://open.spotify.com/track/2dtvgPd3vsotKXtGk4dWlg", playlist.getTracks().get(4).getHttpURL());
    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());


  }
View Full Code Here

        2339641349l,
        1904484306l,
        3794544626l,
    };

    Playlist playlist = new Playlist(Hex.toBytes("473e7d4eef45cd4fa3ee2aaf96c01688"));
    playlist.setName("de");
   
    playlist.setTracks(new ArrayList<Track>(3));
         
    boolean fail = false;
    for (int i = 0; i < defaultTracks.length; i++) {
      playlist.getTracks().clear();
      for (int i2 = 0; i2 <= i; i2++) {
        playlist.getTracks().add((defaultTracks[i2]));
      }
      if (checksums[i] == playlist.calculateChecksum()) {
//        System.out.println("passing test" + i);
      } else {
        System.out.println("!! failing test " + i + ", calculated " + playlist.calculateChecksum() + " != expected " + checksums[i]);
        fail = true;
      }

    }
View Full Code Here

    3e31323430353335 3031373c2f74696d 653e3c757365723e 6b656e742e66696e [>1240535017</time><user>kent.fin]
    656c6c3c2f757365 723e3c2f6368616e 67653e3c76657273 696f6e3e30303030 [ell</user></change><version>0000]
    3030303030362c30 3030303030303030 312c313032363232 393836362c303c2f [000006,0000000001,1026229866,0</]
    76657273696f6e3e                                                    [version>]
     */
    user.getPlaylists().getItems().add(new Playlist(Hex.toBytes("5667962d4c1764d12cd68b86a4394916"), "jotify1", "kent.finell", false));
    assertEquals(1026229866l, user.getPlaylists().calculateChecksum());

    /*
    3600cd0000fd5119 3b39429813002885 0a1a72bb7f020000 000000000000ffff [6?????Q?;9B???(???r?????????????]
    ffff01033c69642d 69732d756e697175 652f3e3c6368616e 67653e3c6f70733e [????<id-is-unique/><change><ops>]
    3c6372656174652f 3e3c6e616d653e6a 6f74696679323c2f 6e616d653e3c2f6f [<create/><name>jotify2</name></o]
    70733e3c74696d65 3e31323430353335 3130353c2f74696d 653e3c757365723e [ps><time>1240535105</time><user>]
    6b656e742e66696e 656c6c3c2f757365 723e3c2f6368616e 67653e3c76657273 [kent.finell</user></change><vers]
    696f6e3e30303030 3030303030312c30 3030303030303030 302c303030303030 [ion>0000000001,0000000000,000000]
    303030312c303c2f 76657273696f6e3e                                   [0001,0</version>]

    3600e50000000000 0000000000000000 0000000000000000 0006000000013d2b [6?????????????????????????????=+]
    066a00033c636861 6e67653e3c6f7073 3e3c6164643e3c69 3e313c2f693e3c69 [?j??<change><ops><add><i>1</i><i]
    74656d733e666435 3131393362333934 3239383133303032 3838353061316137 [tems>fd51193b394298130028850a1a7]
    326262376630323c 2f6974656d733e3c 2f6164643e3c2f6f 70733e3c74696d65 [2bb7f02</items></add></ops><time]
    3e31323430353335 3130353c2f74696d 653e3c757365723e 6b656e742e66696e [>1240535105</time><user>kent.fin]
    656c6c3c2f757365 723e3c2f6368616e 67653e3c76657273 696f6e3e30303030 [ell</user></change><version>0000]
    3030303030372c30 3030303030303030 322c333730313437 363237332c303c2f [000007,0000000002,3701476273,0</]
    76657273696f6e3e                                                    [version>]
     */
    user.getPlaylists().getItems().add(new Playlist(Hex.toBytes("fd51193b394298130028850a1a72bb7f"), "jotify2", "kent.finell", false));
    assertEquals(3701476273l, user.getPlaylists().calculateChecksum());


    /*
    3600cd00005710e6 6cde8a35bfa824d5 6f85fdab31020000 000000000000ffff [6????W??l??5??$?o???1???????????]
    ffff01033c69642d 69732d756e697175 652f3e3c6368616e 67653e3c6f70733e [????<id-is-unique/><change><ops>]
    3c6372656174652f 3e3c6e616d653e6a 6f74696679333c2f 6e616d653e3c2f6f [<create/><name>jotify3</name></o]
    70733e3c74696d65 3e31323430353335 3134383c2f74696d 653e3c757365723e [ps><time>1240535148</time><user>]
    6b656e742e66696e 656c6c3c2f757365 723e3c2f6368616e 67653e3c76657273 [kent.finell</user></change><vers]
    696f6e3e30303030 3030303030312c30 3030303030303030 302c303030303030 [ion>0000000001,0000000000,000000]
    303030312c303c2f 76657273696f6e3e                                   [0001,0</version>]

    3600e50000000000 0000000000000000 0000000000000000 000700000002dca0 [6???????????????????????????????]
    0bb100033c636861 6e67653e3c6f7073 3e3c6164643e3c69 3e323c2f693e3c69 [????<change><ops><add><i>2</i><i]
    74656d733e353731 3065363663646538 6133356266613832 3464353666383566 [tems>5710e66cde8a35bfa824d56f85f]
    646162333130323c 2f6974656d733e3c 2f6164643e3c2f6f 70733e3c74696d65 [dab3102</items></add></ops><time]
    3e31323430353335 3134383c2f74696d 653e3c757365723e 6b656e742e66696e [>1240535148</time><user>kent.fin]
    656c6c3c2f757365 723e3c2f6368616e 67653e3c76657273 696f6e3e30303030 [ell</user></change><version>0000]
    3030303030382c30 3030303030303030 332c343035313337 353135382c303c2f [000008,0000000003,4051375158,0</]
    76657273696f6e3e                                                    [version>]
     */
    user.getPlaylists().getItems().add(new Playlist(Hex.toBytes("5710e66cde8a35bfa824d56f85fdab31"), "jotify3", "kent.finell", false));
    assertEquals(4051375158l, user.getPlaylists().calculateChecksum());


  }
View Full Code Here

    }

    System.out.println("loaded content of user playlists");

    for (int i = user.getPlaylists().getItems().size() - 1; i > 0; i--) {
      Playlist playlist = user.getPlaylists().getItems().get(i);
      if (playlist.getName().startsWith("despotify_Test")) {
        new RemovePlaylistFromUser(store, user, playlist).send(connection.getProtocol());
      }
    }
  }
View Full Code Here

  @Override
  public Playlist send(Connection connection) throws DespotifyException {
    byte[] playlistUUID = new ReserveRandomPlaylistUUID(store, user, playlistName, collaborative).send(connection);
    String hexUUID = Hex.toHex(playlistUUID);
    Playlist playlist = store.getPlaylist(hexUUID);
    playlist.setAuthor(user.getId());
    playlist.setName(playlistName);
    playlist.setId(hexUUID);
    if (new CreatePlaylistWithReservedUUID(store, user, playlist).send(connection)) {
      return playlist;
    } else {
      throw new DespotifyException();
    }
View Full Code Here

      connection.close();
    }

    byte[] playlistUUID = new ReserveRandomPlaylistUUID(store, user, playlistName, collaborative).send(connectionManager);
    String hexUUID = Hex.toHex(playlistUUID);
    Playlist playlist = store.getPlaylist(hexUUID);
    playlist.setAuthor(user.getId());
    playlist.setName(playlistName);
    playlist.setId(hexUUID);
    if (new CreatePlaylistWithReservedUUID(store, user, playlist).send(connectionManager)) {
      return (Playlist)store.persist(playlist);
    } else {
      throw new DespotifyException();
    }
View Full Code Here

TOP

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

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.