Skip to content

Commit fc533e4

Browse files
committed
Add debug logging to live chat polling
1 parent 81b39fa commit fc533e4

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsExtractor.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
1515
import org.schabi.newpipe.extractor.localization.Localization;
1616
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
17+
import org.schabi.newpipe.extractor.utils.ExtractorLogger;
1718
import org.schabi.newpipe.extractor.utils.JsonUtils;
1819
import org.schabi.newpipe.extractor.utils.Utils;
1920

@@ -29,6 +30,7 @@
2930
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
3031

3132
public class YoutubeCommentsExtractor extends CommentsExtractor {
33+
private static final String TAG = YoutubeCommentsExtractor.class.getSimpleName();
3234

3335
private static final String COMMENT_VIEW_MODEL_KEY = "commentViewModel";
3436
private static final String COMMENT_RENDERER_KEY = "commentRenderer";
@@ -65,6 +67,7 @@ public InfoItemsPage<CommentsInfoItem> getInitialPage()
6567
throws IOException, ExtractionException {
6668

6769
if (commentsDisabled && liveChatContinuation != null) {
70+
ExtractorLogger.d(TAG, "getInitialPage() routing to live chat");
6871
return fetchLiveChat(liveChatContinuation);
6972
}
7073

@@ -211,6 +214,7 @@ public InfoItemsPage<CommentsInfoItem> getPage(final Page page)
211214
if ("live_chat".equals(page.getUrl())
212215
|| (commentsDisabled && liveChatContinuation != null)) {
213216
isLiveStream = true;
217+
ExtractorLogger.d(TAG, "getPage() live chat detected, isLiveStream=true");
214218
return fetchLiveChat(page.getId());
215219
}
216220

@@ -418,6 +422,8 @@ private void findLiveChatContinuation(final JsonObject nextResponse) {
418422
private InfoItemsPage<CommentsInfoItem> fetchLiveChat(final String chatContinuation)
419423
throws IOException, ExtractionException {
420424
isLiveStream = true;
425+
ExtractorLogger.d(TAG, "fetchLiveChat() called with continuation={}",
426+
chatContinuation != null ? chatContinuation.substring(0, Math.min(30, chatContinuation.length())) : "null");
421427
final Localization localization = getExtractorLocalization();
422428
final byte[] json = JsonWriter.string(
423429
prepareDesktopJsonBuilder(localization, getExtractorContentCountry())
@@ -429,6 +435,7 @@ private InfoItemsPage<CommentsInfoItem> fetchLiveChat(final String chatContinuat
429435
.getBytes(StandardCharsets.UTF_8);
430436

431437
final String endpoint = "live_chat/" + (isLiveStream ? "get_live_chat" : "get_live_chat_replay");
438+
ExtractorLogger.d(TAG, "fetchLiveChat() using endpoint={} isLiveStream={}", endpoint, isLiveStream);
432439
final JsonObject result = getJsonPostResponse(endpoint, json, localization);
433440

434441
return extractLiveChatComments(result);
@@ -492,8 +499,11 @@ private InfoItemsPage<CommentsInfoItem> extractLiveChatComments(
492499
nextPage = null;
493500
}
494501

502+
ExtractorLogger.d(TAG, "extractLiveChatComments() extracted={} nextPage={}",
503+
collector.getItems().size(), nextPage != null);
495504
return new InfoItemsPage<>(collector, nextPage);
496505
} catch (final Exception e) {
506+
ExtractorLogger.e(TAG, "extractLiveChatComments() failed", e);
497507
return getInfoItemsPageForDisabledComments();
498508
}
499509
}

0 commit comments

Comments
 (0)