Package com.google.gdata.data.youtube

Examples of com.google.gdata.data.youtube.PlaylistFeed


  public PlaylistEntry getVideoInPlaylist(String playlistId, String videoId) {
    String playlistUrl = getPlaylistFeedUrl(playlistId);

    try {
      while (playlistUrl != null) {
        PlaylistFeed playlistFeed = service.getFeed(new URL(playlistUrl), PlaylistFeed.class);
       
        Link nextLink = playlistFeed.getNextLink();
        if (nextLink == null) {
          playlistUrl = null;
        } else {
          playlistUrl = nextLink.getHref();
        }
       
        for (PlaylistEntry playlistEntry : playlistFeed.getEntries()) {
          if (playlistEntry.getMediaGroup().getVideoId().equals(videoId)) {
            return playlistEntry;
          }
        }
      }
View Full Code Here


 
  public PlaylistEntry getLastVideoInPlaylist(String playlistId) {
    String playlistUrl = getPlaylistFeedUrl(playlistId);

    try {
      PlaylistFeed playlistFeed = null;
     
      while (playlistUrl != null) {
        playlistFeed = service.getFeed(new URL(playlistUrl), PlaylistFeed.class);
        Link nextLink = playlistFeed.getNextLink();
       
        if (nextLink == null) {
          playlistUrl = null;
        } else {
          playlistUrl = nextLink.getHref();
        }
      }
     
      if (playlistFeed != null) {
        List<PlaylistEntry> entries = playlistFeed.getEntries();
        return entries.get(entries.size() - 1);
      }
    } catch (MalformedURLException e) {
      log.log(Level.WARNING, "", e);
    } catch (IOException e) {
View Full Code Here

            YouTubeQuery query = new YouTubeQuery(url);
            query.setMaxResults(MAX_RESULTS);
            int i = 1;
            while (true) {
                query.setStartIndex(i);
                PlaylistFeed feed = serv.getFeed(query, PlaylistFeed.class);
                for (PlaylistEntry entry : feed.getEntries()) {
                    playlists.add(entry.getTitle().getPlainText());
                }
                i += MAX_RESULTS;
                if (i > feed.getTotalResults()) {
                    break;
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
View Full Code Here

  }

  public void test() throws MalformedURLException, IOException,
      ServiceException {
    // retrieve a playlist feed and do some batch operations on it
    PlaylistFeed feed = service.getFeed(new URL(""), PlaylistFeed.class);

    // retrieve the batch link from the feed
    URL batchUrl = new URL(feed.getFeedBatchLink().getHref());
    PlaylistFeed batchFeed = new PlaylistFeed();

    // delete the third playlist entry
    PlaylistEntry entryToDelete = feed.getEntries().get(2);
    BatchUtils.setBatchId(entryToDelete, "B");
    BatchUtils.setBatchOperationType(entryToDelete,
        BatchOperationType.DELETE);
    batchFeed.getEntries().add(entryToDelete);

    // add a new video to the playlist
    PlaylistEntry entryToAdd = new PlaylistEntry();
    entryToAdd.setId("mTrp-GKG9Bo");
    BatchUtils.setBatchId(entryToAdd, "A");
    BatchUtils.setBatchOperationType(entryToAdd, BatchOperationType.INSERT);
    batchFeed.getEntries().add(entryToAdd);

    // move the second entry to the top of the playlist
    PlaylistEntry entryToUpdate = feed.getEntries().get(1);
    entryToUpdate.setPosition(0);
    BatchUtils.setBatchId(entryToUpdate, "C");
    BatchUtils.setBatchOperationType(entryToUpdate,
        BatchOperationType.UPDATE);
    batchFeed.getEntries().add(entryToUpdate);

    // return the updated entry
    PlaylistEntry entryToGet = feed.getEntries().get(0);
    BatchUtils.setBatchId(entryToGet, "D");
    BatchUtils.setBatchOperationType(entryToGet, BatchOperationType.QUERY);
    batchFeed.getEntries().add(entryToGet);

    PlaylistFeed batchResponse = service.batch(batchUrl, batchFeed);

    for (PlaylistEntry entry : batchResponse.getEntries()) {
      if (BatchUtils.isSuccess(entry)) {
        System.out.println("Operation " + BatchUtils.getBatchId(entry)
            + " succeeded!");
        String operation = BatchUtils.getBatchOperationType(entry)
            .getName();
View Full Code Here

   * @throws IOException Error sending request or reading the feed.
   * @throws ServiceException If the service is unable to handle the request.
   */
  private static void printPlaylist(Service service, String playlistUrl)
      throws IOException, ServiceException {
    PlaylistFeed playlistFeed = service.getFeed(new URL(playlistUrl),
        PlaylistFeed.class);
    if (playlistFeed != null) {
      for (PlaylistEntry e : playlistFeed.getEntries()) {
        System.out.println("\tPlaylist Entry: " + e.getTitle().getPlainText());
        System.out.println("\tPlaylist URL: " + e.getHtmlLink().getHref());
      }
    }
  }
View Full Code Here

   *                     If the service is unable to handle the request.
   * @throws IOException error sending request or reading the feed.
   */
  private static void printPlaylist(Service service, String playlistUrl)
      throws IOException, ServiceException {
    PlaylistFeed playlistFeed = service.getFeed(new URL(playlistUrl),
        PlaylistFeed.class);
    if (playlistFeed != null) {
      for (PlaylistEntry e : playlistFeed.getEntries()) {
        System.out.println("\tPlaylist Entry: " + e.getTitle().getPlainText());
        System.out.println("\tPlaylist URL: " + e.getHtmlLink().getHref());
      }
    }
  }
View Full Code Here

TOP

Related Classes of com.google.gdata.data.youtube.PlaylistFeed

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.