com.google.api.services.youtube.model.Channel Java Examples
The following examples show how to use
com.google.api.services.youtube.model.Channel.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: YoutubeChannelDeserializer.java From streams with Apache License 2.0 | 6 votes |
@Override public Channel deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonNode node = jp.getCodec().readTree(jp); try { Channel channel = new Channel(); if (node.findPath("etag") != null) { channel.setEtag(node.get("etag").asText()); } if (node.findPath("kind") != null) { channel.setKind(node.get("kind").asText()); } channel.setId(node.get("id").asText()); channel.setTopicDetails(setTopicDetails(node.findValue("topicDetails"))); channel.setStatistics(setChannelStatistics(node.findValue("statistics"))); channel.setContentDetails(setContentDetails(node.findValue("contentDetails"))); channel.setSnippet(setChannelSnippet(node.findValue("snippet"))); return channel; } catch (Throwable throwable) { throw new IOException(throwable); } }
Example #2
Source File: YoutubeActivityUtil.java From streams with Apache License 2.0 | 6 votes |
/** * 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; }
Example #3
Source File: YouTubeSubscriptionServiceImpl.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
@Override @Transactional public YouTubeConnection create(long guildId, Channel channel) { YouTubeConnection connection = super.create(guildId, channel); subscribe(connection.getChannel()); return connection; }
Example #4
Source File: YouTubeSubscriptionServiceImpl.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
@Override protected YouTubeConnection createConnection(Channel channel) { YouTubeConnection connection = new YouTubeConnection(); connection.setChannel(getOrCreateChannel(channel.getId())); ChannelSnippet snippet = channel.getSnippet(); connection.setName(CommonUtils.trimTo(snippet.getTitle(), 255)); connection.setDescription(CommonUtils.trimTo(snippet.getDescription(), 255)); if (snippet.getThumbnails() != null && snippet.getThumbnails().getDefault() != null) { connection.setIconUrl(snippet.getThumbnails().getDefault().getUrl()); } return connection; }
Example #5
Source File: YouTubeSubscriptionHandler.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
@Override public SubscriptionCreateResponse create(long guildId, Map<String, ?> data) { String channelId = getValue(data, "id", String.class); if (StringUtils.isEmpty(channelId)) { throw new IllegalArgumentException("Wrong data"); } Channel channel = youTubeService.getChannelById(channelId); if (channel == null) { return getFailedCreatedDto("wrong_channel"); } YouTubeConnection connection = subscriptionService.create(guildId, channel); return getCreatedDto(getSubscription(connection)); }
Example #6
Source File: YoutubeTypeConverter.java From streams with Apache License 2.0 | 5 votes |
@Override public List<StreamsDatum> process(StreamsDatum streamsDatum) { StreamsDatum result = null; try { Object item = streamsDatum.getDocument(); LOGGER.debug("{} processing {}", STREAMS_ID, item.getClass()); Activity activity; if (item instanceof String) { item = deserializeItem(item); } if (item instanceof Video) { activity = new Activity(); YoutubeActivityUtil.updateActivity((Video)item, activity, streamsDatum.getId()); } else if (item instanceof Channel) { activity = new Activity(); YoutubeActivityUtil.updateActivity((Channel)item, activity, null); } else { throw new NotImplementedException("Type conversion not implement for type : " + item.getClass().getName()); } if (activity != null) { result = new StreamsDatum(activity); count++; } } catch (Exception ex) { LOGGER.error("Exception while converting Video to Activity: {}", ex); } if (result != null) { List<StreamsDatum> streamsDatumList = new ArrayList<>(); streamsDatumList.add(result); return streamsDatumList; } else { return new ArrayList<>(); } }
Example #7
Source File: YoutubeTypeConverter.java From streams with Apache License 2.0 | 5 votes |
private Object deserializeItem(Object item) { try { Class klass = YoutubeEventClassifier.detectClass((String) item); if (klass.equals(Video.class)) { item = mapper.readValue((String) item, Video.class); } else if (klass.equals(Channel.class)) { item = mapper.readValue((String) item, Channel.class); } } catch (Exception ex) { LOGGER.error("Exception while trying to deserializeItem: {}", ex); } return item; }
Example #8
Source File: YoutubeActivityUtil.java From streams with Apache License 2.0 | 5 votes |
/** * Given a {@link Channel} object and an * {@link Activity} object, fill out the appropriate details * * @param channel Channel * @param activity Activity * @throws ActivitySerializerException ActivitySerializerException */ public static void updateActivity(Channel channel, Activity activity, String channelId) throws ActivitySerializerException { try { activity.setProvider(getProvider()); activity.setVerb("post"); activity.setActor(createActorForChannel(channel)); Map<String, Object> extensions = new HashMap<>(); extensions.put("youtube", channel); activity.setAdditionalProperty("extensions", extensions); } catch (Throwable throwable) { throw new ActivitySerializerException(throwable); } }
Example #9
Source File: YoutubeChannelDataCollectorTest.java From streams with Apache License 2.0 | 5 votes |
private ChannelListResponse createMockResponse() { ChannelListResponse response = new ChannelListResponse(); List<Channel> channelList = new LinkedList<>(); response.setItems(channelList); Channel channel = new Channel(); channel.setId(ID); channelList.add(channel); return response; }
Example #10
Source File: YouTubeSubscriptionServiceImpl.java From JuniperBot with GNU General Public License v3.0 | 4 votes |
@Override public Channel getUser(String userName) { return null; }
Example #11
Source File: YouTubeChannel.java From youtube-comment-suite with MIT License | 4 votes |
/** * Convert YouTube object to custom Channel object. */ public YouTubeChannel(Channel item) { super(item.getId(), StringEscapeUtils.unescapeHtml4(item.getSnippet().getTitle()), item.getSnippet().getThumbnails().getDefault().getUrl()); setTypeId(YType.CHANNEL); }
Example #12
Source File: YouTubeChannel.java From SkyTube with GNU General Public License v3.0 | 4 votes |
/** * Parses a {@link Channel} and then sets the instance variables accordingly. * * @param channel */ private boolean parse(Channel channel) { this.id = channel.getId(); boolean ret = false; ChannelSnippet snippet = channel.getSnippet(); if (snippet != null) { ret |= Utils.equals(this.title, snippet.getTitle()); this.title = snippet.getTitle(); ret |= Utils.equals(this.description, snippet.getDescription()); this.description = snippet.getDescription(); ThumbnailDetails thumbnail = snippet.getThumbnails(); if (thumbnail != null) { String thmbNormalUrl = snippet.getThumbnails().getDefault().getUrl(); // YouTube Bug: channels with no thumbnail/avatar will return a link to the default // thumbnail that does NOT start with "http" or "https", but rather it starts with // "//s.ytimg.com/...". So in this case, we just add "https:" in front. String thumbnailUrlLowerCase = thmbNormalUrl.toLowerCase(); if ( !(thumbnailUrlLowerCase.startsWith("http://") || thumbnailUrlLowerCase.startsWith("https://")) ) { thmbNormalUrl = "https:" + thmbNormalUrl; } ret |= Utils.equals(this.thumbnailUrl, thmbNormalUrl); this.thumbnailUrl = thmbNormalUrl; } } ChannelBrandingSettings branding = channel.getBrandingSettings(); if (branding != null) { String bannerUrl = SkyTubeApp.isTablet() ? branding.getImage().getBannerTabletHdImageUrl() : branding.getImage().getBannerMobileHdImageUrl(); ret |= Utils.equals(this.bannerUrl, bannerUrl); this.bannerUrl = bannerUrl; } ChannelStatistics statistics = channel.getStatistics(); if (statistics != null) { long count = statistics.getSubscriberCount().longValue(); ret |= this.subscriberCount != count; this.subscriberCount = count; this.totalSubscribers = getFormattedSubscribers(statistics.getSubscriberCount().longValue()); } return ret; }
Example #13
Source File: YoutubeFaviconFetcher.java From commafeed with Apache License 2.0 | 4 votes |
@Override public Favicon fetch(Feed feed) { String url = feed.getUrl(); if (!url.toLowerCase().contains("youtube.com/feeds/videos.xml")) { return null; } String googleAuthKey = config.getApplicationSettings().getGoogleAuthKey(); if (googleAuthKey == null) { log.debug("no google auth key configured"); return null; } byte[] bytes = null; String contentType = null; try { List<NameValuePair> params = URLEncodedUtils.parse(url.substring(url.indexOf("?") + 1), StandardCharsets.UTF_8); Optional<NameValuePair> userId = params.stream().filter(nvp -> nvp.getName().equalsIgnoreCase("user")).findFirst(); Optional<NameValuePair> channelId = params.stream().filter(nvp -> nvp.getName().equalsIgnoreCase("channel_id")).findFirst(); if (!userId.isPresent() && !channelId.isPresent()) { return null; } YouTube youtube = new YouTube.Builder(new NetHttpTransport(), JacksonFactory.getDefaultInstance(), new HttpRequestInitializer() { @Override public void initialize(HttpRequest request) throws IOException { } }).setApplicationName("CommaFeed").build(); YouTube.Channels.List list = youtube.channels().list("snippet"); list.setKey(googleAuthKey); if (userId.isPresent()) { list.setForUsername(userId.get().getValue()); } else { list.setId(channelId.get().getValue()); } log.debug("contacting youtube api"); ChannelListResponse response = list.execute(); if (response.getItems().isEmpty()) { log.debug("youtube api returned no items"); return null; } Channel channel = response.getItems().get(0); Thumbnail thumbnail = channel.getSnippet().getThumbnails().getDefault(); log.debug("fetching favicon"); HttpResult iconResult = getter.getBinary(thumbnail.getUrl(), TIMEOUT); bytes = iconResult.getContent(); contentType = iconResult.getContentType(); } catch (Exception e) { log.debug("Failed to retrieve YouTube icon", e); } if (!isValidIconResponse(bytes, contentType)) { return null; } return new Favicon(bytes, contentType); }
Example #14
Source File: YouTubeChannel.java From SkyTube with GNU General Public License v3.0 | 3 votes |
/** * Initialise this object. * * @param channel * @param isUserSubscribed if set to true, then it means the user is subscribed to this * channel; otherwise it means that we currently do not know * if the user is subbed or not (hence we need to check). * @param shouldCheckForNewVideos if set to true it will check with the database whether new * videos have been published since last visit. * @return true if the values are different than the stored data. */ public boolean init(Channel channel, boolean isUserSubscribed, boolean shouldCheckForNewVideos) { boolean ret = parse(channel); // if the user has subbed to this channel, then check if videos have been publish since // the last visit to this channel if (this.isUserSubscribed && shouldCheckForNewVideos) { newVideosSinceLastVisit = SubscriptionsDb.getSubscriptionsDb().channelHasNewVideos(this); } return ret; }
Example #15
Source File: YouTubeService.java From JuniperBot with GNU General Public License v3.0 | votes |
Channel getChannelById(String id);