Beispiel #1
0
  public List<VideoItem> getFavoriteVideo(List<String> favoriteVideoIds) {
    Joiner stringJoiner = Joiner.on(',');
    String videoId = stringJoiner.join(favoriteVideoIds);

    //        Log.d(TAG, "String video ID: " + videoId);

    // Call the YouTube Data API's youtube.videos.list method to
    // retrieve the resources that represent the specified videos
    YouTube.Videos.List listVideosRequest = null;
    try {
      listVideosRequest = youtube.videos().list("snippet, recordingDetails").setId(videoId);
      listVideosRequest.setKey(KEY2);
      VideoListResponse listResponse = listVideosRequest.execute();

      List<Video> videoList = listResponse.getItems();

      List<VideoItem> items = new ArrayList<VideoItem>();
      for (Video video : videoList) {
        VideoItem item = new VideoItem();
        item.setTitle(video.getSnippet().getTitle());
        try {
          item.setPublishedDate(
              new SimpleDateFormat("MM/dd/yyyy")
                  .format(
                      (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
                          .parse(video.getSnippet().getPublishedAt().toString()))));
        } catch (ParseException e) {
          Log.d(TAG, "Could parse the date: " + e);
        }
        item.setDescription(video.getSnippet().getDescription());
        item.setThumbnailURL(video.getSnippet().getThumbnails().getDefault().getUrl());
        // same as id in search method
        item.setId(video.getId());

        //                item.setViewCount(video.getStatistics().getViewCount().intValue());
        //                Log.d(TAG, "view count: " +
        // video.getStatistics().getViewCount().intValue());

        items.add(item);
      }
      return items;
    } catch (IOException e) {
      Log.d(TAG, "Could not search: " + e);
      return null;
    }
  }