Java源码示例:com.google.api.services.youtube.model.VideoSnippet

示例1
/**
 * 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;
}
 
示例2
@Override
public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {
    if (mPlaylistVideos.size() == 0) {
        return;
    }

    final Video video = mPlaylistVideos.get(position);
    final VideoSnippet videoSnippet = video.getSnippet();

    holder.mTitleText.setText(videoSnippet.getTitle());

    Picasso.with(holder.mContext)
            .load(videoSnippet.getThumbnails().getHigh().getUrl())
            .placeholder(R.drawable.video_placeholder)
            .into(holder.mThumbnailImage);

    holder.mThumbnailImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(view.getContext(),PlayerActivity.class);
            intent.putExtra("videoID",video.getId());
            holder.mContext.startActivity(intent);
        }
    });


    if (mListener != null) {
        final String nextPageToken = mPlaylistVideos.getNextPageToken();
        if (!isEmpty(nextPageToken) && position == mPlaylistVideos.size() - 1) {
            holder.itemView.post(new Runnable() {
                @Override
                public void run() {
                    mListener.onLastItem(holder.getAdapterPosition(), nextPageToken);
                }
            });
        }
    }
}
 
示例3
@Override
protected WebhookMessage createMessage(Video video, YouTubeConnection connection) {
    MapPlaceholderResolver resolver = new MapPlaceholderResolver();
    resolver.put("channel", video.getSnippet().getChannelTitle());
    resolver.put("video", video.getSnippet().getTitle());
    resolver.put("link", getVideoUrl(video.getId()));
    String announce = connection.getAnnounceMessage();
    if (StringUtils.isBlank(announce)) {
        announce = getMessage(connection, "discord.youtube.announce");
    }
    String content = PLACEHOLDER.replacePlaceholders(announce, resolver);

    WebhookMessageBuilder builder = new WebhookMessageBuilder()
            .setContent(content);

    if (connection.isSendEmbed()) {
        WebhookEmbedBuilder embedBuilder = new WebhookEmbedBuilder();
        VideoSnippet snippet = video.getSnippet();
        embedBuilder.setAuthor(new WebhookEmbed.EmbedAuthor(snippet.getChannelTitle(),
                connection.getIconUrl(),
                getChannelUrl(snippet.getChannelId())));

        if (snippet.getThumbnails() != null && snippet.getThumbnails().getMedium() != null) {
            embedBuilder.setImageUrl(snippet.getThumbnails().getMedium().getUrl());
        }
        embedBuilder.setDescription(CommonUtils.mdLink(snippet.getTitle(), getVideoUrl(video.getId())));
        embedBuilder.setColor(Color.RED.getRGB());
        if (snippet.getPublishedAt() != null) {
            embedBuilder.setTimestamp(Instant.ofEpochMilli(snippet.getPublishedAt().getValue()));
        }

        builder.addEmbeds(embedBuilder.build());
    }
    return builder.build();
}
 
示例4
/**
 * Used for refreshing
 *
 * @param item YouTube video object with snippet and statistics parts present
 */
public YouTubeVideo(Video item) {
    super(item.getId(), item.getSnippet().getTitle(), item.getSnippet().getThumbnails().getMedium().getUrl());
    setTypeId(YType.VIDEO);

    if (item.getSnippet() != null) {
        VideoSnippet snippet = item.getSnippet();

        this.channelId = snippet.getChannelId();
        this.description = snippet.getDescription();
        this.published = snippet.getPublishedAt().getValue();
    } else {
        logger.warn("Video snippet is null");
    }

    if (item.getStatistics() != null) {
        VideoStatistics stats = item.getStatistics();

        this.viewCount = Optional.ofNullable(stats.getViewCount())
                .orElse(BigInteger.ZERO)
                .longValue();

        // Likes and dislikes may be disabled on the video
        this.likes = Optional.ofNullable(stats.getLikeCount())
                .orElse(BigInteger.ZERO)
                .longValue();
        this.dislikes = Optional.ofNullable(stats.getDislikeCount())
                .orElse(BigInteger.ZERO)
                .longValue();

        // When comments are disabled, this value will be null on the video.
        // responseCode should also be 403 when when comment threads are grabbed during refresh.
        this.comments = Optional.ofNullable(stats.getCommentCount())
                .orElse(BigInteger.ZERO)
                .longValue();
    } else {
        logger.warn("Video statistics is null");
    }

    this.refreshedOn = System.currentTimeMillis();
}
 
示例5
/**
 * Constructor.
 */
public YouTubeVideo(Video video) {
	this.id = video.getId();

	VideoSnippet snippet = video.getSnippet();
	if (snippet != null) {
		this.title = snippet.getTitle();

		this.channel = new YouTubeChannel(snippet.getChannelId(), snippet.getChannelTitle());
		setPublishDate(snippet.getPublishedAt());

		if (snippet.getThumbnails() != null) {
			Thumbnail thumbnail = snippet.getThumbnails().getHigh();
			if (thumbnail != null) {
				this.thumbnailUrl = thumbnail.getUrl();
			}

			thumbnail = snippet.getThumbnails().getMaxres();
			if (thumbnail != null) {
				this.thumbnailMaxResUrl = thumbnail.getUrl();
			}
		}

		this.language = snippet.getDefaultAudioLanguage() != null ? snippet.getDefaultAudioLanguage()
				: (snippet.getDefaultLanguage());

		this.description = snippet.getDescription();
	}

	if (video.getContentDetails() != null) {
		setDuration(video.getContentDetails().getDuration());
		setIsLiveStream();
		setDurationInSeconds(video.getContentDetails().getDuration());
	}

	VideoStatistics statistics = video.getStatistics();
	if (statistics != null) {
		setLikeDislikeCount(statistics.getLikeCount() != null ? statistics.getLikeCount().longValue() : null, statistics.getDislikeCount() != null ? statistics.getDislikeCount().longValue() : null);

		setViewCount(statistics.getViewCount());
	}
}