mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-27 23:09:05 +00:00
[AB-xxx] fixing youtube sometimes not returning videos even if specified
This commit is contained in:
@@ -26,7 +26,7 @@ public class YoutubeSearchServiceBean implements YoutubeSearchService {
|
|||||||
@Override
|
@Override
|
||||||
public YoutubeVideo searchOneVideoForQuery(String query) {
|
public YoutubeVideo searchOneVideoForQuery(String query) {
|
||||||
try {
|
try {
|
||||||
YouTube.Search.List search = youTube.search().list("id,snippet");
|
YouTube.Search.List search = youTube.search().list("id");
|
||||||
search.setQ(query);
|
search.setQ(query);
|
||||||
search.setType("video");
|
search.setType("video");
|
||||||
search.setMaxResults(1L);
|
search.setMaxResults(1L);
|
||||||
@@ -35,6 +35,9 @@ public class YoutubeSearchServiceBean implements YoutubeSearchService {
|
|||||||
if(items.isEmpty()) {
|
if(items.isEmpty()) {
|
||||||
throw new YoutubeVideoNotFoundException();
|
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());
|
return youtubeVideoService.getVideoInfo(items.get(0).getId().getVideoId());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new YoutubeAPIException(e);
|
throw new YoutubeAPIException(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user