本文整理汇总了Java中com.google.api.services.youtube.model.SearchListResponse类的典型用法代码示例。如果您正苦于以下问题:Java SearchListResponse类的具体用法?Java SearchListResponse怎么用?Java SearchListResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SearchListResponse类属于com.google.api.services.youtube.model包,在下文中一共展示了SearchListResponse类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResults
import com.google.api.services.youtube.model.SearchListResponse; //导入依赖的package包/类
public List<String> getResults(String query, int numresults)
{
List<String> urls = new ArrayList<>();
search.setQ(query);
search.setMaxResults((long)numresults);
SearchListResponse searchResponse;
try {
searchResponse = search.execute();
List<SearchResult> searchResultList = searchResponse.getItems();
searchResultList.stream().forEach((sr) -> {
urls.add(sr.getId().getVideoId());
});
} catch (IOException ex) {
SimpleLog.getLog("Youtube").fatal("Search failure: "+ex.toString());
return null;
}
return urls;
}
示例2: parse
import com.google.api.services.youtube.model.SearchListResponse; //导入依赖的package包/类
private static ArrayList<Map<String, String>> parse(SearchListResponse response) {
ResourceId rId;
ArrayList<Map<String, String>> output = new ArrayList<>();
for (SearchResult result : response.getItems()) {
SearchResultSnippet snippet = result.getSnippet();
rId = result.getId();
Map<String, String> element = new HashMap<String, String>();
element.put("title", snippet.getTitle());
element.put("url", "http://www.youtube.com/embed/" + rId.getVideoId());
element.put("thumbnail", snippet.getThumbnails().getDefault().getUrl());
element.put("description", snippet.getDescription());
element.put("channel", snippet.getChannelTitle());
element.put("datePublished", snippet.getPublishedAt().toString().substring(0, 10));
output.add(element);
System.out.println(element.toString());
}
return output;
}
示例3: handleCommand
import com.google.api.services.youtube.model.SearchListResponse; //导入依赖的package包/类
@Override
public void handleCommand(String sender, MessageEvent event, String command, String[] args) {
if (command.equals(".youtube") || command.equals(".yt")) {
// Perform search
String query = StringUtils.join(args, " ");
try {
YouTube.Search.List search = youtube.search().list("id,snippet");
search.setKey(SettingsManager.getInstance().getSettings().getYoutubeKey());
search.setQ(query);
search.setMaxResults(1L);
search.setType("video");
SearchListResponse searchListResponse = search.execute();
List<SearchResult> searchResults = searchListResponse.getItems();
if (searchResults != null) {
SearchResult firstResult = searchResults.get(0);
event.getBot().sendIRC().message(event.getChannel().getName(), formatSearchResult(firstResult));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例4: listByCandidate
import com.google.api.services.youtube.model.SearchListResponse; //导入依赖的package包/类
public List<Publication> listByCandidate(final Candidate candidate, final Date lastExecutionDate) throws Throwable{
final List<Publication> result = new ArrayList<Publication>();
try {
//create query
final String query = String.format("%s %s", candidate.getFullName(), candidate.getArabicFullName());
//create the request
final YouTube.Search.List searchRequest = createSearchRequest(query, new DateTime(lastExecutionDate));
//call youtube api
final SearchListResponse searchListResponse = searchRequest.execute();
//serialize response
for (SearchResult searchResult : searchListResponse.getItems()) {
result.add(new Publication(searchResult, candidate));
}
} catch (Throwable e) {
log.error(String.format("Exception when call Youtube API for candidate id=%s", candidate.getId()), e);
throw e;
}
return result;
}
示例5: nextToken
import com.google.api.services.youtube.model.SearchListResponse; //导入依赖的package包/类
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;
}
示例6: getYoutubeVideo
import com.google.api.services.youtube.model.SearchListResponse; //导入依赖的package包/类
/**
* This method uses the YouTube Data API to find the YouTube video best matching the query.
*
* @param query
* - the argument of a song request
* @return the YouTube ID of the video best matching the query
* @throws IOException
*/
private static String getYoutubeVideo(String query) throws IOException {
try {
String videoId = getYoutubeIdFromUrl(query);
if (videoId == null) {
YouTube youtube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(),
new HttpRequestInitializer() {
public void initialize(HttpRequest request) throws IOException {
}
}).setApplicationName("sourceradio").build();
YouTube.Search.List search = youtube.search().list("id");
search.setKey(properties.get("youtube key"));
search.setQ(query);
search.setType("video");
search.setFields("items(id)");
search.setMaxResults(1L);
SearchListResponse searchResponse = search.execute();
List<SearchResult> searchResultList = searchResponse.getItems();
if (searchResultList != null && searchResultList.size() > 0) {
videoId = searchResultList.get(0).getId().getVideoId();
}
}
return videoId;
} catch (IOException e) {
throw new IOException("Error: Failed to find YouTube video.", e);
}
}
示例7: search
import com.google.api.services.youtube.model.SearchListResponse; //导入依赖的package包/类
public List<VideoItem> search(String keywords){
// Setting number of search results
query.setMaxResults((long) 25);
query.setQ(keywords);
try{
SearchListResponse response = query.execute();
List<SearchResult> results = response.getItems();
List<VideoItem> items = new ArrayList<VideoItem>();
// Putting video information to items
for(SearchResult result:results){
VideoItem item = new VideoItem();
item.setId(result.getId().getVideoId());
item.setTitle(result.getSnippet().getTitle());
item.setDescription(result.getSnippet().getDescription());
item.setThumbnailURL(result.getSnippet().getThumbnails().getDefault().getUrl());
items.add(item);
}
return items;
}catch(IOException e){
return null;
}
}
示例8: onPostExecute
import com.google.api.services.youtube.model.SearchListResponse; //导入依赖的package包/类
@Override
protected void onPostExecute(SearchListResponse searchListResponse) {
pb.setVisibility(View.INVISIBLE);
if (searchListResponse == null)
return;
onQuery(searchListResponse);
}
示例9: onQuery
import com.google.api.services.youtube.model.SearchListResponse; //导入依赖的package包/类
private boolean onQuery(SearchListResponse result) {
if (result == null)
return false;
searchResultList.clear();
searchResultList.addAll(result.getItems());
adapter.notifyDataSetChanged();
return true;
}
示例10: processMessage
import com.google.api.services.youtube.model.SearchListResponse; //导入依赖的package包/类
@Override
public Optional<String> processMessage(
String from, String message, Matcher matcher, boolean fromRoom) {
String query = matcher.group(1);
try {
YouTube.Search.List search = youtube.search().list("id,snippet");
search.setKey(this.apiKey);
search.setQ(query);
search.setType("video");
search.setFields("items(id/kind,id/videoId,snippet/title,snippet)");
search.setMaxResults(1L);
SearchListResponse searchResponse = search.execute();
List<SearchResult> searchResultList = searchResponse.getItems();
if (searchResultList != null) {
SearchResult result = searchResultList.get(0);
ResourceId id = result.getId();
if (id.getKind().equals("youtube#video")) {
return Optional.of("http://www.youtube.com/watch?v=" + id.getVideoId());
}
} else {
return Optional.of("Sorry, no results for `" + query + "`!");
}
} catch (IOException ex) {
logger.error("Error searching YouTube", ex);
}
return Optional.empty();
}
示例11: loadInBackground
import com.google.api.services.youtube.model.SearchListResponse; //导入依赖的package包/类
@Override
public List<YouTubeVideo> loadInBackground() {
ArrayList<YouTubeVideo> items = new ArrayList<>();
try {
YouTube.Search.List searchList = youtube.search().list("id");
YouTube.Videos.List videosList = youtube.videos().list("id,contentDetails,statistics,snippet");
searchList.setKey(Config.YOUTUBE_API_KEY);
searchList.setType("video"); //TODO ADD PLAYLISTS SEARCH
searchList.setMaxResults(Config.NUMBER_OF_VIDEOS_RETURNED);
searchList.setFields("items(id/kind,id/videoId)");
videosList.setKey(Config.YOUTUBE_API_KEY);
videosList.setFields("items(id,contentDetails/duration,statistics/viewCount,snippet/title,snippet/thumbnails/default/url)");
//search
searchList.setQ(keywords);
SearchListResponse searchListResponse = searchList.execute();
List<SearchResult> searchResults = searchListResponse.getItems();
//find video list
videosList.setId(Utils.concatenateIDs(searchResults)); //save all ids from searchList list in order to find video list
VideoListResponse resp = videosList.execute();
List<Video> videoResults = resp.getItems();
for (Video video : videoResults) {
YouTubeVideo item = new YouTubeVideo();
item.setTitle(video.getSnippet().getTitle());
item.setThumbnailURL(video.getSnippet().getThumbnails().getDefault().getUrl());
item.setId(video.getId());
if (video.getStatistics() != null) {
BigInteger viewsNumber = video.getStatistics().getViewCount();
String viewsFormatted = NumberFormat.getIntegerInstance().format(viewsNumber) + " views";
item.setViewCount(viewsFormatted);
}
if (video.getContentDetails() != null) {
String isoTime = video.getContentDetails().getDuration();
String time = Utils.convertISO8601DurationToNormalTime(isoTime);
item.setDuration(time);
}
items.add(item);
}
} catch (IOException e) {
e.printStackTrace();
}
Log.d(TAG, "loadInBackground: return " + items.size());
return items;
}
示例12: doInBackground
import com.google.api.services.youtube.model.SearchListResponse; //导入依赖的package包/类
@Override
protected SearchListResponse doInBackground(String... params) {
return Search.search(params[0]);
}