Package com.google.gdata.data.youtube

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


  }

  public boolean insertVideoIntoPlaylist(String playlistId, String videoId, boolean retry) {
    log.info(String.format("Attempting to insert video id '%s' into playlist id '%s'...",
        videoId, playlistId));
    PlaylistEntry playlistEntry = new PlaylistEntry();
    playlistEntry.setId(videoId);

    if (getVideoInPlaylist(playlistId, videoId) != null) {
      log.warning(String.format("Video id '%s' is already in playlist id '%s'.", videoId,
          playlistId));
      // Return true here, so that the video is flagged as being in the playlist.
      return true;
    }
   
    // As of Aug 2011, it's now possible to set the playlist position at insertion time.
    playlistEntry.setPosition(0);

    try {
      playlistEntry = service.insert(new URL(getPlaylistFeedUrl(playlistId)), playlistEntry);
      log.info(String.format("Inserted video id '%s' into playlist id '%s' at position 1.",
        videoId, playlistId));
      return true;
    } catch (MalformedURLException e) {
      log.log(Level.WARNING, "", e);
    } catch (IOException e) {
      log.log(Level.WARNING, "", e);
    } catch (ServiceForbiddenException e) {
      log.log(Level.INFO, "Maximum size of playlist reached.", e);

      if (retry) {
        log.info("Removing oldest entry from playlist and retrying...");

        PlaylistEntry lastVideo = getLastVideoInPlaylist(playlistId);
        if (lastVideo != null) {
          try {
            lastVideo.delete();
            log.info("Last entry removed.");

            return insertVideoIntoPlaylist(playlistId, videoId, false);
          } catch (IOException innerEx) {
            log.log(Level.WARNING, "", innerEx);
View Full Code Here


    return null;
  }

  public boolean removeVideoFromPlaylist(String playlistId, String videoId) {
    try {
      PlaylistEntry playlistEntry = getVideoInPlaylist(playlistId, videoId);

      if (playlistEntry == null) {
        log.warning(String.format("Could not find video id '%s' in playlist id '%s'.", videoId,
            playlistId));
        return false;
      } else {
        playlistEntry.delete();

        log.info(String.format("Removed video '%s' from playlist id '%s'.", videoId, playlistId));

        return true;
      }
View Full Code Here

    // 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);
View Full Code Here

      System.out.println("Sorry, the video ID you entered was not valid.\n");
      return;
    }

    String playlistUrl = entry.getFeedUrl();
    PlaylistEntry playlistEntry = new PlaylistEntry(videoEntry);

    try {
      service.insert(new URL(playlistUrl), playlistEntry);
    } catch (ServiceException e) {
      System.out.println("Error adding vide to playlist");
View Full Code Here

TOP

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

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.