|
15 | 15 | import org.schabi.newpipe.extractor.exceptions.ParsingException; |
16 | 16 | import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; |
17 | 17 | import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; |
| 18 | +import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper; |
18 | 19 | import org.schabi.newpipe.extractor.utils.JsonUtils; |
19 | 20 | import org.schabi.newpipe.extractor.utils.Parser; |
20 | 21 |
|
@@ -46,11 +47,9 @@ public YoutubeCommentsExtractor(StreamingService service, ListLinkHandler uiHand |
46 | 47 |
|
47 | 48 | @Override |
48 | 49 | public InfoItemsPage<CommentsInfoItem> getInitialPage() throws IOException, ExtractionException { |
49 | | - final String commentsTokenInside; |
50 | | - if (responseBody.contains("commentSectionRenderer")) { |
| 50 | + String commentsTokenInside = findValue(responseBody, "sectionListRenderer", "}"); |
| 51 | + if (!commentsTokenInside.contains("continuation\":\"")) { |
51 | 52 | commentsTokenInside = findValue(responseBody, "commentSectionRenderer", "}"); |
52 | | - } else { |
53 | | - commentsTokenInside = findValue(responseBody, "sectionListRenderer", "}"); |
54 | 53 | } |
55 | 54 | final String commentsToken = findValue(commentsTokenInside, "continuation\":\"", "\""); |
56 | 55 | return getPage(getNextPage(commentsToken)); |
@@ -133,7 +132,7 @@ public void onFetchPage(@Nonnull Downloader downloader) throws IOException, Extr |
133 | 132 | final Map<String, List<String>> requestHeaders = new HashMap<>(); |
134 | 133 | requestHeaders.put("User-Agent", singletonList(USER_AGENT)); |
135 | 134 | final Response response = downloader.get(getUrl(), requestHeaders, getExtractorLocalization()); |
136 | | - responseBody = response.responseBody(); |
| 135 | + responseBody = YoutubeParsingHelper.unescapeDocument(response.responseBody()); |
137 | 136 | ytClientVersion = findValue(responseBody, "INNERTUBE_CONTEXT_CLIENT_VERSION\":\"", "\""); |
138 | 137 | ytClientName = Parser.matchGroup1(YT_CLIENT_NAME_PATTERN, responseBody); |
139 | 138 | } |
@@ -163,16 +162,9 @@ private String getDataString(Map<String, String> params) throws UnsupportedEncod |
163 | 162 | return result.toString(); |
164 | 163 | } |
165 | 164 |
|
166 | | - private String findValue(String doc, String start, String end) { |
167 | | - final String unescaped = doc |
168 | | - .replaceAll("\\\\x22", "\"") |
169 | | - .replaceAll("\\\\x7b", "{") |
170 | | - .replaceAll("\\\\x7d", "}") |
171 | | - .replaceAll("\\\\x5b", "[") |
172 | | - .replaceAll("\\\\x5d", "]"); |
173 | | - |
174 | | - final int beginIndex = unescaped.indexOf(start) + start.length(); |
175 | | - final int endIndex = unescaped.indexOf(end, beginIndex); |
176 | | - return unescaped.substring(beginIndex, endIndex); |
| 165 | + private String findValue(final String doc, final String start, final String end) { |
| 166 | + final int beginIndex = doc.indexOf(start) + start.length(); |
| 167 | + final int endIndex = doc.indexOf(end, beginIndex); |
| 168 | + return doc.substring(beginIndex, endIndex); |
177 | 169 | } |
178 | 170 | } |
0 commit comments