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

The following examples show how to use com.google.api.services.youtube.model.SearchListResponse. 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: YoutubeConnector.java    From search-youtube with Apache License 2.0 5 votes vote down vote up
public List<VideoItem> search(String keywords) {

	        //setting keyword to query
			query.setQ(keywords);

	        //max results that should be returned
			query.setMaxResults(MAXRESULTS);

			try {

	            //executing prepared query and calling Youtube API
				SearchListResponse response = query.execute();

	            //retrieving list from response received
	            //getItems method returns a list from the response which is originally in the form of JSON
				List<SearchResult> results = response.getItems();

	            //list of type VideoItem for saving all data individually
				List<VideoItem> items = new ArrayList<VideoItem>();

				//check if result is found and call our setItemsList method
				if (results != null) {

					//iterator method returns a Iterator instance which can be used to iterate through all values in list
					items = setItemsList(results.iterator());
				}

				return items;

			} catch (IOException e) {

				//catch exception and print on console
				Log.d("YC", "Could not search: " + e);
				return null;
			}
		}
 
Example #3
Source File: GetYouTubeVideoBySearch.java    From SkyTube with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<CardData> getNextVideos() {
	setLastException(null);

	List<CardData> videosList = null;

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

			// communicate with YouTube
			SearchListResponse searchResponse = this.videosList.execute();

			// get videos
			List<SearchResult> searchResultList = searchResponse.getItems();
			if (searchResultList != null) {
				videosList = getVideosList(searchResultList);
			}

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

			// if nextPageToken is null, it means that there are no more videos
			if (nextPageToken == null)
				noMoreVideoPages = true;
		} catch (IOException ex) {
			setLastException(ex);
			Logger.e(this, "Error has occurred while getting Featured Videos:" + ex.getMessage(), ex);
		}
	}

	return videosList;
}
 
Example #4
Source File: SearchYouTube.java    From youtube-comment-suite with MIT License 4 votes vote down vote up
public void search(String pageToken, String type, String text, String locText, String locRadius, String order, int resultType) {
    runLater(() -> searching.setValue(true));
    try {
        String encodedText = URLEncoder.encode(text, "UTF-8");
        String searchType = types[resultType];

        if (pageToken.equals(emptyToken)) {
            pageToken = "";
        }

        searchList = youtubeApi.search().list("snippet")
                .setKey(FXMLSuite.getYouTubeApiKey())
                .setMaxResults(50L)
                .setPageToken(pageToken)
                .setQ(encodedText)
                .setType(type)
                .setOrder(order.toLowerCase());

        SearchListResponse sl;
        if (type.equals("Normal")) {
            logger.debug("Normal Search [key={},part=snippet,text={},type={},order={},token={}]",
                    FXMLSuite.getYouTubeApiKey(), encodedText, searchType, order.toLowerCase(), pageToken);

            sl = searchList.execute();
        } else {
            logger.debug("Location Search [key={},part=snippet,text={},loc={},radius={},type={},order={},token={}]",
                    FXMLSuite.getYouTubeApiKey(), encodedText, locText, locRadius, searchType, order.toLowerCase(), pageToken);

            sl = searchList.setLocation(locText)
                    .setLocationRadius(locRadius)
                    .execute();
        }

        this.pageToken = sl.getNextPageToken() == null ? emptyToken : sl.getNextPageToken();
        this.total = sl.getPageInfo().getTotalResults();

        logger.debug("Search [videos={}]", sl.getItems().size());
        for (SearchResult item : sl.getItems()) {
            logger.debug("Video [id={},author={},title={}]",
                    item.getId(),
                    item.getSnippet().getChannelTitle(),
                    item.getSnippet().getTitle());
            SearchYouTubeListItem view = new SearchYouTubeListItem(item, number++);
            runLater(() -> {
                resultsList.getItems().add(view);
                searchInfo.setText(String.format("Showing %s out of %s", resultsList.getItems().size(), total));
            });
        }
    } catch (IOException e) {
        logger.error(e);
        e.printStackTrace();
    }
    runLater(() -> {
        if (this.pageToken != null && !this.pageToken.equals(emptyToken)) {
            btnNextPage.setDisable(false);
        }
        searching.setValue(false);
    });
}