I have a specific playlist that contains 562 videos.
My goal is to get all the IDs of each video and put them on the List (Java).
I am using PlaylistItems: list and setMaxResults (50L) - the highest possible. Yes, in the end it returns me my 562 videos, but if I try to create a HashMap (no duplicates, each value is unique) based on the video id, it turns out that out of 562 videos, about 50 are duplicates.
I still cannot identify the pattern, if you do setMaxResults (49L) - then the number of takes will decrease by 1. If you do setMaxResults (48L) - then the number of takes will grow ...There is no setting setMaxResults (), the default is 5 - out of 562 videos with unique IDs, only ~ 340 will return at all ...
We get all the videos of the playlist
List<PlaylistItem> playlistItemList = new ArrayList(); try { String pageToken = ""; while (pageToken != null) { logger.info("pageToken: " + pageToken); YouTube.PlaylistItems.List youtubePlaylistItemsList = youtube.playlistItems().list("snippet"); youtubePlaylistItemsList.setPlaylistId("UUlatNLsHQYQ00TCT3Nfse6w"); youtubePlaylistItemsList.setMaxResults(50L); youtubePlaylistItemsList.setPageToken(pageToken); PlaylistItemListResponse playlistItemListResponse = youtubePlaylistItemsList.execute(); playlistItemList.addAll(playlistItemListResponse.getItems()); pageToken = playlistItemListResponse.getNextPageToken(); } } catch (IOException e) { logger.error("Error: ", e); }
playlistItemList.size() = 562.
Now let's select the number of unique video IDs
HashMap<String, String> realVideoIds = new HashMap<String, String>(); try { youtubeVideosList = youtube.videos().list("id,statistics,snippet"); for (int i = 0; i < playlistItemList.size(); i++) { if (realVideoIds.containsKey(playlistItemList.get(i).getSnippet().getResourceId().getVideoId())) { logger.info("getContentDetails: " + playlistItemList.get(i).getSnippet().getResourceId().getVideoId()); } realVideoIds.put(playlistItemList.get(i).getSnippet().getResourceId().getVideoId().trim(), playlistItemList.get(i).getSnippet().getTitle()); } logger.info("realVideoIds size: " + realVideoIds.size());
realVideoIds.size() = 512.
Total 562 != 512. As I wrote above, the smaller the MaxResults value, the greater the difference.
Thank you for your attention, I will be glad for any help =)