Search in sources :

Example 6 with VideoListResponse

use of com.google.api.services.youtube.model.VideoListResponse in project opencast by opencast.

the class YouTubeAPIVersion3ServiceImpl method getVideoById.

@Override
public Video getVideoById(final String videoId) throws IOException {
    final YouTube.Videos.List search = youTube.videos().list("id,snippet");
    search.setId(videoId);
    search.setFields("items(id,kind,snippet),nextPageToken,pageInfo,prevPageToken,tokenPagination");
    final VideoListResponse response = execute(search);
    return response.getItems().isEmpty() ? null : response.getItems().get(0);
}
Also used : VideoListResponse(com.google.api.services.youtube.model.VideoListResponse)

Example 7 with VideoListResponse

use of com.google.api.services.youtube.model.VideoListResponse in project api-samples by youtube.

the class VideoLocalizations method getVideoLocalization.

/**
 * Returns localized metadata for a video in a selected language.
 * If the localized text is not available in the requested language,
 * this method will return text in the default language.
 *
 * @param videoId The id parameter specifies the video ID for the resource
 * that is being updated.
 * @param language The language of the localized metadata
 * @throws IOException
 */
private static void getVideoLocalization(String videoId, String language) throws IOException {
    // Call the YouTube Data API's videos.list method to retrieve videos.
    VideoListResponse videoListResponse = youtube.videos().list("snippet").setId(videoId).set("hl", language).execute();
    // Since the API request specified a unique video ID, the API
    // response should return exactly one video. If the response does
    // not contain a video, then the specified video ID was not found.
    List<Video> videoList = videoListResponse.getItems();
    if (videoList.isEmpty()) {
        System.out.println("Can't find a video with ID: " + videoId);
        return;
    }
    Video video = videoList.get(0);
    // Print information from the API response.
    System.out.println("\n================== Video ==================\n");
    System.out.println("  - ID: " + video.getId());
    System.out.println("  - Title(" + language + "): " + video.getLocalizations().get(language).getTitle());
    System.out.println("  - Description(" + language + "): " + video.getLocalizations().get(language).getDescription());
    System.out.println("\n-------------------------------------------------------------\n");
}
Also used : Video(com.google.api.services.youtube.model.Video) VideoListResponse(com.google.api.services.youtube.model.VideoListResponse)

Aggregations

VideoListResponse (com.google.api.services.youtube.model.VideoListResponse)7 Video (com.google.api.services.youtube.model.Video)6 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)2 YouTube (com.google.api.services.youtube.YouTube)2 VideoLocalization (com.google.api.services.youtube.model.VideoLocalization)2 IOException (java.io.IOException)2 Credential (com.google.api.client.auth.oauth2.Credential)1 HttpRequest (com.google.api.client.http.HttpRequest)1 HttpRequestInitializer (com.google.api.client.http.HttpRequestInitializer)1 Joiner (com.google.api.client.util.Joiner)1 SearchListResponse (com.google.api.services.youtube.model.SearchListResponse)1 SearchResult (com.google.api.services.youtube.model.SearchResult)1 VideoSnippet (com.google.api.services.youtube.model.VideoSnippet)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1