void refresh() throws IOException { Disposable disposable = // Observable.just(ytApi.playlistItems() .list(YOUTUBE_PLAYLIST_PART) .setPlaylistId(YOUTUBE_PLAYLIST_ID) .setPageToken(null) .setFields(YOUTUBE_PLAYLIST_FIELDS) .setMaxResults(YOUTUBE_PLAYLIST_MAX_RESULTS) .setKey(API_KEY) // ) .map(AbstractGoogleClientRequest::execute) .map(PlaylistItemListResponse::getItems) .flatMap(playlistItems -> Observable.fromIterable(playlistItems) .map(item -> item.getSnippet().getResourceId().getVideoId())) .toList() .map(ids -> ytApi.videos().list(YOUTUBE_VIDEOS_PART).setFields(YOUTUBE_VIDEOS_FIELDS) // .setKey(API_KEY).setId(TextUtils.join(",", ids)).execute()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnError( throwable -> Log.e(TAG, "accept() called with: throwable = [" + throwable + "]")) .doOnSuccess( response -> Log.d(TAG, "accept() called with: response = [" + response + "]")) .onErrorReturnItem(new VideoListResponse()) // Bad work around .doOnSuccess(liveData::setValue) .subscribe(); disposables.add(disposable); } }
/** Builds a new instance of {@link YouTube}. */ @Override public YouTube build() { return new YouTube(this); }
ChannelListResponse clr = youtube.channels() .list("contentDetails").setMine(true).execute(); PlaylistItemListResponse pilr = youtube.playlistItems() .list("id,contentDetails") .setPlaylistId(uploadsPlaylistId) VideoListResponse vlr = youtube.videos() .list("id,snippet,status") .setId(TextUtils.join(",", videoIds)).execute();
/** * @return url of thumbnail if the video is fully processed */ public static boolean checkIfProcessed(String videoId, YouTube youtube) { try { YouTube.Videos.List list = youtube.videos().list("processingDetails"); list.setId(videoId); VideoListResponse listResponse = list.execute(); List<Video> videos = listResponse.getItems(); if (videos.size() == 1) { Video video = videos.get(0); String status = video.getProcessingDetails().getProcessingStatus(); Log.e(TAG, String.format("Processing status of [%s] is [%s]", videoId, status)); if (status.equals(SUCCEEDED)) { return true; } } else { // can't find the video Log.e(TAG, String.format("Can't find video with ID [%s]", videoId)); return false; } } catch (IOException e) { Log.e(TAG, "Error fetching video metadata", e); } return false; } }
public List<SimpleResult> getPlayListItems(String playlistCode) { List<SimpleResult> playlist = new ArrayList<>(); try { YouTube.PlaylistItems.List playlistRequest = youtube.playlistItems().list("id,contentDetails,snippet"); playlistRequest.setPlaylistId(playlistCode); playlistRequest.setKey(search.getKey()); playlistRequest.setFields("items(contentDetails/videoId,snippet/title,snippet/publishedAt),nextPageToken,pageInfo"); String nextToken = ""; do { playlistRequest.setPageToken(nextToken); PlaylistItemListResponse playlistItemResult = playlistRequest.execute(); playlist.addAll(playlistItemResult.getItems().stream().map(playlistItem -> new SimpleResult(playlistItem.getContentDetails().getVideoId(), playlistItem.getSnippet().getTitle())).collect(Collectors.toList())); nextToken = playlistItemResult.getNextPageToken(); } while (nextToken != null); } catch (IOException e) { e.printStackTrace(); } return playlist; }
public YTSearch() { keyQueue = new LinkedList<>(); Collections.addAll(keyQueue, BotConfig.GOOGLE_API_KEY); youtube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), (HttpRequest request) -> { }).setApplicationName(BotConfig.BOT_NAME).build(); YouTube.Search.List tmp = null; try { tmp = youtube.search().list("id,snippet"); tmp.setOrder("relevance"); tmp.setVideoCategoryId("10"); } catch (IOException ex) { DiscordBot.LOGGER.error("Failed to initialize search: " + ex.toString()); } search = tmp; if (search != null) { search.setType("video"); search.setFields("items(id/kind,id/videoId,snippet/title)"); } setupNextKey(); }
YouTube.Channels.List channelLists = this.youTube.channels().list(CONTENT).setId(this.userInfo.getUserId()).setKey(this.youtubeConfig.getApiKey()); boolean tryAgain = false; do { channelLists = null; } else { channelLists = this.youTube.channels().list(CONTENT).setId(this.userInfo.getUserId()).setOauthToken(this.youtubeConfig.getApiKey()) .setPageToken(channelLists.getPageToken());
try { if (request == null) { request = this.youtube.activities().list("contentDetails") .setChannelId(userInfo.getUserId()) .setMaxResults(MAX_RESULTS) feed = request.execute(); } else { request = this.youtube.activities().list("contentDetails") .setChannelId(userInfo.getUserId()) .setMaxResults(MAX_RESULTS)
/** * Given a Youtube videoId, return the relevant Youtube Video object. * @param videoId videoId * @return List of Videos * @throws IOException */ List<Video> getVideoList(String videoId) throws IOException { VideoListResponse videosListResponse = this.youtube.videos().list("snippet,statistics") .setId(videoId) .setKey(config.getApiKey()) .execute(); if (videosListResponse.getItems().size() == 0) { LOGGER.debug("No Youtube videos found for videoId: {}", videoId); return new ArrayList<>(); } return videosListResponse.getItems(); }
YouTube.Search.List search = youtube.search().list( "id,snippet" );
playlistItemListResponse = mYouTubeDataApi.playlistItems() .list(YOUTUBE_PLAYLIST_PART) .setPlaylistId(playlistId) videoListResponse = mYouTubeDataApi.videos() .list(YOUTUBE_VIDEOS_PART) .setFields(YOUTUBE_VIDEOS_FIELDS)
@Override protected Void doInBackground(Void... voids) { YouTube youtube = new YouTube.Builder(transport, jsonFactory, credential).setApplicationName(Constants.APP_NAME) .build(); try { youtube.videos().update("snippet", updateVideo).execute(); } catch (UserRecoverableAuthIOException e) { startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION); } catch (IOException e) { Log.e(TAG, e.getMessage()); } return null; }
youtube.videos().insert("snippet,statistics,status", videoObjectDefiningMetadata, mediaContent);
List<Video> videosList; try { listVideosRequest = youtube.videos().list("id,snippet,status,player") .setId(prepareId(url)) .setKey(youtubeApikey);