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");
}
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;
}
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);
}
}
Aggregations