void bind(@NonNull Video item) { this.videoId = item.getId(); this.videoName.setText(item.getSnippet().getTitle()); this.videoCaption.setText(item.getSnippet().getDescription()); Thumbnail thumbnail = item.getSnippet().getThumbnails().getHigh(); if (thumbnail != null && thumbnail.getHeight() > 0) { playerViewContainer.setAspectRatio(thumbnail.getWidth() / (float) thumbnail.getHeight()); Glide.with(itemView).load(thumbnail.getUrl()).apply(options).into(thumbnailView); } }
public VideoSnippet addTags(Collection<? extends String> tags) { VideoSnippet mSnippet = mVideo.getSnippet(); List<String> mTags = mSnippet.getTags(); if (mTags == null) { mTags = new ArrayList<String>(2); } mTags.addAll(tags); return mSnippet; }
public String getYouTubeId() { return mVideo.getId(); }
try { Video videoObjectDefiningMetadata = new Video(); videoObjectDefiningMetadata.setStatus(status); videoObjectDefiningMetadata.setSnippet(snippet); videoId = returnedVideo.getId(); Log.d(TAG, String.format("videoId = [%s]", videoId)); } catch (final GooglePlayServicesAvailabilityIOException availabilityException) {
/** * Because the Youtube Video object contains complex objects within its hierarchy, we have to use * a custom deserializer * * @param jsonParser jsonParser * @param deserializationContext deserializationContext * @return The deserialized {@link com.google.api.services.youtube.YouTube.Videos} object * @throws java.io.IOException IOException * @throws com.fasterxml.jackson.core.JsonProcessingException JsonProcessingException */ @Override public Video deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { JsonNode node = jsonParser.getCodec().readTree(jsonParser); Video video = new Video(); try { video.setId(node.get("id").asText()); video.setEtag(node.get("etag").asText()); video.setKind(node.get("kind").asText()); video.setSnippet(buildSnippet(node)); video.setStatistics(buildStatistics(node)); } catch (Exception ex) { LOGGER.error("Exception while trying to deserialize a Video object: {}", ex); } return video; }
private void prepareYElementFromApi(Video video, YElement yElement) throws ParseException { yElement.addName(new YName(video.getSnippet().getTitle())); yElement.addDescription(new YDescription(YLanguage.Undetermined, video.getSnippet().getDescription() , DescriptionTypes.DS_SUMMARY)); prepareDate(video, yElement); String license = video.getStatus().getLicense(); if(null != license && license.contains("creativeCommon")) { yElement.addTagList(new YTagList().setType(YModelUtils.LICENSE).addValue("cc0")); } prepareContent(video, yElement); List<String> tags = video.getSnippet().getTags(); if (CollectionUtils.isNotEmpty(tags)) { yElement.addTagList(new YTagList().setType(TagTypes.TG_KEYWORD).setValues(tags)); } YCurrent currentLevel = new YCurrent().setLevel(VideoConstants.VIDEO_CURRENT_LEVEL); yElement.addStructure(new YStructure() .setHierarchy(HierarchyWithLevelIds.EXT_HIERARCHY_PUBLICATION) .setCurrent(currentLevel)); prepareAttributes(video, yElement); }
private void directTag(final VideoData video) { final Video updateVideo = new Video(); VideoSnippet snippet = video .addTags(Arrays.asList( Constants.DEFAULT_KEYWORD, Upload.generateKeywordFromPlaylistId(Constants.UPLOAD_PLAYLIST))); updateVideo.setSnippet(snippet); updateVideo.setId(video.getYouTubeId()); new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... voids) { YouTube youtube = new YouTube.Builder(transport, jsonFactory, credential).setApplicationName(Constants.APP_NAME) .build(); try { youtube.videos().update("snippet", updateVideo).execute(); } catch (UserRecoverableAuthIOException e) { startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION); } catch (IOException e) { Log.e(TAG, e.getMessage()); } return null; } }.execute((Void) null); Toast.makeText(this, R.string.video_submitted_to_ytdl, Toast.LENGTH_LONG) .show(); }
if ("public".equals(video.getStatus() .getPrivacyStatus())) { VideoData videoData = new VideoData();
public String getTitle() { return mVideo.getSnippet().getTitle(); }
@Override public void onClick(View view) { Intent intent = new Intent(view.getContext(),PlayerActivity.class); intent.putExtra("videoID",video.getId()); holder.mContext.startActivity(intent); } });
/** * Given a {@link YouTube.Videos} object and an * {@link Activity} object, fill out the appropriate details * * @param video Video * @param activity Activity * @throws ActivitySerializerException ActivitySerializerException */ public static void updateActivity(Video video, Activity activity, String channelId) throws ActivitySerializerException { activity.setActor(buildActor(video, video.getSnippet().getChannelId())); activity.setVerb("post"); activity.setId(formatId(activity.getVerb(), Optional.ofNullable(video.getId()).orElse(null))); activity.setPublished(new DateTime(video.getSnippet().getPublishedAt().getValue())); activity.setTitle(video.getSnippet().getTitle()); activity.setContent(video.getSnippet().getDescription()); activity.setUrl("https://www.youtube.com/watch?v=" + video.getId()); activity.setProvider(getProvider()); activity.setObject(buildActivityObject(video)); addYoutubeExtensions(activity, video); }
/** * Process a list of Video objects. * @param videos List of Video * @param afterDate afterDate * @param beforeDate beforeDate * @param activity com.google.api.services.youtube.model.Activity * @param feed ActivityListResponse */ void processVideos(List<Video> videos, DateTime afterDate, DateTime beforeDate, com.google.api.services.youtube.model.Activity activity, ActivityListResponse feed) { try { for (Video video : videos) { if (video != null) { org.joda.time.DateTime published = new org.joda.time.DateTime(video.getSnippet().getPublishedAt().getValue()); if ((afterDate == null && beforeDate == null) || (beforeDate == null && afterDate.isBefore(published)) || (afterDate == null && beforeDate.isAfter(published)) || ((afterDate != null && beforeDate != null) && (afterDate.isAfter(published) && beforeDate.isBefore(published)))) { LOGGER.debug("Providing Youtube Activity: {}", MAPPER.writeValueAsString(video)); this.datumQueue.put(new StreamsDatum(gson.toJson(video), activity.getId())); } else if (afterDate != null && afterDate.isAfter(published)) { feed.setNextPageToken(null); // do not fetch next page break; } } } } catch (Exception ex) { LOGGER.error("Exception while trying to process video list: {}, {}", videos, ex); } }
private void prepareAttributes(Video video, YElement yElement) { yElement.addAttribute(SOURCE_YOUTUBE_VIDEO_ID, video.getId()); }
/** * Given a video object, create the appropriate activity object with a valid image * (thumbnail) and video URL. * @param video Video * @return Activity Object with Video URL and a thumbnail image */ private static ActivityObject buildActivityObject(Video video) { ActivityObject activityObject = new ActivityObject(); ThumbnailDetails thumbnailDetails = video.getSnippet().getThumbnails(); Thumbnail thumbnail = thumbnailDetails.getDefault(); if (thumbnail != null) { Image image = new Image(); image.setUrl(thumbnail.getUrl()); image.setHeight(thumbnail.getHeight()); image.setWidth(thumbnail.getWidth()); activityObject.setImage(image); } activityObject.setUrl("https://www.youtube.com/watch?v=" + video.getId()); activityObject.setObjectType("video"); return activityObject; }
/** * Build an {@link ActivityObject} actor given the video object * @param video Video * @param id id * @return Actor object */ private static ActivityObject buildActor(Video video, String id) { ActivityObject actor = new ActivityObject(); actor.setId("id:youtube:" + id); actor.setDisplayName(video.getSnippet().getChannelTitle()); actor.setSummary(video.getSnippet().getDescription()); actor.setAdditionalProperty("handle", video.getSnippet().getChannelTitle()); return actor; }
private void prepareContent(Video video, YElement yElement) { YContentFile viedoUrlContnent = new YContentFile(video.getId(), VideoConstants.VIDEO_URL_FILE_TYPE, VideoConstants.YOUTUBE_FORMAT, Collections.singletonList(video.getId())); yElement.addContent(viedoUrlContnent); String thumbnailUrl = parseThumbnailUrl(video); if (thumbnailUrl != null) { // TODO format detect YContentFile thumbnailContent = new YContentFile(video.getId() + "_thumbnail", FileTypes.FT_THUMBNAIL, MediaType.ANY_IMAGE_TYPE.toString(), Collections.singletonList(thumbnailUrl)); yElement.addContent(thumbnailContent); } }
public String getThumbUri() { return mVideo.getSnippet().getThumbnails().getDefault().getUrl(); }
this.part = com.google.api.client.util.Preconditions.checkNotNull(part, "Required parameter part must be specified."); checkRequiredParameter(content, "content"); checkRequiredParameter(content.getId(), "Video.getId()");
private String parseThumbnailUrl(Video video) { ThumbnailDetails thumbnails = video.getSnippet().getThumbnails(); if (thumbnails != null && thumbnails.getDefault() != null) { return thumbnails.getDefault().getUrl(); } return null; }
final VideoSnippet videoSnippet = video.getSnippet();