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); } }
@NonNull private List<Video> getItems() { List<Video> items = data.getItems(); if (items == null) items = new ArrayList<>(); return items; }
void refresh() throws IOException { Disposable disposable = // Observable.just(ytApi.playlistItems() .list(YOUTUBE_PLAYLIST_PART) .setPlaylistId(YOUTUBE_PLAYLIST_ID) .setPageToken(null) .setFields(YOUTUBE_PLAYLIST_FIELDS) .setMaxResults(YOUTUBE_PLAYLIST_MAX_RESULTS) .setKey(API_KEY) // ) .map(AbstractGoogleClientRequest::execute) .map(PlaylistItemListResponse::getItems) .flatMap(playlistItems -> Observable.fromIterable(playlistItems) .map(item -> item.getSnippet().getResourceId().getVideoId())) .toList() .map(ids -> ytApi.videos().list(YOUTUBE_VIDEOS_PART).setFields(YOUTUBE_VIDEOS_FIELDS) // .setKey(API_KEY).setId(TextUtils.join(",", ids)).execute()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnError( throwable -> Log.e(TAG, "accept() called with: throwable = [" + throwable + "]")) .doOnSuccess( response -> Log.d(TAG, "accept() called with: response = [" + response + "]")) .onErrorReturnItem(new VideoListResponse()) // Bad work around .doOnSuccess(liveData::setValue) .subscribe(); disposables.add(disposable); } }
/** * 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; }
private String parseThumbnailUrl(Video video) { ThumbnailDetails thumbnails = video.getSnippet().getThumbnails(); if (thumbnails != null && thumbnails.getDefault() != null) { return thumbnails.getDefault().getUrl(); } return null; }
/** * createActorForChannel. * @param channel Channel * @return $.actor */ public static ActivityObject createActorForChannel(Channel channel) { ActivityObject actor = new ActivityObject(); // TODO: use generic provider id concatenator actor.setId("id:youtube:" + channel.getId()); actor.setSummary(channel.getSnippet().getDescription()); actor.setDisplayName(channel.getSnippet().getTitle()); Image image = new Image(); image.setUrl(channel.getSnippet().getThumbnails().getHigh().getUrl()); actor.setImage(image); actor.setUrl("https://youtube.com/user/" + channel.getId()); Map<String, Object> actorExtensions = new HashMap<>(); actorExtensions.put("followers", channel.getStatistics().getSubscriberCount()); actorExtensions.put("posts", channel.getStatistics().getVideoCount()); actor.setAdditionalProperty("extensions", actorExtensions); return actor; }
/** * Given the raw JsonNode, construct a video snippet object. * @param node JsonNode * @return VideoSnippet */ private VideoSnippet buildSnippet(JsonNode node) { VideoSnippet snippet = new VideoSnippet(); JsonNode snippetNode = node.get("snippet"); snippet.setChannelId(snippetNode.get("channelId").asText()); snippet.setChannelTitle(snippetNode.get("channelTitle").asText()); snippet.setDescription(snippetNode.get("description").asText()); snippet.setTitle(snippetNode.get("title").asText()); snippet.setPublishedAt(new DateTime(snippetNode.get("publishedAt").get("value").asLong())); ThumbnailDetails thumbnailDetails = new ThumbnailDetails(); for (JsonNode t : snippetNode.get("thumbnails")) { Thumbnail thumbnail = new Thumbnail(); thumbnail.setHeight(t.get("height").asLong()); thumbnail.setUrl(t.get("url").asText()); thumbnail.setWidth(t.get("width").asLong()); thumbnailDetails.setDefault(thumbnail); } snippet.setThumbnails(thumbnailDetails); return snippet; }
public String getTitle() { return mVideo.getSnippet().getTitle(); }
/** * 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 getYouTubeId() { return mVideo.getId(); }
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; }
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); }
protected ThumbnailDetails setThumbnails(JsonNode node) { ThumbnailDetails details = new ThumbnailDetails(); if (node == null) { return details; } details.setDefault(new Thumbnail().setUrl(node.get("default").get("url").asText())); details.setHigh(new Thumbnail().setUrl(node.get("high").get("url").asText())); details.setMedium(new Thumbnail().setUrl(node.get("medium").get("url").asText())); return details; }
protected ChannelStatistics setChannelStatistics(JsonNode node) { ChannelStatistics stats = new ChannelStatistics(); if (node == null) { return stats; } stats.setCommentCount(node.get("commentCount").bigIntegerValue()); stats.setHiddenSubscriberCount(node.get("hiddenSubscriberCount").asBoolean()); stats.setSubscriberCount(node.get("subscriberCount").bigIntegerValue()); stats.setVideoCount(node.get("videoCount").bigIntegerValue()); stats.setViewCount(node.get("viewCount").bigIntegerValue()); return stats; }
/** * Given the raw JsonNode, construct a statistics object. * @param node JsonNode * @return VideoStatistics */ private VideoStatistics buildStatistics(JsonNode node) { VideoStatistics statistics = new VideoStatistics(); JsonNode statisticsNode = node.get("statistics"); statistics.setCommentCount(statisticsNode.get("commentCount").bigIntegerValue()); statistics.setDislikeCount(statisticsNode.get("dislikeCount").bigIntegerValue()); statistics.setFavoriteCount(statisticsNode.get("favoriteCount").bigIntegerValue()); statistics.setLikeCount(statisticsNode.get("likeCount").bigIntegerValue()); statistics.setViewCount(statisticsNode.get("viewCount").bigIntegerValue()); return statistics; } }
protected ChannelContentDetails.RelatedPlaylists setRelatedPlaylists(JsonNode node) { ChannelContentDetails.RelatedPlaylists playlists = new ChannelContentDetails.RelatedPlaylists(); if (node == null) { return playlists; } if (node.findValue("favorites") != null) { playlists.setFavorites(node.get("favorites").asText()); } if (node.findValue("likes") != null) { playlists.setLikes(node.get("likes").asText()); } if (node.findValue("uploads") != null) { playlists.setUploads(node.get("uploads").asText()); } return playlists; }
protected ChannelLocalization setLocalized(JsonNode node) { if (node == null) { return new ChannelLocalization(); } ChannelLocalization localization = new ChannelLocalization(); localization.setDescription(node.get("description").asText()); localization.setTitle(node.get("title").asText()); return localization; }
/** * Add the Youtube extensions to the Activity object that we're building. * @param activity Activity * @param video Video */ private static void addYoutubeExtensions(Activity activity, Video video) { Map<String, Object> extensions = ExtensionUtil.getInstance().ensureExtensions(activity); extensions.put("youtube", video); if (video.getStatistics() != null) { Map<String, Object> likes = new HashMap<>(); likes.put("count", video.getStatistics().getCommentCount()); extensions.put("likes", likes); } }
public String getThumbUri() { return mVideo.getSnippet().getThumbnails().getDefault().getUrl(); }
private void prepareAttributes(Video video, YElement yElement) { yElement.addAttribute(SOURCE_YOUTUBE_VIDEO_ID, video.getId()); }