com.google.api.services.youtube.model.Video Java Examples

The following examples show how to use com.google.api.services.youtube.model.Video. 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: YoutubeTypeConverterTest.java    From streams with Apache License 2.0 6 votes vote down vote up
@Test
public void testVideoConversion() {
  try {
    LOGGER.info("raw: {}", testVideo);
    Activity activity = new Activity();

    Video video = objectMapper.readValue(testVideo, Video.class);
    StreamsDatum streamsDatum = new StreamsDatum(video);

    assertNotNull(streamsDatum.getDocument());

    List<StreamsDatum> retList = youtubeTypeConverter.process(streamsDatum);
    YoutubeActivityUtil.updateActivity(video, activity, "testChannelId");

    assertEquals(retList.size(), 1);
    assert (retList.get(0).getDocument() instanceof Activity);
    assertEquals(activity, retList.get(0).getDocument());
  } catch (Exception ex) {
    LOGGER.error("Exception while trying to convert video to activity: {}", ex);
  }
}
 
Example #2
Source File: YoutubeVideoDeserializer.java    From streams with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: YoutubeActivityUtil.java    From streams with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #4
Source File: YoutubeActivityUtil.java    From streams with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #5
Source File: ExploreFragment.java    From wmn-safety with MIT License 6 votes vote down vote up
private void reloadUi(final PlaylistVideos playlistVideos, boolean fetchPlaylist) {
    initCardAdapter(playlistVideos);
    if (fetchPlaylist) {
        new GetPlaylistAsyncTask(mYouTubeDataApi) {
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                showProgressDialog(true);
            }

            @Override
            public void onPostExecute(Pair<String, List<Video>> result) {
                handleGetPlaylistResult(playlistVideos, result);
                showProgressDialog(false);
            }
        }.execute(playlistVideos.playlistId, playlistVideos.getNextPageToken());
    }
}
 
Example #6
Source File: YoutubeUserActivityCollector.java    From streams with Apache License 2.0 6 votes vote down vote up
/**
 * Given a feed and an after and before date, fetch all relevant user videos
 * and place them into the datumQueue for post-processing.
 * @param feed ActivityListResponse
 * @param afterDate DateTime
 * @param beforeDate DateTime
 * @throws IOException IOException
 * @throws InterruptedException InterruptedException
 */
void processActivityFeed(ActivityListResponse feed, DateTime afterDate, DateTime beforeDate) throws IOException, InterruptedException {
  for (com.google.api.services.youtube.model.Activity activity : feed.getItems()) {
    try {
      List<Video> videos = new ArrayList<>();

      if (activity.getContentDetails().getUpload() != null) {
        videos.addAll(getVideoList(activity.getContentDetails().getUpload().getVideoId()));
      }
      if (activity.getContentDetails().getPlaylistItem() != null && activity.getContentDetails().getPlaylistItem().getResourceId() != null) {
        videos.addAll(getVideoList(activity.getContentDetails().getPlaylistItem().getResourceId().getVideoId()));
      }

      processVideos(videos, afterDate, beforeDate, activity, feed);
    } catch (Exception ex) {
      LOGGER.error("Error while trying to process activity: {}, {}", activity, ex);
    }
  }
}
 
Example #7
Source File: YoutubeUserActivityCollector.java    From streams with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
  }
}
 
Example #8
Source File: YoutubeTypeConverterTest.java    From streams with Apache License 2.0 6 votes vote down vote up
@Test
public void testStringVideoConversion() {
  try {
    LOGGER.info("raw: {}", testVideo);
    Activity activity = new Activity();

    Video video = objectMapper.readValue(testVideo, Video.class);
    StreamsDatum streamsDatum = new StreamsDatum(testVideo);

    assertNotNull(streamsDatum.getDocument());

    List<StreamsDatum> retList = youtubeTypeConverter.process(streamsDatum);
    YoutubeActivityUtil.updateActivity(video, activity, "testChannelId");

    assertEquals(retList.size(), 1);
    assert (retList.get(0).getDocument() instanceof Activity);
    assertEquals(activity, retList.get(0).getDocument());
  } catch (Exception ex) {
    LOGGER.error("Exception while trying to convert video to activity: {}", ex);
  }
}
 
Example #9
Source File: YouTubeAPI.java    From UTubeTV with The Unlicense 6 votes vote down vote up
private List<YouTubeData> itemsToMap(List<Video> playlistItemList) {
  List<YouTubeData> result = new ArrayList<YouTubeData>();

  // convert the list into hash maps of video info
  for (Video playlistItem : playlistItemList) {
    YouTubeData map = new YouTubeData();

    map.mVideo = playlistItem.getId();
    map.mTitle = playlistItem.getSnippet().getTitle();
    map.mDescription = Utils.condenseWhiteSpace(playlistItem.getSnippet().getDescription());
    map.mThumbnail = thumbnailURL(playlistItem.getSnippet().getThumbnails());
    map.mDuration = Utils.durationToDuration((String) playlistItem.getContentDetails()
        .get("duration"));

    result.add(map);
  }

  return result;
}
 
Example #10
Source File: YouTubeAPI.java    From UTubeTV with The Unlicense 6 votes vote down vote up
private List<YouTubeData> itemsToMap(List<Video> playlistItemList) {
  List<YouTubeData> result = new ArrayList<YouTubeData>();

  // convert the list into hash maps of video info
  for (Video playlistItem : playlistItemList) {
    YouTubeData map = new YouTubeData();

    map.mVideo = playlistItem.getId();
    map.mDuration = Utils.durationToDuration((String) playlistItem.getContentDetails()
        .get("duration"));
    map.mTitle = playlistItem.getSnippet().getTitle();
    map.mDescription = Utils.condenseWhiteSpace(playlistItem.getSnippet().getDescription());
    map.mThumbnail = thumbnailURL(playlistItem.getSnippet().getThumbnails());
    map.mPublishedDate = playlistItem.getSnippet().getPublishedAt().getValue();

    result.add(map);
  }

  return result;
}
 
Example #11
Source File: YoutubeVideoSerDeTest.java    From streams with Apache License 2.0 5 votes vote down vote up
/**
 * setup for test.
 */
@Before
public void setup() {
  objectMapper = StreamsJacksonMapper.getInstance();
  SimpleModule simpleModule = new SimpleModule();
  simpleModule.addDeserializer(Video.class, new YoutubeVideoDeserializer());
  objectMapper.registerModule(simpleModule);
  objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
 
Example #12
Source File: YoutubeUserActivityCollectorTest.java    From streams with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetVideos() throws IOException {
  DateTime now = new DateTime(System.currentTimeMillis());
  YouTube youtube = buildYouTube(0, 1, 0, now, now.minus(10000));

  BlockingQueue<StreamsDatum> datumQueue = new ThroughputQueue<>();
  YoutubeUserActivityCollector collector = new YoutubeUserActivityCollector(youtube, datumQueue, new ExponentialBackOffStrategy(2), new UserInfo().withUserId(USER_ID), this.config);

  List<Video> video = collector.getVideoList("fake_video_id");

  assertNotNull(video.get(0));
}
 
Example #13
Source File: YoutubeActivityUtil.java    From streams with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
  }
}
 
Example #14
Source File: YoutubeTypeConverterTest.java    From streams with Apache License 2.0 5 votes vote down vote up
/**
 * setup for test.
 */
@Before
public void setup() {
  objectMapper = StreamsJacksonMapper.getInstance();
  SimpleModule simpleModule = new SimpleModule();
  simpleModule.addDeserializer(Video.class, new YoutubeVideoDeserializer());
  objectMapper.registerModule(simpleModule);
  objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

  youtubeTypeConverter = new YoutubeTypeConverter();
  youtubeTypeConverter.prepare(null);
}
 
Example #15
Source File: YoutubeUserActivityCollector.java    From streams with Apache License 2.0 5 votes vote down vote up
/**
 * Given a Youtube videoId, return the relevant Youtube Video object.
 * @param videoId videoId
 * @return List of Videos
 * @throws IOException
 */
List<Video> getVideoList(String videoId) throws IOException {
  VideoListResponse videosListResponse = this.youtube.videos().list("snippet,statistics")
      .setId(videoId)
      .setKey(config.getApiKey())
      .execute();

  if (videosListResponse.getItems().size() == 0) {
    LOGGER.debug("No Youtube videos found for videoId: {}", videoId);
    return new ArrayList<>();
  }

  return videosListResponse.getItems();
}
 
Example #16
Source File: YoutubeUserActivityCollectorTest.java    From streams with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetVideosNull() throws IOException {
  DateTime now = new DateTime(System.currentTimeMillis());
  YouTube youtube = buildYouTube(0, 0, 0, now.plus(10000), now.minus(10000));

  BlockingQueue<StreamsDatum> datumQueue = new ThroughputQueue<>();
  YoutubeUserActivityCollector collector = new YoutubeUserActivityCollector(youtube, datumQueue, new ExponentialBackOffStrategy(2), new UserInfo().withUserId(USER_ID), this.config);

  List<Video> video = collector.getVideoList("fake_video_id");

  assertEquals(video.size(), 0);
}
 
Example #17
Source File: YoutubeActivityUtil.java    From streams with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #18
Source File: YouTubeRecyclerViewFragment.java    From YouTubePlaylist with Apache License 2.0 5 votes vote down vote up
private void reloadUi(final PlaylistVideos playlistVideos, boolean fetchPlaylist) {
    // initialize the cards adapter
    initCardAdapter(playlistVideos);

    if (fetchPlaylist) {
        // start fetching the selected playlistVideos contents
        new GetPlaylistAsyncTask(mYouTubeDataApi) {
            @Override
            public void onPostExecute(Pair<String, List<Video>> result) {
                handleGetPlaylistResult(playlistVideos, result);
            }
        }.execute(playlistVideos.playlistId, playlistVideos.getNextPageToken());
    }
}
 
Example #19
Source File: YouTubeRecyclerViewFragment.java    From YouTubePlaylist with Apache License 2.0 5 votes vote down vote up
private void initCardAdapter(final PlaylistVideos playlistVideos) {
    // create the adapter with our playlistVideos and a callback to handle when we reached the last item
    mPlaylistCardAdapter = new PlaylistCardAdapter(playlistVideos, new LastItemReachedListener() {
        @Override
        public void onLastItem(int position, String nextPageToken) {
            new GetPlaylistAsyncTask(mYouTubeDataApi) {
                @Override
                public void onPostExecute(Pair<String, List<Video>> result) {
                    handleGetPlaylistResult(playlistVideos, result);
                }
            }.execute(playlistVideos.playlistId, playlistVideos.getNextPageToken());
        }
    });
    mRecyclerView.setAdapter(mPlaylistCardAdapter);
}
 
Example #20
Source File: YouTubeRecyclerViewFragment.java    From YouTubePlaylist with Apache License 2.0 5 votes vote down vote up
private void handleGetPlaylistResult(PlaylistVideos playlistVideos, Pair<String, List<Video>> result) {
    if (result == null) return;
    final int positionStart = playlistVideos.size();
    playlistVideos.setNextPageToken(result.first);
    playlistVideos.addAll(result.second);
    mPlaylistCardAdapter.notifyItemRangeInserted(positionStart, result.second.size());
}
 
Example #21
Source File: YoutubeTypeConverter.java    From streams with Apache License 2.0 5 votes vote down vote up
@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 #22
Source File: ExploreFragment.java    From wmn-safety with MIT License 5 votes vote down vote up
private void initCardAdapter(final PlaylistVideos playlistVideos) {
    mPlaylistCardAdapter = new PlaylistCardAdapter(playlistVideos, new ItemReachedListener() {
        @Override
        public void onLastItem(int position, String nextPageToken) {
            new GetPlaylistAsyncTask(mYouTubeDataApi) {
                @Override
                public void onPostExecute(Pair<String, List<Video>> result) {
                    handleGetPlaylistResult(playlistVideos, result);
                }}.execute(playlistVideos.playlistId, playlistVideos.getNextPageToken());}
    });
    mRecyclerView.setAdapter(mPlaylistCardAdapter);
}
 
Example #23
Source File: ExploreFragment.java    From wmn-safety with MIT License 5 votes vote down vote up
private void handleGetPlaylistResult(PlaylistVideos playlistVideos, Pair<String, List<Video>> result) {
    if (result == null) return;
    final int positionStart = playlistVideos.size();
    playlistVideos.setNextPageToken(result.first);
    playlistVideos.addAll(result.second);
    mPlaylistCardAdapter.notifyItemRangeInserted(positionStart, result.second.size());
}
 
Example #24
Source File: PlaylistCardAdapter.java    From wmn-safety with MIT License 5 votes vote down vote up
@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);
                }
            });
        }
    }
}
 
Example #25
Source File: SpotifyAudioSourceManager.java    From SkyBot with GNU Affero General Public License v3.0 5 votes vote down vote up
private AudioItem getSpotifyTrack(AudioReference reference) {

        final Matcher res = SPOTIFY_TRACK_REGEX.matcher(reference.identifier);

        if (!res.matches()) {
            return null;
        }

        try {
            final Track track = this.spotifyApi.getTrack(res.group(res.groupCount())).build().execute();
            final String videoId = searchYoutube(track.getName(), track.getArtists()[0].getName());

            if (videoId == null) {
                return null;
            }

            final Video v = getVideoById(videoId, this.config.googl);

            if (v == null) {
                return null;
            }

            return audioTrackFromVideo(v, track.getAlbum().getImages());
        }
        catch (Exception e) {
            //logger.error("Something went wrong!", e);
            throw new FriendlyException(e.getMessage(), Severity.FAULT, e);
        }
    }
 
Example #26
Source File: SpotifyAudioSourceManager.java    From SkyBot with GNU Affero General Public License v3.0 5 votes vote down vote up
private List<AudioTrack> getTrackListFromVideoIds(List<String> videoIds, Image[] images) throws Exception {
    final String videoIdsJoined = String.join(",", videoIds);
    final List<Video> videosByIds = getVideosByIds(videoIdsJoined, this.config.googl);
    final List<AudioTrack> playList = new ArrayList<>();

    videosByIds.forEach((video) -> playList.add(audioTrackFromVideo(video, images)));

    return playList;
}
 
Example #27
Source File: SpotifyAudioSourceManager.java    From SkyBot with GNU Affero General Public License v3.0 5 votes vote down vote up
private AudioTrack audioTrackFromVideo(Video v, Image[] images) {
    return new SpotifyAudioTrack(new AudioTrackInfoWithImage(
        v.getSnippet().getTitle(),
        v.getSnippet().getChannelTitle(),
        toLongDuration(v.getContentDetails().getDuration()),
        v.getId(),
        false,
        "https://youtube.com/watch?v=" + v.getId(),
        imageUrlOrThumbnail(images, v)
    ), this.youtubeAudioSourceManager);
}
 
Example #28
Source File: SpotifyAudioSourceManager.java    From SkyBot with GNU Affero General Public License v3.0 5 votes vote down vote up
private String imageUrlOrThumbnail(Image[] images, Video video) {
    if (images.length > 0) {
        return images[0].getUrl();
    }

    return getThumbnail(video);
}
 
Example #29
Source File: YouTubeSubscriptionServiceImpl.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@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();
}
 
Example #30
Source File: YoutubeTypeConverter.java    From streams with Apache License 2.0 5 votes vote down vote up
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;
}