[AB-xxx] fixing youtube sometimes not returning videos even if specified

This commit is contained in:
Sheldan
2025-05-29 22:00:45 +02:00
parent db73071a71
commit 9f9c0612eb

View File

@@ -26,7 +26,7 @@ public class YoutubeSearchServiceBean implements YoutubeSearchService {
@Override
public YoutubeVideo searchOneVideoForQuery(String query) {
try {
YouTube.Search.List search = youTube.search().list("id,snippet");
YouTube.Search.List search = youTube.search().list("id");
search.setQ(query);
search.setType("video");
search.setMaxResults(1L);
@@ -35,6 +35,9 @@ public class YoutubeSearchServiceBean implements YoutubeSearchService {
if(items.isEmpty()) {
throw new YoutubeVideoNotFoundException();
}
if(items.stream().noneMatch(searchResult -> searchResult.getId().get("kind").equals("youtube#video"))) {
throw new YoutubeVideoNotFoundException();
}
return youtubeVideoService.getVideoInfo(items.get(0).getId().getVideoId());
} catch (IOException e) {
throw new YoutubeAPIException(e);