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 getTitle() { return mVideo.getSnippet().getTitle(); }
/** * 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); } }
/** * 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; }
public String getThumbUri() { return mVideo.getSnippet().getThumbnails().getDefault().getUrl(); }
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();
private void prepareDate(Video video, YElement yElement) { DateTime publishedAt = video.getSnippet().getPublishedAt(); LocalDate publishedDate = new LocalDate(publishedAt.getValue()); YDate yDate = new YDate(DateTypes.DT_PUBLISHED, publishedDate.getYear(), publishedDate.getMonthOfYear(), publishedDate.getDayOfMonth(), null); yElement.addDate(yDate); }
/** * 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); }
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); }
/** * 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; }