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

The following examples show how to use com.google.api.services.youtube.model.ResourceId. 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: YouTubeObject.java    From youtube-comment-suite with MIT License 5 votes vote down vote up
/**
 * @return id of video, channel, or playlist
 */
protected static String getIdFromResource(ResourceId resourceId) {
    if (resourceId.getVideoId() != null) {
        return resourceId.getVideoId();
    } else if (resourceId.getChannelId() != null) {
        return resourceId.getChannelId();
    } else if (resourceId.getPlaylistId() != null) {
        return resourceId.getPlaylistId();
    }
    return null;
}
 
Example #2
Source File: YoutubeConnector.java    From search-youtube with Apache License 2.0 4 votes vote down vote up
private static List<VideoItem> setItemsList(Iterator<SearchResult> iteratorSearchResults) {

	        //temporary list to store the raw data from the returned results
			List<VideoItem> tempSetItems = new ArrayList<>();

	        //if no result then printing appropriate output
			if (!iteratorSearchResults.hasNext()) {
				System.out.println(" There aren't any results for your query.");
			}

	        //iterating through all search results
	        //hasNext() method returns true until it has no elements left to iterate
			while (iteratorSearchResults.hasNext()) {

	            //next() method returns single instance of current video item
	            //and returns next item everytime it is called
	            //SearchResult is Youtube's custom result type which can be used to retrieve data of each video item
				SearchResult singleVideo = iteratorSearchResults.next();

				//getId() method returns the resource ID of one video in the result obtained
				ResourceId rId = singleVideo.getId();

	            // Confirm that the result represents a video. Otherwise, the
	            // item will not contain a video ID.
	            //getKind() returns which type of resource it is which can be video, playlist or channel
				if (rId.getKind().equals("youtube#video")) {

	                //object of VideoItem class that can be added to array list
					VideoItem item = new VideoItem();

	                //getting High quality thumbnail object
	                //URL of thumbnail is in the heirarchy snippet/thumbnails/high/url
					Thumbnail thumbnail = singleVideo.getSnippet().getThumbnails().getHigh();

	                //retrieving title,description,thumbnail url, id from the heirarchy of each resource
	                //Video ID - id/videoId
	                //Title - snippet/title
	                //Description - snippet/description
	                //Thumbnail - snippet/thumbnails/high/url
					item.setId(singleVideo.getId().getVideoId());
					item.setTitle(singleVideo.getSnippet().getTitle());
					item.setDescription(singleVideo.getSnippet().getDescription());
					item.setThumbnailURL(thumbnail.getUrl());

	                //adding one Video item to temporary array list
					tempSetItems.add(item);

	                //for debug purpose printing one by one details of each Video that was found
					System.out.println(" Video Id" + rId.getVideoId());
					System.out.println(" Title: " + singleVideo.getSnippet().getTitle());
					System.out.println(" Thumbnail: " + thumbnail.getUrl());
					System.out.println(" Description: "+ singleVideo.getSnippet().getDescription());
					System.out.println("\n-------------------------------------------------------------\n");
				}
			}
			return tempSetItems;
		}
 
Example #3
Source File: YouTubeObject.java    From youtube-comment-suite with MIT License 2 votes vote down vote up
/**
 * Constructor for SearchResult where search results could be of any type (video, channel, playlist)
 *
 * @param id       resourceId from {@link com.google.api.services.youtube.model.SearchResult}
 * @param title    video title, playlist name, channel name
 * @param thumbUrl url of thumbnail, profile picture
 */
public YouTubeObject(ResourceId id, String title, String thumbUrl) {
    this.id = getIdFromResource(id);
    this.title = title;
    this.thumbUrl = thumbUrl;
}