Package com.google.gdata.data.youtube

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


    Tube tub = new Tube();
    try {
      System.out.println("Update from youtube : " + id);
      String videoEntryUrl = "http://gdata.youtube.com/feeds/api/videos/"
          + id;
      VideoEntry videoEntry = service.getEntry(new URL(videoEntryUrl),
          VideoEntry.class);
      if (fullContent) {
        tub.transformVideoEntry(videoEntry);
      } else {
        tub.transformHalfVideoEntry(videoEntry);
View Full Code Here


    Tube tub = new Tube();
    try {
      System.out.println("Update from youtube : " + id);
      String videoEntryUrl = "http://gdata.youtube.com/feeds/api/videos/"
          + id;
      VideoEntry videoEntry = service.getEntry(new URL(videoEntryUrl),
          VideoEntry.class);
      tub.transformVideoEntry(videoEntry);
      TubeModel.add(tub);
      System.out.println("Save to database success !");
      return tub;
View Full Code Here

      // Max title length is 60 characters or 100 bytes.
      if (title.length() > 60) {
        title = title.substring(0, 59);
      }

      VideoEntry newEntry = new VideoEntry();
      YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();

      mg.setTitle(new MediaTitle());
      mg.getTitle().setPlainTextContent(title);

      mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, assignment.getCategory()));

      mg.setKeywords(new MediaKeywords());

      List<String> tags = new ArrayList<String>();
      for (int i = 0; i < tagsArray.length(); i++) {
        String tag = tagsArray.getString(i).trim();
        mg.getKeywords().addKeyword(tag);
        tags.add(tag);
      }

      // Sort the list of tags and join with "," so that we can easily compare
      // what's in the
      // datastore with what we get back from the YouTube API.
      String sortedTags = util.sortedJoin(tags, ",");

      mg.setDescription(new MediaDescription());
      mg.getDescription().setPlainTextContent(description);

      String applicationNameTag = Util.CLIENT_ID_PREFIX + SystemProperty.applicationId.get();
      if (applicationNameTag.length() > 25) {
        applicationNameTag = applicationNameTag.substring(0, 24) + "!";
      }
      mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, applicationNameTag));

      // Maximum size of a developer tag is 25 characters, and we prepend 2
      // characters.
      if (assignmentId.length() <= 23) {
        // Minimum size of a developer tag is 3 characters, so always append 2
        // characters.
        String assignmentIdTag = String.format("A-%s", assignmentId);

        // Use a developer tag to make it easy for developers to query for all
        // videos uploaded for
        // a given assignment.
        mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, assignmentIdTag));
      } else {
        log.warning(String.format("Assignment id '%s' is longer than 25 characters, and can't be "
            + "used as a developer tag.", assignmentId));
      }
     
      if (jsonObj.has("latitude") && jsonObj.has("longitude")) {
        newEntry.setGeoCoordinates(new GeoRssWhere(jsonObj.getDouble("latitude"),
            jsonObj.getDouble("longitude")));
      } else if (!util.isNullOrEmpty(location)) {
        newEntry.setLocation(location);
      }

      userSession.addMetaData("videoTitle", title);
      userSession.addMetaData("videoDescription", description);
      userSession.addMetaData("videoLocation", location);
View Full Code Here

    String videoId = videoSubmission.getVideoId();
    LOG.info(String.format(
        "Updating description and tags of id '%s' (YouTube video id '%s').",
        videoSubmission.getId(), videoId));

    VideoEntry videoEntry = userYouTubeApi.getUploadsVideoEntry(videoId);
    if (videoEntry == null) {
      LOG.warning(String.format(
          "Couldn't get video with id '%s' in the uploads feed of user "
              + "'%s'. Perhaps the AuthSub token has been revoked?", videoId,
          videoSubmission.getYouTubeName()));
    } else {
      String currentDescription = videoSubmission.getVideoDescription();
      String newDescription = String.format("%s\n\n%s", prependText,
          currentDescription);

      // If we have a new tag to add, add to the datastore and YouTube entries.
      if (!util.isNullOrEmpty(newTag)) {
        String currentTags = videoSubmission.getVideoTags();
        String[] tagsArray = currentTags.split(",\\s?");
        ArrayList<String> tagsArrayList = new ArrayList<String>(Arrays
            .asList(tagsArray));
        if (!tagsArrayList.contains(newTag)) {
          tagsArrayList.add(newTag);
          String newTags = util.sortedJoin(tagsArrayList, ",");
          videoSubmission.setVideoTags(newTags);
        }

        YouTubeMediaGroup mg = videoEntry.getOrCreateMediaGroup();
        // This should work as expected even if the tag already exists; No
        // duplicates will be added.
        mg.getKeywords().addKeyword(newTag);
      }

      // Update the datastore entry's description.
      videoSubmission.setVideoDescription(newDescription);

      // Update the YouTube entry's description.
      videoEntry.getMediaGroup().getDescription().setPlainTextContent(
          newDescription);

      try {
        // And update the YouTube.com video as well.
        videoEntry.update();
        return videoEntry;
      } catch (IOException e) {
        LOG.log(Level.WARNING, String.format(
            "Error while updating video id '%s':", videoId), e);
      } catch (ServiceException e) {
View Full Code Here

      apiManager.setAuthSubToken(authSubToken);

      for (int i = 0; i < videoIds.length(); i++) {
        String videoId = videoIds.getString(i);
       
        VideoEntry videoEntry = apiManager.getUploadsVideoEntry(videoId);
 
        if (videoEntry == null) {
          JSONObject responseJsonObj = new JSONObject();
          responseJsonObj.put("success", "false");
          responseJsonObj.put("message", "Cannot find this video in your account.");
 
          resp.setContentType("text/javascript");
          resp.getWriter().println(responseJsonObj.toString());
        } else {
          String title = videoEntry.getTitle().getPlainText();
          String description = videoEntry.getMediaGroup().getDescription().getPlainTextContent();
 
          List<String> tags = videoEntry.getMediaGroup().getKeywords().getKeywords();
          String sortedTags = util.sortedJoin(tags, ",");
 
          long viewCount = -1;
 
          YtStatistics stats = videoEntry.getStatistics();
          if (stats != null) {
            viewCount = stats.getViewCount();
          }
 
          VideoSubmission submission = new VideoSubmission(Long.parseLong(assignmentId));
View Full Code Here

        // This will retrieve video info from the Uploads feed of the user who
        // owns the video.
        // This should always be the freshest data, but it relies on the AuthSub
        // token being valid.
        VideoEntry videoEntry = apiManager.getUploadsVideoEntry(videoId);
        if (videoEntry == null) {
          // Try an unauthenticated request to the specific user's uploads feed
          // next.
          videoEntry = apiManager.getUploadsVideoEntry(videoSubmission.getYouTubeName(), videoId);

          if (videoEntry == null) {
            // Fall back on looking for the video in the public feed.
            videoEntry = apiManager.getVideoEntry(videoId);

            if (videoEntry == null) {
              // The video must have been deleted...
              log.info(String.format("Unable to find YouTube video id '%s'.", videoId));
              videoSubmission.setYouTubeState("NOT_FOUND");
            }
          }
        }

        if (videoEntry != null) {
          try {
            YtPublicationState state = videoEntry.getPublicationState();
            String stateValue;
            if (state == null) {
              // TODO: Find some way to check whether the video is embeddable
              // and/or private, and
              // populate that info. Because we're getting the video from the
              // authenticated
              // uploads feed (by default), that info isn't easily exposed on
              // the videoEntry
              // object. An alternative would be to get an instance from the
              // public video feed
              // and check that.

              List<YouTubeMediaRating> ratings = videoEntry.getMediaGroup().getYouTubeRatings();
              if (ratings.size() == 0) {
                stateValue = "OKAY";
              } else {
                StringBuffer restrictionBuffer = new StringBuffer("RESTRICTED IN: ");
                for (YouTubeMediaRating rating : ratings) {
                  restrictionBuffer.append(rating.getCountries());
                }
                stateValue = restrictionBuffer.toString();
              }
            } else {
              stateValue = state.getState().toString();
            }
            if (!stateValue.equals(videoSubmission.getYouTubeState())) {
              log.info(String.format("YouTube state differs: '%s' (local) vs. '%s' (YT).",
                  videoSubmission.getYouTubeState(), stateValue));
              videoSubmission.setYouTubeState(stateValue);
              videoSubmission.setUpdated(now);
            }

            String title = videoEntry.getTitle().getPlainText();
            if (!title.equals(videoSubmission.getVideoTitle())) {
              log.info(String.format("Title differs: '%s' (local) vs. '%s' (YT).", videoSubmission
                  .getVideoTitle(), title));
              videoSubmission.setVideoTitle(title);
              videoSubmission.setUpdated(now);
            }

            String description = videoEntry.getMediaGroup().getDescription().getPlainTextContent();
            if (!description.equals(videoSubmission.getVideoDescription())) {
              log.info(String.format("Description differs: '%s' (local) vs. '%s' (YT).",
                  videoSubmission.getVideoDescription(), description));
              videoSubmission.setVideoDescription(description);
              videoSubmission.setUpdated(now);
            }

            List<String> tags = videoEntry.getMediaGroup().getKeywords().getKeywords();
            String sortedTags = util.sortedJoin(tags, ",");
            if (!sortedTags.equals(videoSubmission.getVideoTags())) {
              log.info(String.format("Tags differs: '%s' (local) vs. '%s' (YT).", videoSubmission
                  .getVideoTags(), sortedTags));
              videoSubmission.setVideoTags(sortedTags);
              videoSubmission.setUpdated(now);
            }
          } catch (NullPointerException e) {
            log.info(String.format("Couldn't get metadata for video id '%s'. It may not have been"
                + " accepted by YouTube.", videoId));
          }

          // Unconditionally update view count info, but don't call setUpdated()
          // since this is an
          // auto-update.
          YtStatistics stats = videoEntry.getStatistics();
          if (stats != null) {
            videoSubmission.setViewCount(stats.getViewCount());
          }

          log.info(String.format("Finished syncing video id '%s'", videoId));
View Full Code Here

        apiManager.setClientLoginToken(userAuthToken.getClientLoginToken());
      } else {
        throw new IllegalArgumentException(String.format("Couldn't retrieve authentication token for user '%s'.", user));
      }

      VideoEntry videoEntry = apiManager.getVideoEntry(id);
      if (videoEntry == null) {
        throw new IllegalArgumentException(String.format("Couldn't retrieve video entry with id " + "'%s' for user '%s'.", id, user));
      }

      Link insightLink = videoEntry.getLink("http://gdata.youtube.com/schemas/2007#insight.views", null);
      if (insightLink != null) {
        String url = insightLink.getHref();
        if (util.isNullOrEmpty(url)) {
          throw new IllegalArgumentException(String.format("No insight download URL found for " + "video id '%s'.", id));
        }
View Full Code Here

      if (util.isNullOrEmpty(authSubToken)) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "missing authSubToken");
      }

      youtubeApiProxy.setAuthSubToken(authSubToken);
      VideoEntry videoEntry = youtubeApiProxy.getUploadsVideoEntry(videoId);

      if (videoEntry == null) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST,
            "video id does not match the authsub token");
      } else {
        String youTubeName = videoEntry.getAuthors().get(0).getName();
        String title = videoEntry.getTitle().getPlainText();
        String description = videoEntry.getMediaGroup().getDescription().getPlainTextContent();
        List<String> tags = videoEntry.getMediaGroup().getKeywords().getKeywords();
        String sortedTags = util.sortedJoin(tags, ",");

        VideoSubmission submission = new VideoSubmission(assignmentId);
        submission.setVideoId(videoId);
        submission.setVideoTitle(title);
View Full Code Here

      String videoId = videoSubmission.getVideoId();

      // This will retrieve video info from the Uploads feed of the user who owns the video.
      // This should always be the freshest data, but it relies on the AuthSub token being valid.
      VideoEntry videoEntry = apiManager.getUploadsVideoEntry(videoId);
      if (videoEntry == null) {
        // Try an unauthenticated request to the specific user's uploads feed next.
        AdminConfig admin = adminConfigDao.getAdminConfig();
        String clientId = admin.getClientId();
        YouTubeApiHelper apiHelper = new YouTubeApiHelper(clientId);
        videoEntry = apiHelper.getUploadsVideoEntry(videoSubmission.getYouTubeName(), videoId);

        if (videoEntry == null) {
          // Fall back on looking for the video in the public feed.
          videoEntry = apiHelper.getVideoEntry(videoId);

          if (videoEntry == null) {
            // The video must have been deleted...
            LOG.info(String.format("Unable to find YouTube video id '%s'.", videoId));
            videoSubmission.setYouTubeState("NOT_FOUND");
          }
        }
      }

      if (videoEntry != null) {
        try {
          YtPublicationState state = videoEntry.getPublicationState();
          String stateValue;
          if (state == null) {
            // TODO: Find some way to check whether the video is embeddable and/or private, and
            // populate that info. Because we're getting the video from the authenticated
            // uploads feed (by default), that info isn't easily exposed on the videoEntry
            // object. An alternative would be to get an instance from the public video feed
            // and check that.

            List<YouTubeMediaRating> ratings = videoEntry.getMediaGroup().getYouTubeRatings();
            if (ratings.size() == 0) {
              stateValue = "OKAY";
            } else {
              StringBuffer restrictionBuffer = new StringBuffer("RESTRICTED IN: ");
              for (YouTubeMediaRating rating : ratings) {
                restrictionBuffer.append(rating.getCountries());
              }
              stateValue = restrictionBuffer.toString();
            }
          } else {
            stateValue = state.getState().toString();
          }
          if (!stateValue.equals(videoSubmission.getYouTubeState())) {
            LOG.info(String.format("YouTube state differs: '%s' (local) vs. '%s' (YT).",
                videoSubmission.getYouTubeState(), stateValue));
            videoSubmission.setYouTubeState(stateValue);
            videoSubmission.setUpdated(now);
          }

          String title = videoEntry.getTitle().getPlainText();
          if (!title.equals(videoSubmission.getVideoTitle())) {
            LOG.info(String.format("Title differs: '%s' (local) vs. '%s' (YT).", videoSubmission
                .getVideoTitle(), title));
            videoSubmission.setVideoTitle(title);
            videoSubmission.setUpdated(now);
          }

          String description = videoEntry.getMediaGroup().getDescription().getPlainTextContent();
          if (!description.equals(videoSubmission.getVideoDescription())) {
            LOG.info(String.format("Description differs: '%s' (local) vs. '%s' (YT).",
                videoSubmission.getVideoDescription(), description));
            videoSubmission.setVideoDescription(description);
            videoSubmission.setUpdated(now);
          }

          List<String> tags = videoEntry.getMediaGroup().getKeywords().getKeywords();
          String sortedTags = util.sortedJoin(tags, ",");
          if (!sortedTags.equals(videoSubmission.getVideoTags())) {
            LOG.info(String.format("Tags differs: '%s' (local) vs. '%s' (YT).", videoSubmission
                .getVideoTags(), sortedTags));
            videoSubmission.setVideoTags(sortedTags);
            videoSubmission.setUpdated(now);
          }
        } catch (NullPointerException e) {
          LOG.info(String.format("Couldn't get metadata for video id '%s'. It may not have been"
              + " accepted by YouTube.", videoId));
        }

        // Unconditionally update view count info, but don't call setUpdated() since this is an
        // auto-update.
        YtStatistics stats = videoEntry.getStatistics();
        if (stats != null) {
          videoSubmission.setViewCount(stats.getViewCount());
        }

        LOG.info(String.format("Finished syncing video id '%s'", videoId));
View Full Code Here

    if (title.length() > 100) {
      title = title.substring(0, 99);
    }

    VideoEntry newEntry = new VideoEntry();
    YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();

    mg.setTitle(new MediaTitle());
    mg.getTitle().setPlainTextContent(title);

    mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "News"));
View Full Code Here

TOP

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

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.