From d4e6d22e64847bb6d402a0502818f4c6d260a0b0 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sat, 20 Apr 2024 11:43:08 +0200 Subject: [PATCH] [YouTube] Improve meta info code for review --- .../youtube/YoutubeMetaInfoHelper.java | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeMetaInfoHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeMetaInfoHelper.java index 48587e0cb..214a13c40 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeMetaInfoHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeMetaInfoHelper.java @@ -170,41 +170,34 @@ public final class YoutubeMetaInfoHelper { // usually an encouragement like "We are with you" final String title = getTextFromObjectOrThrow(r.getObject("title"), "title"); + // usually a phone number - final String action; + final String action; // this variable is expected to start with "\n" if (r.has("actionText")) { - action = getTextFromObjectOrThrow(r.getObject("actionText"), "action"); + action = "\n" + getTextFromObjectOrThrow(r.getObject("actionText"), "action"); } else if (r.has("contacts")) { final JsonArray contacts = r.getArray("contacts"); final StringBuilder stringBuilder = new StringBuilder(); - int i = 0; - final int contactsSize = contacts.size(); - if (contactsSize != 0) { - // Loop over contacts item from the first contact to the last one, if there is - // not only one, in order to not add an unneeded line return - for (; i < contactsSize - 1; i++) { - stringBuilder.append(getTextFromObjectOrThrow(contacts.getObject(i) - .getObject("actionText"), "contacts.actionText")); - stringBuilder.append("\n"); - } - // Add the latest contact without an extra line return + // Loop over contacts item from the first contact to the last one + for (int i = 0; i < contacts.size(); i++) { + stringBuilder.append("\n"); stringBuilder.append(getTextFromObjectOrThrow(contacts.getObject(i) .getObject("actionText"), "contacts.actionText")); } - action = stringBuilder.toString(); } else { - action = null; + action = ""; } + // usually details about the phone number final String details = getTextFromObjectOrThrow(r.getObject("detailsText"), "details"); + // usually the name of an association final String urlText = getTextFromObjectOrThrow(r.getObject("navigationText"), "urlText"); metaInfo.setTitle(title); - metaInfo.setContent(new Description(isNullOrEmpty(action) - ? details : details + "\n" + action, Description.PLAIN_TEXT)); + metaInfo.setContent(new Description(details + action, Description.PLAIN_TEXT)); metaInfo.addUrlText(urlText); // usually the webpage of the association