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); } }
/** * @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; } }
/** * 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(); }
.list("id,snippet,status") .setId(TextUtils.join(",", videoIds)).execute();
try { videoListResponse = mYouTubeDataApi.videos() .list(YOUTUBE_VIDEOS_PART) .setFields(YOUTUBE_VIDEOS_FIELDS) .setKey(ApiKey.YOUTUBE_API_KEY)
List<Video> videosList; try { listVideosRequest = youtube.videos().list("id,snippet,status,player") .setId(prepareId(url)) .setKey(youtubeApikey);