本文整理汇总了Java中com.google.api.services.youtube.model.SearchResult类的典型用法代码示例。如果您正苦于以下问题:Java SearchResult类的具体用法?Java SearchResult怎么用?Java SearchResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SearchResult类属于com.google.api.services.youtube.model包,在下文中一共展示了SearchResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResults
import com.google.api.services.youtube.model.SearchResult; //导入依赖的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: concatenateIDs
import com.google.api.services.youtube.model.SearchResult; //导入依赖的package包/类
/**
* Concatenates provided ids in order to search for all of them at once and not in many iterations (slower)
*
* @param searchResults results acquired from search query
* @return concatenated ids
*/
public static String concatenateIDs(List<SearchResult> searchResults) {
StringBuilder contentDetails = new StringBuilder();
for (SearchResult result : searchResults) {
if(result!= null) {
if(result.getId() != null) {
String id = result.getId().getVideoId();
if (id != null) {
contentDetails.append(id);
contentDetails.append(",");
}
}
}
}
if (contentDetails.length() == 0) {
return null;
}
if (contentDetails.toString().endsWith(",")) {
contentDetails.setLength(contentDetails.length() - 1); //remove last ,
}
return contentDetails.toString();
}
示例3: concatenateIDs
import com.google.api.services.youtube.model.SearchResult; //导入依赖的package包/类
/**
* Concatenates provided ids in order to search for all of them at once and not in many iterations (slower)
*
* @param searchResults results acquired from search query
* @return concatenated ids
*/
public static String concatenateIDs(List<SearchResult> searchResults)
{
StringBuilder contentDetails = new StringBuilder();
for (SearchResult result : searchResults) {
if (result.getId() == null) {
continue;
}
String id = result.getId().getVideoId();
if (id != null) {
contentDetails.append(id);
contentDetails.append(",");
}
}
if (contentDetails.length() == 0) {
return null;
}
if (contentDetails.toString().endsWith(",")) {
contentDetails.setLength(contentDetails.length() - 1); // remove last
}
return contentDetails.toString();
}
示例4: concatenateIDs
import com.google.api.services.youtube.model.SearchResult; //导入依赖的package包/类
/**
* Concatenates provided ids in order to search for all of them at once and not in many iterations (slower)
*
* @param searchResults results acquired from search query
* @return concatenated ids
*/
public static String concatenateIDs(List<SearchResult> searchResults) {
StringBuilder contentDetails = new StringBuilder();
for (SearchResult result : searchResults) {
String id = result.getId().getVideoId();
if (id != null) {
contentDetails.append(id);
contentDetails.append(",");
}
}
if (contentDetails.length() == 0) {
return null;
}
if (contentDetails.toString().endsWith(",")) {
contentDetails.setLength(contentDetails.length() - 1); //remove last ,
}
return contentDetails.toString();
}
示例5: parse
import com.google.api.services.youtube.model.SearchResult; //导入依赖的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;
}
示例6: fetch
import com.google.api.services.youtube.model.SearchResult; //导入依赖的package包/类
@Override
public Video fetch(String query) {
if (!isInitialized()) {
init();
}
YouTube.Search.List search = searchConfig(query);
Video video = null;
try {
List<SearchResult> searchResultList = search.execute().getItems();
if (searchResultList != null) {
String videoId = getVideoId(searchResultList.iterator());
video = new Video(videoId);
}
} catch (IOException e) {
logger.error("Unable to get video for query %s", query);
}
return video;
}
示例7: handleCommand
import com.google.api.services.youtube.model.SearchResult; //导入依赖的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();
}
}
}
示例8: parseSongResult
import com.google.api.services.youtube.model.SearchResult; //导入依赖的package包/类
private ArrayList<SongResult> parseSongResult(Iterator<SearchResult> iteratorSearchResults, String query) {
ArrayList<SongResult> t = new ArrayList<SongResult>();
if (!iteratorSearchResults.hasNext()) {
if (HomescreenActivity.debugMode) {
Log.d("Play", "No results");
}
}
while (iteratorSearchResults.hasNext()) {
SearchResult singleVideo = iteratorSearchResults.next();
ResourceId rId = singleVideo.getId();
// Confirm that the result represents a video. Otherwise, the
// item will not contain a video ID.
if (rId.getKind().equals("youtube#video")) {
t.add(new SongResult(singleVideo.getSnippet().getTitle(), rtspURL(rId.getVideoId())));
}
}
return t;
}
示例9: getView
import com.google.api.services.youtube.model.SearchResult; //导入依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Holder holder;
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.item_search, null);
holder = new Holder();
holder.thumIv = (ImageView) convertView.findViewById(R.id.video_thm);
holder.titleTv = (TextView) convertView.findViewById(R.id.video_title);
holder.descriptionTv = (TextView) convertView.findViewById(R.id.video_description);
convertView.setTag(holder);
} else {
holder = (Holder) convertView.getTag();
}
SearchResult result = getItem(position);
holder.titleTv.setText(result.getSnippet().getTitle());
holder.descriptionTv.setText(result.getSnippet().getDescription());
ImageLoaderUtil.getImageLoader().displayImage(result.getSnippet().getThumbnails().getDefault().getUrl(), holder.thumIv, options);
return convertView;
}
示例10: listByCandidate
import com.google.api.services.youtube.model.SearchResult; //导入依赖的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;
}
示例11: prettyPrint
import com.google.api.services.youtube.model.SearchResult; //导入依赖的package包/类
private static void prettyPrint(Iterator<SearchResult> iteratorSearchResults, String query) {
//
// " First " + NUMBER_OF_VIDEOS_RETURNED + " videos for search on \"" + query + "\".");
//
// if (!iteratorSearchResults.hasNext()) {
// System.out.println(" There aren't any results for your query.");
// }
while (iteratorSearchResults.hasNext()) {
SearchResult singleVideo = iteratorSearchResults.next();
ResourceId rId = singleVideo.getId();
// Confirm that the result represents a video. Otherwise, the
// item will not contain a video ID.
if (rId.getKind().equals("youtube#video")) {
Thumbnail thumbnail = singleVideo.getSnippet().getThumbnails().getDefault();
System.out.println(" Video Id" + rId.getVideoId());
System.out.println(" Title: " + singleVideo.getSnippet().getTitle());
System.out.println(" Thumbnail: " + thumbnail.getUrl());
System.out.println("\n-------------------------------------------------------------\n");
}
}
}
示例12: itemsToMap
import com.google.api.services.youtube.model.SearchResult; //导入依赖的package包/类
private List<YouTubeData> itemsToMap(List<SearchResult> playlistItemList) {
List<YouTubeData> result = new ArrayList<YouTubeData>();
// convert the list into hash maps of video info
for (SearchResult playlistItem : playlistItemList) {
YouTubeData map = new YouTubeData();
if (searchChannels)
map.mChannel = playlistItem.getId().getChannelId();
else
map.mVideo = playlistItem.getId().getVideoId();
map.mTitle = playlistItem.getSnippet().getTitle();
map.mDescription = Utils.condenseWhiteSpace(playlistItem.getSnippet().getDescription());
map.mThumbnail = thumbnailURL(playlistItem.getSnippet().getThumbnails());
result.add(map);
}
return result;
}
示例13: getYoutubeVideo
import com.google.api.services.youtube.model.SearchResult; //导入依赖的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);
}
}
示例14: getVideoId
import com.google.api.services.youtube.model.SearchResult; //导入依赖的package包/类
/**
* Get video ID
* @param iteratorSearchResults
*/
private String getVideoId(Iterator<SearchResult> iteratorSearchResults) {
String id = "";
while (iteratorSearchResults.hasNext()) {
SearchResult singleVideo = iteratorSearchResults.next();
ResourceId rId = singleVideo.getId();
// Confirm that the result represents a video. Otherwise, the
// item will not contain a video ID.
if (rId.getKind().equals("youtube#video")) {
id = rId.getVideoId();
}
}
return id;
}
示例15: formatSearchResult
import com.google.api.services.youtube.model.SearchResult; //导入依赖的package包/类
private String formatSearchResult(SearchResult result) {
StringBuilder response = new StringBuilder();
response.append(Colors.BOLD).append("Title: ").append(Colors.NORMAL).append(result.getSnippet().getTitle()).append(" ");
response.append(Colors.BOLD).append("Channel: ").append(Colors.NORMAL).append(result.getSnippet().getChannelTitle()).append(" ");
response.append(Colors.BOLD).append("URL: ").append(Colors.NORMAL).append("https://www.youtube.com/watch?v=").append(result.getId().getVideoId());
return response.toString();
}