mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2024-12-13 05:40:34 +05:30
[YouTube] Improve meta info code for review
This commit is contained in:
parent
74bf000473
commit
d4e6d22e64
@ -170,41 +170,34 @@ public final class YoutubeMetaInfoHelper {
|
|||||||
|
|
||||||
// usually an encouragement like "We are with you"
|
// usually an encouragement like "We are with you"
|
||||||
final String title = getTextFromObjectOrThrow(r.getObject("title"), "title");
|
final String title = getTextFromObjectOrThrow(r.getObject("title"), "title");
|
||||||
|
|
||||||
// usually a phone number
|
// usually a phone number
|
||||||
final String action;
|
final String action; // this variable is expected to start with "\n"
|
||||||
if (r.has("actionText")) {
|
if (r.has("actionText")) {
|
||||||
action = getTextFromObjectOrThrow(r.getObject("actionText"), "action");
|
action = "\n" + getTextFromObjectOrThrow(r.getObject("actionText"), "action");
|
||||||
} else if (r.has("contacts")) {
|
} else if (r.has("contacts")) {
|
||||||
final JsonArray contacts = r.getArray("contacts");
|
final JsonArray contacts = r.getArray("contacts");
|
||||||
final StringBuilder stringBuilder = new StringBuilder();
|
final StringBuilder stringBuilder = new StringBuilder();
|
||||||
int i = 0;
|
// Loop over contacts item from the first contact to the last one
|
||||||
final int contactsSize = contacts.size();
|
for (int i = 0; i < contacts.size(); i++) {
|
||||||
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");
|
stringBuilder.append("\n");
|
||||||
}
|
|
||||||
// Add the latest contact without an extra line return
|
|
||||||
stringBuilder.append(getTextFromObjectOrThrow(contacts.getObject(i)
|
stringBuilder.append(getTextFromObjectOrThrow(contacts.getObject(i)
|
||||||
.getObject("actionText"), "contacts.actionText"));
|
.getObject("actionText"), "contacts.actionText"));
|
||||||
}
|
}
|
||||||
|
|
||||||
action = stringBuilder.toString();
|
action = stringBuilder.toString();
|
||||||
} else {
|
} else {
|
||||||
action = null;
|
action = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// usually details about the phone number
|
// usually details about the phone number
|
||||||
final String details = getTextFromObjectOrThrow(r.getObject("detailsText"), "details");
|
final String details = getTextFromObjectOrThrow(r.getObject("detailsText"), "details");
|
||||||
|
|
||||||
// usually the name of an association
|
// usually the name of an association
|
||||||
final String urlText = getTextFromObjectOrThrow(r.getObject("navigationText"),
|
final String urlText = getTextFromObjectOrThrow(r.getObject("navigationText"),
|
||||||
"urlText");
|
"urlText");
|
||||||
|
|
||||||
metaInfo.setTitle(title);
|
metaInfo.setTitle(title);
|
||||||
metaInfo.setContent(new Description(isNullOrEmpty(action)
|
metaInfo.setContent(new Description(details + action, Description.PLAIN_TEXT));
|
||||||
? details : details + "\n" + action, Description.PLAIN_TEXT));
|
|
||||||
metaInfo.addUrlText(urlText);
|
metaInfo.addUrlText(urlText);
|
||||||
|
|
||||||
// usually the webpage of the association
|
// usually the webpage of the association
|
||||||
|
Loading…
Reference in New Issue
Block a user