2018-09-25 23:50:29 +02:00
|
|
|
package org.schabi.newpipe.extractor.services.youtube.extractors;
|
|
|
|
|
|
|
|
import org.schabi.newpipe.extractor.comments.CommentsInfoItemExtractor;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
|
|
|
import org.schabi.newpipe.extractor.utils.JsonUtils;
|
|
|
|
|
|
|
|
import com.grack.nanojson.JsonArray;
|
|
|
|
import com.grack.nanojson.JsonObject;
|
|
|
|
|
2018-09-26 00:51:58 +02:00
|
|
|
public class YoutubeCommentsInfoItemExtractor implements CommentsInfoItemExtractor {
|
|
|
|
|
2018-09-25 23:50:29 +02:00
|
|
|
private final JsonObject json;
|
|
|
|
private final String url;
|
2018-09-26 00:51:58 +02:00
|
|
|
|
2018-09-25 23:50:29 +02:00
|
|
|
public YoutubeCommentsInfoItemExtractor(JsonObject json, String url) {
|
|
|
|
this.json = json;
|
|
|
|
this.url = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getUrl() throws ParsingException {
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getThumbnailUrl() throws ParsingException {
|
2018-09-26 00:51:58 +02:00
|
|
|
try {
|
|
|
|
JsonArray arr = (JsonArray) JsonUtils.getValue(json, "authorThumbnail.thumbnails");
|
|
|
|
return (String) JsonUtils.getValue(arr.getObject(2), "url");
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new ParsingException("Could not get thumbnail url", e);
|
|
|
|
}
|
2018-09-25 23:50:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() throws ParsingException {
|
2018-09-26 00:51:58 +02:00
|
|
|
try {
|
|
|
|
return (String) JsonUtils.getValue(json, "authorText.simpleText");
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new ParsingException("Could not get author name", e);
|
|
|
|
}
|
2018-09-25 23:50:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getPublishedTime() throws ParsingException {
|
2018-09-26 00:51:58 +02:00
|
|
|
try {
|
|
|
|
JsonArray arr = (JsonArray) JsonUtils.getValue(json, "publishedTimeText.runs");
|
|
|
|
return (String) JsonUtils.getValue(arr.getObject(0), "text");
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new ParsingException("Could not get publishedTimeText", e);
|
|
|
|
}
|
2018-09-25 23:50:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Integer getLikeCount() throws ParsingException {
|
2018-09-26 00:51:58 +02:00
|
|
|
try {
|
|
|
|
return (Integer) JsonUtils.getValue(json, "likeCount");
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new ParsingException("Could not get like count", e);
|
|
|
|
}
|
2018-09-25 23:50:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getCommentText() throws ParsingException {
|
|
|
|
try {
|
2018-09-26 00:51:58 +02:00
|
|
|
return (String) JsonUtils.getValue(json, "contentText.simpleText");
|
|
|
|
} catch (Exception e1) {
|
|
|
|
try {
|
|
|
|
JsonArray arr = (JsonArray) JsonUtils.getValue(json, "contentText.runs");
|
|
|
|
return (String) JsonUtils.getValue(arr.getObject(0), "text");
|
|
|
|
} catch (Exception e2) {
|
|
|
|
throw new ParsingException("Could not get comment text", e2);
|
|
|
|
}
|
2018-09-25 23:50:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getCommentId() throws ParsingException {
|
2018-09-26 00:51:58 +02:00
|
|
|
try {
|
|
|
|
return (String) JsonUtils.getValue(json, "commentId");
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new ParsingException("Could not get comment id", e);
|
|
|
|
}
|
2018-09-25 23:50:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getAuthorThumbnail() throws ParsingException {
|
2018-09-26 00:51:58 +02:00
|
|
|
try {
|
|
|
|
JsonArray arr = (JsonArray) JsonUtils.getValue(json, "authorThumbnail.thumbnails");
|
|
|
|
return (String) JsonUtils.getValue(arr.getObject(2), "url");
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new ParsingException("Could not get author thumbnail", e);
|
|
|
|
}
|
2018-09-25 23:50:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getAuthorName() throws ParsingException {
|
2018-09-26 00:51:58 +02:00
|
|
|
try {
|
|
|
|
return (String) JsonUtils.getValue(json, "authorText.simpleText");
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new ParsingException("Could not get author name", e);
|
|
|
|
}
|
2018-09-25 23:50:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getAuthorEndpoint() throws ParsingException {
|
2018-09-26 00:51:58 +02:00
|
|
|
try {
|
|
|
|
return "https://youtube.com"
|
|
|
|
+ (String) JsonUtils.getValue(json, "authorEndpoint.browseEndpoint.canonicalBaseUrl");
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new ParsingException("Could not get author endpoint", e);
|
|
|
|
}
|
2018-09-25 23:50:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|