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

The following examples show how to use com.google.api.services.youtube.model.VideoListResponse. 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: YouTubeAPI.java    From UTubeTV with The Unlicense 6 votes vote down vote up
private String nextToken() {
  String result = null;

  if (response == null)
    result = ""; // first time
  else {
    // is there a better way of doing this?
    if (response instanceof SearchListResponse) {
      result = ((SearchListResponse) response).getNextPageToken();
    } else if (response instanceof PlaylistItemListResponse) {
      result = ((PlaylistItemListResponse) response).getNextPageToken();
    } else if (response instanceof SubscriptionListResponse) {
      result = ((SubscriptionListResponse) response).getNextPageToken();
    } else if (response instanceof VideoListResponse) {
      result = ((VideoListResponse) response).getNextPageToken();
    } else if (response instanceof PlaylistListResponse) {
      result = ((PlaylistListResponse) response).getNextPageToken();
    } else {
      doHandleExceptionMessage("nextToken bug!");
    }
  }

  return result;
}
 
Example #2
Source File: GetFeaturedVideos.java    From SkyTube with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<CardData> getNextVideos() {
	setLastException(null);

	if (!noMoreVideoPages()) {
		try {
			// set the page token/id to retrieve
			videosList.setPageToken(nextPageToken);

			// set the preferred region (placed here to reflect any changes performed at runtime)
			videosList.setRegionCode(getPreferredRegion());

			// communicate with YouTube
			VideoListResponse response = videosList.execute();

			// get videos
			List<Video> searchResultList = response.getItems();

			// set the next page token
			nextPageToken = response.getNextPageToken();

			// if nextPageToken is null, it means that there are no more videos
			if (nextPageToken == null)
				noMoreVideoPages = true;
			return toYouTubeVideoList(searchResultList);
		} catch (IOException e) {
			setLastException(e);
			Logger.e(this, "Error has occurred while getting Featured Videos:" + e.getMessage(), e);
		}
	}
	return Collections.emptyList();
}
 
Example #3
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 #4
Source File: YoutubeUserActivityCollectorTest.java    From streams with Apache License 2.0 4 votes vote down vote up
@Override
public VideoListResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
  int totalCount = 0;
  int batchAfter = 0;
  int batchBefore = 0;
  int batchIn = 0;
  inCount = 0;
  afterCount = 0;
  beforeCount = 0;

  if (afterCount != numAfter) {
    if (numAfter - afterCount >= maxBatch) {
      afterCount += maxBatch;
      batchAfter += maxBatch;
      totalCount += batchAfter;
    } else {
      batchAfter += numAfter - afterCount;
      totalCount += numAfter - afterCount;
      afterCount = numAfter;
    }
  }
  if (totalCount < maxBatch && inCount != numInRange) {
    if (numInRange - inCount >= maxBatch - totalCount) {
      inCount += maxBatch - totalCount;
      batchIn += maxBatch - totalCount;
      totalCount += batchIn;
    } else {
      batchIn += numInRange - inCount;
      totalCount += numInRange - inCount;
      inCount = numInRange;
    }
  }
  if (totalCount < maxBatch && beforeCount != numBefore) {
    if (numBefore - batchBefore >= maxBatch - totalCount) {
      batchBefore += maxBatch - totalCount;
      totalCount = maxBatch;
      beforeCount += batchBefore;
    } else {
      batchBefore += numBefore - beforeCount;
      totalCount += numBefore - beforeCount;
      beforeCount = numBefore;
    }
  }

  return createMockVideoListResponse(batchBefore, batchAfter, batchIn, after, before, numAfter != afterCount || inCount != numInRange || beforeCount != numBefore);
}
 
Example #5
Source File: ListViewActivity.java    From RxTube with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.youtube_list_view);

  ButterKnife.inject(this);

  final List<String> ids = new ArrayList<>();
  ids.add("iX-QaNzd-0Y");
  ids.add("nCkpzqqog4k");
  ids.add("pB-5XG-DbAA");
  ids.add("QD7qIthSdkA");
  ids.add("GtKnRFNffsI");
  ids.add("IIA1XQnAv5s");
  ids.add("6vopR3ys8Kw");
  ids.add("uJ_1HMAGb4k");
  ids.add("MYSVMgRr6pw");
  ids.add("oWYp1xRPH5g");
  ids.add("qlGQoxzdwP4");
  ids.add("4ZHwu0uut3k");
  ids.add("b6dD-I7kJmM");
  ids.add("NDH1bGnNMjw");
  ids.add("rnqUBmd5xRo");
  ids.add("fJ5LaPyzaj0");
  ids.add("6teOmBuMxw4");
  ids.add("RBumgq5yVrA");

  // Show loader here
  progressBar.setVisibility(View.VISIBLE);
  final RxTube rxTube = YoutubeExampleApplication.get(this).getYouTube();
  videoSubscription = rxTube.create(new RxTube.Query<YouTube.Videos.List>() {
    @Override public YouTube.Videos.List create(YouTube youTube) throws Exception {
      final YouTube.Videos.List request = youTube.videos().list("snippet");
      request.setId(TextUtils.join(",", ids));
      return request;
    }
  }).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<VideoListResponse>() {
    @Override public void call(VideoListResponse response) {
      // Hide loader here.
      progressBar.setVisibility(View.GONE);

      listView.setAdapter(new SimpleYoutubeListAdapter(
          ListViewActivity.this, response.getItems()));
    }
  }, new Action1<Throwable>() {
    @Override public void call(Throwable throwable) {
      // Hide loader here.
      progressBar.setVisibility(View.GONE);
      Toast.makeText(
          ListViewActivity.this,
          "There was an error " + throwable, Toast.LENGTH_LONG).show();
    }
  });

  listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
      final Video video = (Video) parent.getItemAtPosition(position);
      PlayerUtil.showPlayer(ListViewActivity.this, video.getId());
    }
  });
}