mirror of
https://github.com/JonasunderscoreJones/ZtereoMUSIC.git
synced 2025-10-25 13:39:19 +02:00
fix: #9 solved by checking if there are any results before parsing the json
This commit is contained in:
parent
bdbf2b44d5
commit
7962ebec0c
1 changed files with 6 additions and 3 deletions
|
|
@ -25,11 +25,14 @@ public class YoutubeSearch {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonPath path = JsonPath.parse("items[0].id.videoId");
|
JsonPath resultsNumberPath = JsonPath.parse("pageInfo.totalResults");
|
||||||
|
JsonPath videoPath = JsonPath.parse("items[0].id.videoId");
|
||||||
|
|
||||||
//todo: actually check if there is a response before parsing directly to the response + get the music-related one with most views
|
|
||||||
try {
|
try {
|
||||||
return Optional.ofNullable(JSON.parse(jsonResponse).query(path).asString());
|
int results = JSON.parse(jsonResponse).query(resultsNumberPath).asInt();
|
||||||
|
if (results == 0) return Optional.empty();
|
||||||
|
|
||||||
|
return Optional.ofNullable(JSON.parse(jsonResponse).query(videoPath).asString());
|
||||||
} catch (JsonSyntaxException e) {
|
} catch (JsonSyntaxException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue