Skip to content

Commit d4e6d22

Browse files
committed
[YouTube] Improve meta info code for review
1 parent 74bf000 commit d4e6d22

1 file changed

Lines changed: 10 additions & 17 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeMetaInfoHelper.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -170,41 +170,34 @@ private static void getEmergencyOneboxRenderer(
170170

171171
// usually an encouragement like "We are with you"
172172
final String title = getTextFromObjectOrThrow(r.getObject("title"), "title");
173+
173174
// usually a phone number
174-
final String action;
175+
final String action; // this variable is expected to start with "\n"
175176
if (r.has("actionText")) {
176-
action = getTextFromObjectOrThrow(r.getObject("actionText"), "action");
177+
action = "\n" + getTextFromObjectOrThrow(r.getObject("actionText"), "action");
177178
} else if (r.has("contacts")) {
178179
final JsonArray contacts = r.getArray("contacts");
179180
final StringBuilder stringBuilder = new StringBuilder();
180-
int i = 0;
181-
final int contactsSize = contacts.size();
182-
if (contactsSize != 0) {
183-
// Loop over contacts item from the first contact to the last one, if there is
184-
// not only one, in order to not add an unneeded line return
185-
for (; i < contactsSize - 1; i++) {
186-
stringBuilder.append(getTextFromObjectOrThrow(contacts.getObject(i)
187-
.getObject("actionText"), "contacts.actionText"));
188-
stringBuilder.append("\n");
189-
}
190-
// Add the latest contact without an extra line return
181+
// Loop over contacts item from the first contact to the last one
182+
for (int i = 0; i < contacts.size(); i++) {
183+
stringBuilder.append("\n");
191184
stringBuilder.append(getTextFromObjectOrThrow(contacts.getObject(i)
192185
.getObject("actionText"), "contacts.actionText"));
193186
}
194-
195187
action = stringBuilder.toString();
196188
} else {
197-
action = null;
189+
action = "";
198190
}
191+
199192
// usually details about the phone number
200193
final String details = getTextFromObjectOrThrow(r.getObject("detailsText"), "details");
194+
201195
// usually the name of an association
202196
final String urlText = getTextFromObjectOrThrow(r.getObject("navigationText"),
203197
"urlText");
204198

205199
metaInfo.setTitle(title);
206-
metaInfo.setContent(new Description(isNullOrEmpty(action)
207-
? details : details + "\n" + action, Description.PLAIN_TEXT));
200+
metaInfo.setContent(new Description(details + action, Description.PLAIN_TEXT));
208201
metaInfo.addUrlText(urlText);
209202

210203
// usually the webpage of the association

0 commit comments

Comments
 (0)