Skip to content

Commit f40fc0a

Browse files
committed
[YouTube] Add support for new crisis meta info action data
The new action data can return multiple contact actions instead of only one, which will be concatenated by a new line return. This commit fixes tests of the CrisisResources test class of YoutubeSearchExtractorTest.
1 parent 2a3c6f8 commit f40fc0a

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,40 @@ private static void getEmergencyOneboxRenderer(
171171
// usually an encouragement like "We are with you"
172172
final String title = getTextFromObjectOrThrow(r.getObject("title"), "title");
173173
// usually a phone number
174-
final String action = getTextFromObjectOrThrow(r.getObject("actionText"), "action");
174+
final String action;
175+
if (r.has("actionText")) {
176+
action = getTextFromObjectOrThrow(r.getObject("actionText"), "action");
177+
} else if (r.has("contacts")) {
178+
final JsonArray contacts = r.getArray("contacts");
179+
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
191+
stringBuilder.append(getTextFromObjectOrThrow(contacts.getObject(i)
192+
.getObject("actionText"), "contacts.actionText"));
193+
}
194+
195+
action = stringBuilder.toString();
196+
} else {
197+
action = null;
198+
}
175199
// usually details about the phone number
176200
final String details = getTextFromObjectOrThrow(r.getObject("detailsText"), "details");
177201
// usually the name of an association
178202
final String urlText = getTextFromObjectOrThrow(r.getObject("navigationText"),
179203
"urlText");
180204

181205
metaInfo.setTitle(title);
182-
metaInfo.setContent(new Description(details + "\n" + action, Description.PLAIN_TEXT));
206+
metaInfo.setContent(new Description(isNullOrEmpty(action)
207+
? details : details + "\n" + action, Description.PLAIN_TEXT));
183208
metaInfo.addUrlText(urlText);
184209

185210
// usually the webpage of the association

0 commit comments

Comments
 (0)