Search in sources :

Example 1 with PlaylistListResponse

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

the class PlaylistLocalizations method getPlaylistLocalization.

/**
     * Returns localized metadata for a playlist 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 playlistId The id parameter specifies the playlist ID for the resource
     * that is being updated.
     * @param language The language of the localized metadata
     * @throws IOException
     */
private static void getPlaylistLocalization(String playlistId, String language) throws IOException {
    // Call the YouTube Data API's playlists.list method to retrieve playlists.
    PlaylistListResponse playlistListResponse = youtube.playlists().list("snippet").setId(playlistId).set("hl", language).execute();
    // Since the API request specified a unique playlist ID, the API
    // response should return exactly one playlist. If the response does
    // not contain a playlist, then the specified playlist ID was not found.
    List<Playlist> playlistList = playlistListResponse.getItems();
    if (playlistList.isEmpty()) {
        System.out.println("Can't find a playlist with ID: " + playlistId);
        return;
    }
    Playlist playlist = playlistList.get(0);
    // Print information from the API response.
    System.out.println("\n================== Playlist ==================\n");
    System.out.println("  - ID: " + playlist.getId());
    System.out.println("  - Title(" + language + "): " + playlist.getLocalizations().get(language).getTitle());
    System.out.println("  - Description(" + language + "): " + playlist.getLocalizations().get(language).getDescription());
    System.out.println("\n-------------------------------------------------------------\n");
}
Also used : Playlist(com.google.api.services.youtube.model.Playlist) PlaylistListResponse(com.google.api.services.youtube.model.PlaylistListResponse)

Example 2 with PlaylistListResponse

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

the class PlaylistLocalizations method listPlaylistLocalizations.

/**
     * Returns a list of localized metadata for a playlist.
     *
     * @param playlistId The id parameter specifies the playlist ID for the resource
     * that is being updated.
     * @throws IOException
     */
private static void listPlaylistLocalizations(String playlistId) throws IOException {
    // Call the YouTube Data API's playlists.list method to retrieve playlists.
    PlaylistListResponse playlistListResponse = youtube.playlists().list("snippet,localizations").setId(playlistId).execute();
    // Since the API request specified a unique playlist ID, the API
    // response should return exactly one playlist. If the response does
    // not contain a playlist, then the specified playlist ID was not found.
    List<Playlist> playlistList = playlistListResponse.getItems();
    if (playlistList.isEmpty()) {
        System.out.println("Can't find a playlist with ID: " + playlistId);
        return;
    }
    Playlist playlist = playlistList.get(0);
    Map<String, PlaylistLocalization> localizations = playlist.getLocalizations();
    // Print information from the API response.
    System.out.println("\n================== Playlist ==================\n");
    System.out.println("  - ID: " + playlist.getId());
    for (String language : localizations.keySet()) {
        System.out.println("  - Title(" + language + "): " + localizations.get(language).getTitle());
        System.out.println("  - Description(" + language + "): " + localizations.get(language).getDescription());
    }
    System.out.println("\n-------------------------------------------------------------\n");
}
Also used : Playlist(com.google.api.services.youtube.model.Playlist) PlaylistListResponse(com.google.api.services.youtube.model.PlaylistListResponse) PlaylistLocalization(com.google.api.services.youtube.model.PlaylistLocalization)

Example 3 with PlaylistListResponse

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

the class PlaylistLocalizations method setPlaylistLocalization.

/**
     * Updates a playlist's default language and sets its localized metadata.
     *
     * @param playlistId The id parameter specifies the playlist ID for the resource
     * that is being updated.
     * @param defaultLanguage The language of the playlist's default metadata
     * @param language The language of the localized metadata
     * @param title The localized title to be set
     * @param description The localized description to be set
     * @throws IOException
     */
private static void setPlaylistLocalization(String playlistId, String defaultLanguage, String language, String title, String description) throws IOException {
    // Call the YouTube Data API's playlists.list method to retrieve playlists.
    PlaylistListResponse playlistListResponse = youtube.playlists().list("snippet,localizations").setId(playlistId).execute();
    // Since the API request specified a unique playlist ID, the API
    // response should return exactly one playlist. If the response does
    // not contain a playlist, then the specified playlist ID was not found.
    List<Playlist> playlistList = playlistListResponse.getItems();
    if (playlistList.isEmpty()) {
        System.out.println("Can't find a playlist with ID: " + playlistId);
        return;
    }
    Playlist playlist = playlistList.get(0);
    // Modify playlist's default language and localizations properties.
    // Ensure that a value is set for the resource's snippet.defaultLanguage property.
    playlist.getSnippet().setDefaultLanguage(defaultLanguage);
    // Preserve any localizations already associated with the playlist. If the
    // playlist does not have any localizations, create a new array. Append the
    // provided localization to the list of localizations associated with the playlist.
    Map<String, PlaylistLocalization> localizations = playlist.getLocalizations();
    if (localizations == null) {
        localizations = new ArrayMap<String, PlaylistLocalization>();
        playlist.setLocalizations(localizations);
    }
    PlaylistLocalization playlistLocalization = new PlaylistLocalization();
    playlistLocalization.setTitle(title);
    playlistLocalization.setDescription(description);
    localizations.put(language, playlistLocalization);
    // Update the playlist resource by calling the playlists.update() method.
    Playlist playlistResponse = youtube.playlists().update("snippet,localizations", playlist).execute();
    // Print information from the API response.
    System.out.println("\n================== Updated Playlist ==================\n");
    System.out.println("  - ID: " + playlistResponse.getId());
    System.out.println("  - Default Language: " + playlistResponse.getSnippet().getDefaultLanguage());
    System.out.println("  - Title(" + language + "): " + playlistResponse.getLocalizations().get(language).getTitle());
    System.out.println("  - Description(" + language + "): " + playlistResponse.getLocalizations().get(language).getDescription());
    System.out.println("\n-------------------------------------------------------------\n");
}
Also used : Playlist(com.google.api.services.youtube.model.Playlist) PlaylistListResponse(com.google.api.services.youtube.model.PlaylistListResponse) PlaylistLocalization(com.google.api.services.youtube.model.PlaylistLocalization)

Example 4 with PlaylistListResponse

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

the class YouTubeAPIVersion3ServiceImpl method getMyPlaylistByTitle.

@Override
public Playlist getMyPlaylistByTitle(final String title) throws IOException {
    final String trimmedTitle = title.trim();
    boolean searchedAllPlaylist = false;
    Playlist playlist = null;
    String nextPageToken = null;
    while (!searchedAllPlaylist) {
        final PlaylistListResponse searchResult = getMyPlaylists(nextPageToken, 50);
        for (final Playlist p : searchResult.getItems()) {
            if (p.getSnippet().getTitle().trim().equals(trimmedTitle)) {
                playlist = p;
                break;
            }
        }
        nextPageToken = searchResult.getNextPageToken();
        searchedAllPlaylist = nextPageToken == null;
    }
    return playlist;
}
Also used : Playlist(com.google.api.services.youtube.model.Playlist) PlaylistListResponse(com.google.api.services.youtube.model.PlaylistListResponse)

Aggregations

Playlist (com.google.api.services.youtube.model.Playlist)4 PlaylistListResponse (com.google.api.services.youtube.model.PlaylistListResponse)4 PlaylistLocalization (com.google.api.services.youtube.model.PlaylistLocalization)2