Search in sources :

Example 1 with CaptionListResponse

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

the class Captions method listCaptions.

/**
     * Returns a list of caption tracks. (captions.listCaptions)
     *
     * @param videoId The videoId parameter instructs the API to return the
     * caption tracks for the video specified by the video id.
     * @throws IOException
     */
private static List<Caption> listCaptions(String videoId) throws IOException {
    // Call the YouTube Data API's captions.list method to
    // retrieve video caption tracks.
    CaptionListResponse captionListResponse = youtube.captions().list("snippet", videoId).execute();
    List<Caption> captions = captionListResponse.getItems();
    // Print information from the API response.
    System.out.println("\n================== Returned Caption Tracks ==================\n");
    CaptionSnippet snippet;
    for (Caption caption : captions) {
        snippet = caption.getSnippet();
        System.out.println("  - ID: " + caption.getId());
        System.out.println("  - Name: " + snippet.getName());
        System.out.println("  - Language: " + snippet.getLanguage());
        System.out.println("\n-------------------------------------------------------------\n");
    }
    return captions;
}
Also used : CaptionSnippet(com.google.api.services.youtube.model.CaptionSnippet) CaptionListResponse(com.google.api.services.youtube.model.CaptionListResponse) Caption(com.google.api.services.youtube.model.Caption)

Aggregations

Caption (com.google.api.services.youtube.model.Caption)1 CaptionListResponse (com.google.api.services.youtube.model.CaptionListResponse)1 CaptionSnippet (com.google.api.services.youtube.model.CaptionSnippet)1