Examples of VideoSubmission


Examples of com.google.ytd.model.VideoSubmission

   
    if (oldAssignment.equals(newAssignment)) {
      throw new IllegalArgumentException("oldAssignment and newAssignment can't be the same.");
    }

    VideoSubmission submission = submissionDao.getSubmissionById(id);
    if (submission == null) {
      throw new IllegalArgumentException("Can't find submission with id " + id);
    }
   
    if (submission.isInPlaylist()) {
      AdminConfig adminConfig = adminConfigDao.getAdminConfig();

      // Set the YouTubeApiHelper with the admin auth token
      String token = adminConfig.getYouTubeAuthSubToken();
      if (util.isNullOrEmpty(token)) {
        LOG.warning(String.format("No AuthSub token found in admin config."));
      } else {
        adminYouTubeApi.setAuthSubToken(token);
      }
     
      removeFromPlaylist(submission);
    }
   
    submission.setAssignmentId(Long.parseLong(newAssignment));
    submission = submissionDao.save(submission);
   
    boolean success = true;
    if (submission.isInPlaylist()) {
      success = addToPlaylist(submission);
    }
   
    json.put("success", success);
    return json;
View Full Code Here

Examples of com.google.ytd.model.VideoSubmission

          YtStatistics stats = videoEntry.getStatistics();
          if (stats != null) {
            viewCount = stats.getViewCount();
          }
 
          VideoSubmission submission = new VideoSubmission(Long.parseLong(assignmentId));
 
          submission.setArticleUrl(articleUrl);
          submission.setVideoId(videoId);
          submission.setVideoTitle(title);
          submission.setVideoDescription(description);
          submission.setVideoTags(sortedTags);
          submission.setVideoLocation(location);
          submission.setPhoneNumber(phoneNumber);
          submission.setVideoDate(date);
          submission.setYouTubeName(youTubeName);
 
          userAuthTokenDao.setUserAuthToken(youTubeName, authSubToken);
 
          submission.setViewCount(viewCount);
          submission.setVideoSource(VideoSubmission.VideoSource.EXISTING_VIDEO);
          submission.setNotifyEmail(email);
 
          AdminConfig adminConfig = adminConfigDao.getAdminConfig();
          if (adminConfig.getModerationMode() == AdminConfig.ModerationModeType.NO_MOD.ordinal()) {
            // NO_MOD is set, auto approve all submission
            // TODO: This isn't enough, as the normal approval flow (adding the
            // branding, tags, emails,
            // etc.) isn't taking place.
            submission.setStatus(VideoSubmission.ModerationStatus.APPROVED);
           
            // Add video to YouTube playlist if it isn't in it already.
            // This code is kind of ugly and is mostly copy/pasted from UpdateVideoSubmissionStatus
            // TODO: It should be refactored into a common helper method somewhere...
            if (!submission.isInPlaylist()) {
              Assignment assignment = assignmentDao.getAssignmentById(assignmentId);
 
              if (assignment == null) {
                log.warning(String.format("Couldn't find assignment id '%d' for video id '%s'.",
                    assignmentId, videoId));
              } else {
                String playlistId = assignment.getPlaylistId();
                if (util.isNullOrEmpty(playlistId)) {
                  log.warning(String.format("Assignment id '%d' doesn't have an associated playlist.",
                      assignmentId));
                } else {
                  apiManager.setAuthSubToken(adminConfig.getYouTubeAuthSubToken());
                  if (apiManager.insertVideoIntoPlaylist(playlistId, videoId)) {
                    submission.setIsInPlaylist(true);
                  }
                }
              }
            }
          }
View Full Code Here

Examples of com.google.ytd.model.VideoSubmission

    if (util.isNullOrEmpty(id)) {
      throw new IllegalArgumentException("Missing required param: id");
    }

    VideoSubmission videoSubmission = videoSubmissionDao.getSubmissionById(id);
    if (videoSubmission.isInPlaylist()) {
      removeFromPlaylist(videoSubmission);
    }
   
    videoSubmissionDao.deleteSubmission(id);
   
View Full Code Here

Examples of com.google.ytd.model.VideoSubmission

    if (util.isNullOrEmpty(adminNotes)) {
      // Essentially emptying the admin notes
      adminNotes = "";
    }

    VideoSubmission submission = submissionDao.getSubmissionById(id);

    if (submission == null) {
      throw new IllegalArgumentException("The input video id cannot be located.");
    }

    submission.setAdminNotes(adminNotes);
    submission.setUpdated(new Date());
    submissionDao.save(submission);

    return json;
  }
View Full Code Here

Examples of com.google.ytd.model.VideoSubmission

    if (util.isNullOrEmpty(submissionId)) {
      throw new IllegalArgumentException(
          "Required parameter 'submissionId' is null or empty.");
    }

    VideoSubmission videoSubmission = submissionDao
        .getSubmissionById(submissionId);
    if (videoSubmission == null) {
      throw new IllegalArgumentException(String.format(
          "Couldn't retrieve VideoSubmission with"
              + " id '%s' from the datastore.", submissionId));
    }

    String username = videoSubmission.getYouTubeName();
    UserAuthToken userAuthToken = authTokenDao.getUserAuthToken(videoSubmission
        .getYouTubeName());
    if (!userAuthToken.getAuthSubToken().isEmpty()) {
      apiManager.setAuthSubToken(userAuthToken.getAuthSubToken());
    } else {
      apiManager.setClientLoginToken(userAuthToken.getClientLoginToken());
    }

    Map<String, String> languageToUrl = apiManager.getCaptions(videoSubmission
        .getVideoId());
    if (languageToUrl != null) {
      json.put("captions", languageToUrl);
      json.put("username", username);
      json.put("videoId", videoSubmission.getVideoId());
    } else {
      throw new IllegalArgumentException(
          "Unable to retrieve caption information for the video.");
    }
View Full Code Here

Examples of com.google.ytd.model.VideoSubmission

        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);
        submission.setVideoDescription(description);
        submission.setVideoTags(sortedTags);
        submission.setVideoLocation(location);
        submission.setVideoDate(date);
        submission.setYouTubeName(youTubeName);
        submission.setVideoSource(VideoSubmission.VideoSource.MOBILE_SUBMIT);
        submission.setNotifyEmail(email);

        userAuthTokenDao.setUserAuthToken(youTubeName, authSubToken);

        AdminConfig adminConfig = adminConfigDao.getAdminConfig();
        if (adminConfig.getModerationMode() == AdminConfig.ModerationModeType.NO_MOD.ordinal()) {
          // NO_MOD is set, auto approve all submission
          // TODO: This isn't enough, as the normal approval flow (adding the
          // branding, tags, emails,
          // etc.) isn't taking place.
          submission.setStatus(VideoSubmission.ModerationStatus.APPROVED);
        }
        pmfUtil.persistJdo(submission);
        emailUtil.sendNewSubmissionEmail(submission);

        resp.setContentType("text/plain");
View Full Code Here

Examples of com.google.ytd.model.VideoSubmission

      throw new IllegalArgumentException("Missing required param: videoId");
    }

    LOG.info(String.format("Sync'ing metadata for submission id %s", submissionId));

    VideoSubmission videoSubmission = submissionDao.getSubmissionById(submissionId);
    if (videoSubmission == null) {
      throw new IllegalArgumentException(String.format("Couldn't retrieve VideoSubmission with"
          + " id '%s' from the datastore.", submissionId));
    }

    Date now = new Date();
    long delta = now.getTime() - videoSubmission.getLastSynced().getTime();
    if (delta > REFRESH_INTERVAL) {
      UserAuthToken userAuthToken =
        userAuthTokenDao.getUserAuthToken(videoSubmission.getYouTubeName());
   
      if (!userAuthToken.getAuthSubToken().isEmpty()) {
        apiManager.setAuthSubToken(userAuthToken.getAuthSubToken());
      } else {
        apiManager.setClientLoginToken(userAuthToken.getClientLoginToken());
      }

      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));
      }

      // It's important to update lastSynced even for videos that didn't change.
      videoSubmission.setLastSynced(now);
      submissionDao.save(videoSubmission);
    } else {
      LOG.info(String.format("Data is fresh; %.2f seconds since last sync.", delta / 1000.0));
    }
View Full Code Here

Examples of com.google.ytd.model.VideoSubmission

      String videoDate = userSession.getMetaData("videoDate");

      log.fine(String.format("Attempting to persist VideoSubmission with YouTube id '%s' "
          + "for assignment id '%s'...", videoId, assignmentId));

      VideoSubmission submission = submissionDao.newSubmission(Long.parseLong(assignmentId));

      submission.setArticleUrl(articleUrl);
      submission.setVideoId(videoId);
      submission.setVideoTitle(videoTitle);
      submission.setVideoDescription(videoDescription);
      submission.setVideoTags(videoTags);
      submission.setVideoLocation(videoLocation);
      submission.setVideoDate(videoDate);
      submission.setYouTubeName(youTubeName);
      submission.setVideoSource(VideoSubmission.VideoSource.NEW_UPLOAD);
      submission.setNotifyEmail(email);
      submission.setPhoneNumber(phoneNumber);

      userAuthTokenDao.setUserAuthToken(youTubeName, authSubToken);

      AdminConfig adminConfig = adminConfigDao.getAdminConfig();

      youTubeApiHelper.setAuthSubToken(adminConfig.getYouTubeAuthSubToken());

      if (adminConfig.getModerationMode() == AdminConfig.ModerationModeType.NO_MOD.ordinal()) {
        // NO_MOD is set, auto approve all submission
        // TODO: This isn't enough, as the normal approval flow (adding the branding, tags, emails,
        // etc.) isn't taking place.
        submission.setStatus(VideoSubmission.ModerationStatus.APPROVED);
        youTubeApiHelper.updateModeration(videoId, true);
       
        // Add video to YouTube playlist if it isn't in it already.
        // This code is kind of ugly and is mostly copy/pasted from UpdateVideoSubmissionStatus
        // TODO: It should be refactored into a common helper method somewhere...
        if (!submission.isInPlaylist()) {
          Assignment assignment = assignmentDao.getAssignmentById(assignmentId);

          if (assignment == null) {
            log.warning(String.format("Couldn't find assignment id '%d' for video id '%s'.",
                assignmentId, videoId));
          } else {
            String playlistId = assignment.getPlaylistId();
            if (util.isNullOrEmpty(playlistId)) {
              log.warning(String.format("Assignment id '%d' does not have an associated playlist.",
                  assignmentId));
            } else {
              if (youTubeApiHelper.insertVideoIntoPlaylist(playlistId, videoId)) {
                submission.setIsInPlaylist(true);
              }
            }
          }
        }
      } else {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.