Fix yt list bug

pull/541/head
okjack 1 year ago
parent d093a26802
commit 0e08e97f45
  1. 26
      youtube/src/main/java/com/github/kiulian/downloader/parser/ParserImpl.java

@ -83,17 +83,17 @@ public class ParserImpl implements Parser {
private VideoInfo parseVideoAndroid(String videoId, YoutubeCallback<VideoInfo> callback) throws YoutubeException { private VideoInfo parseVideoAndroid(String videoId, YoutubeCallback<VideoInfo> callback) throws YoutubeException {
String url = "https://youtubei.googleapis.com/youtubei/v1/player?key=" + ANDROID_APIKEY; String url = "https://youtubei.googleapis.com/youtubei/v1/player?key=" + ANDROID_APIKEY;
String body = "{" + String body = "{" +
" \"videoId\": \"" + videoId + "\"," + " \"videoId\": \"" + videoId + "\"," +
" \"context\": {" + " \"context\": {" +
" \"client\": {" + " \"client\": {" +
" \"hl\": \"en\"," + " \"hl\": \"en\"," +
" \"gl\": \"US\"," + " \"gl\": \"US\"," +
" \"clientName\": \"ANDROID_TESTSUITE\"," + " \"clientName\": \"ANDROID_TESTSUITE\"," +
" \"clientVersion\": \"1.9\"," + " \"clientVersion\": \"1.9\"," +
" \"androidSdkVersion\": 31" + " \"androidSdkVersion\": 31" +
" }" + " }" +
" }" + " }" +
"}"; "}";
RequestWebpage request = new RequestWebpage(url, "POST", body).header("Content-Type", "application/json"); RequestWebpage request = new RequestWebpage(url, "POST", body).header("Content-Type", "application/json");
Response<String> response = downloader.downloadWebpage(request); Response<String> response = downloader.downloadWebpage(request);
if (!response.ok()) { if (!response.ok()) {
@ -424,11 +424,11 @@ public class ParserImpl implements Parser {
} }
String html = response.data(); String html = response.data();
try { try {
JsonObject content; JsonObject content = new JsonObject();
JsonObject jsonResponse = JsonParser.parseString(html).getAsJsonObject(); JsonObject jsonResponse = JsonParser.parseString(html).getAsJsonObject();
if (jsonResponse.has("continuationContents")) { if (jsonResponse.has("continuationContents")) {
content = jsonResponse.getAsJsonObject("continuationContents").getAsJsonObject("playlistVideoListContinuation"); content = jsonResponse.getAsJsonObject("continuationContents").getAsJsonObject("playlistVideoListContinuation");
} else { } else if (jsonResponse.has("onResponseReceivedActions")) {
content = jsonResponse.getAsJsonArray("onResponseReceivedActions").get(0).getAsJsonObject().getAsJsonObject("appendContinuationItemsAction"); content = jsonResponse.getAsJsonArray("onResponseReceivedActions").get(0).getAsJsonObject().getAsJsonObject("appendContinuationItemsAction");
} }
populatePlaylist(content, videos, clientVersion); populatePlaylist(content, videos, clientVersion);

Loading…
Cancel
Save