Search in sources :

Example 6 with Playlist

use of com.google.api.services.youtube.model.Playlist 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 7 with Playlist

use of com.google.api.services.youtube.model.Playlist 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)

Example 8 with Playlist

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

the class YouTubeV3PublicationServiceImpl method retract.

private void retract(final String seriesTitle, final String episodeName) throws Exception {
    final List<SearchResult> items = youTubeService.searchMyVideos(truncateTitleToMaxFieldLength(episodeName, false), null, 1).getItems();
    if (!items.isEmpty()) {
        final String videoId = items.get(0).getId().getVideoId();
        if (seriesTitle != null) {
            final Playlist playlist = youTubeService.getMyPlaylistByTitle(truncateTitleToMaxFieldLength(seriesTitle, true));
            youTubeService.removeVideoFromPlaylist(playlist.getId(), videoId);
        }
        youTubeService.removeMyVideo(videoId);
    }
}
Also used : Playlist(com.google.api.services.youtube.model.Playlist) SearchResult(com.google.api.services.youtube.model.SearchResult)

Aggregations

Playlist (com.google.api.services.youtube.model.Playlist)8 PlaylistListResponse (com.google.api.services.youtube.model.PlaylistListResponse)4 PlaylistLocalization (com.google.api.services.youtube.model.PlaylistLocalization)2 Video (com.google.api.services.youtube.model.Video)2 File (java.io.File)2 PlaylistItem (com.google.api.services.youtube.model.PlaylistItem)1 PlaylistSnippet (com.google.api.services.youtube.model.PlaylistSnippet)1 PlaylistStatus (com.google.api.services.youtube.model.PlaylistStatus)1 SearchResult (com.google.api.services.youtube.model.SearchResult)1 URL (java.net.URL)1 Date (java.util.Date)1 Test (org.junit.Test)1 JobImpl (org.opencastproject.job.api.JobImpl)1 MediaPackage (org.opencastproject.mediapackage.MediaPackage)1 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)1 PublicationException (org.opencastproject.publication.api.PublicationException)1 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1