Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ allprojects {

extensions.configure<JavaPluginExtension> {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
languageVersion.set(JavaLanguageVersion.of(17))
}
}
}
Expand All @@ -29,7 +29,7 @@ subprojects {
tasks.withType<Javadoc>().configureEach {
(options as StandardJavadocDocletOptions).apply {
encoding = Charsets.UTF_8.toString()
links = listOf("https://docs.oracle.com/javase/11/docs/api/")
links = listOf("https://docs.oracle.com/javase/17/docs/api/")
tags = listOf(
"apiNote:a:API Note:",
"implSpec:a:Implementation Requirements:",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public BandcampCommentsInfoItemExtractor(final JsonObject review, final String u

@Override
public String getName() throws ParsingException {
return getCommentText().getContent();
return getCommentText().content();
}

@Override
Expand All @@ -41,7 +41,7 @@ public List<Image> getThumbnails() throws ParsingException {
@Nonnull
@Override
public Description getCommentText() throws ParsingException {
return new Description(review.getString("why"), Description.PLAIN_TEXT);
return Description.of(review.getString("why"), Description.Type.PLAIN_TEXT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public Description getDescription() throws ParsingException {
if (license != null) {
sb.append(license.html());
}
return new Description(sb.toString(), Description.HTML);
return Description.of(sb.toString(), Description.Type.HTML);
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public List<Image> getUploaderAvatars() {
@Nonnull
@Override
public Description getDescription() {
return new Description(showInfo.getString("desc"), Description.PLAIN_TEXT);
return Description.of(showInfo.getString("desc"), Description.Type.PLAIN_TEXT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public List<Image> getUploaderAvatars() {
public Description getDescription() {
final String s = Utils.nonEmptyAndNullJoin("\n\n", current.getString("about"),
current.getString("lyrics"), current.getString("credits"));
return new Description(s, Description.PLAIN_TEXT);
return Description.of(s, Description.Type.PLAIN_TEXT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public List<Image> getThumbnails() throws ParsingException {
@Nonnull
@Override
public Description getDescription() throws ParsingException {
return new Description(conference.getString("description")
+ " - " + group, Description.PLAIN_TEXT);
final String text = conference.getString("description") + " - " + group;
return new Description(text, Description.Type.PLAIN_TEXT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public List<Image> getThumbnails() {
@Nonnull
@Override
public Description getDescription() {
return new Description(data.getString("description"), Description.PLAIN_TEXT);
return Description.of(data.getString("description"), Description.Type.PLAIN_TEXT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ public Description getCommentText() throws ParsingException {
try {
final Document doc = Jsoup.parse(htmlText);
final var text = doc.body().text();
return new Description(text, Description.PLAIN_TEXT);
return Description.of(text, Description.Type.PLAIN_TEXT);
} catch (final Exception e) {
final var text = htmlText.replaceAll("(?s)<[^>]*>(\\s*<[^>]*>)*", "");
return new Description(text, Description.PLAIN_TEXT);
return Description.of(text, Description.Type.PLAIN_TEXT);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ public long getStreamCount() {
@Nonnull
@Override
public Description getDescription() throws ParsingException {
final String description = playlistInfo.getString("description");
if (isNullOrEmpty(description)) {
return Description.EMPTY_DESCRIPTION;
}
return new Description(description, Description.PLAIN_TEXT);
return Description.of(playlistInfo.getString("description"), Description.Type.PLAIN_TEXT);
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import javax.annotation.Nonnull;
import java.util.List;

import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.getThumbnailsFromPlaylistOrVideoItem;

public class PeertubePlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {
Expand Down Expand Up @@ -65,10 +64,6 @@ public long getStreamCount() throws ParsingException {
@Nonnull
@Override
public Description getDescription() throws ParsingException {
final String description = item.getString("description");
if (isNullOrEmpty(description)) {
return Description.EMPTY_DESCRIPTION;
}
return new Description(description, Description.PLAIN_TEXT);
return Description.of(item.getString("description"), Description.Type.PLAIN_TEXT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public Description getDescription() throws ParsingException {
// Something went wrong when getting the full description, use the shortened one
}
}
return new Description(text, Description.MARKDOWN);
return Description.of(text, Description.Type.MARKDOWN);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public String getCommentId() {
@Nonnull
@Override
public Description getCommentText() {
return new Description(json.getString("body"), Description.PLAIN_TEXT);
return Description.of(json.getString("body"), Description.Type.PLAIN_TEXT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,7 @@ public long getStreamCount() {
@Nonnull
@Override
public Description getDescription() throws ParsingException {
final String description = playlist.getString("description");
if (isNullOrEmpty(description)) {
return Description.EMPTY_DESCRIPTION;
}
return new Description(description, Description.PLAIN_TEXT);
return Description.of(playlist.getString("description"), Description.Type.PLAIN_TEXT);
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public List<Image> getThumbnails() throws ParsingException {
@Nonnull
@Override
public Description getDescription() {
return new Description(track.getString("description"), Description.PLAIN_TEXT);
return Description.of(track.getString("description"), Description.Type.PLAIN_TEXT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private static MetaInfo getInfoPanelContent(@Nonnull final JsonObject infoPanelC
}
sb.append(getTextFromObject((JsonObject) paragraph));
}
metaInfo.setContent(new Description(sb.toString(), Description.HTML));
metaInfo.setContent(Description.of(sb.toString(), Description.Type.HTML));
if (infoPanelContentRenderer.has("sourceEndpoint")) {
final String metaInfoLinkUrl = getUrlFromNavigationEndpoint(
infoPanelContentRenderer.getObject("sourceEndpoint"));
Expand Down Expand Up @@ -115,7 +115,7 @@ private static MetaInfo getClarificationRenderer(
throw new ParsingException("Could not extract clarification renderer content");
}
metaInfo.setTitle(title);
metaInfo.setContent(new Description(text, Description.PLAIN_TEXT));
metaInfo.setContent(new Description(text, Description.Type.PLAIN_TEXT));

if (clarificationRenderer.has("actionButton")) {
final JsonObject actionButton = clarificationRenderer.getObject("actionButton")
Expand Down Expand Up @@ -203,7 +203,7 @@ private static void getEmergencyOneboxRenderer(
"urlText");

metaInfo.setTitle(title);
metaInfo.setContent(new Description(details + action, Description.PLAIN_TEXT));
metaInfo.setContent(new Description(details + action, Description.Type.PLAIN_TEXT));
metaInfo.addUrlText(urlText);

// usually the webpage of the association
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,13 @@ public String getTextualLikeCount() {
.getString("likeCountNotliked");
}

@Nonnull
@Override
public Description getCommentText() throws ParsingException {
// Comments' text work in the same way as an attributed video description
return new Description(
attributedDescriptionToHtml(commentEntityPayload.getObject(PROPERTIES)
.getObject("content")), Description.HTML);
final String text = attributedDescriptionToHtml(commentEntityPayload.getObject(PROPERTIES)
.getObject("content"));
return Description.of(text, Description.Type.HTML);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public Description getCommentText() throws ParsingException {
// eg. https://www.youtube.com/watch?v=Nj4F63E59io<feff>
final String commentTextBomRemoved = Utils.removeUTF8BOM(commentText);

return new Description(commentTextBomRemoved, Description.HTML);
return Description.of(commentTextBomRemoved, Description.Type.HTML);
} catch (final Exception e) {
throw new ParsingException("Could not get comment text", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public Description getDescription() throws ParsingException {
true
);

return new Description(description, Description.HTML);
return Description.of(description, Description.Type.HTML);
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,13 @@ public Description getDescription() throws ParsingException {
getVideoSecondaryInfoRenderer().getObject("description"),
true);
if (!isNullOrEmpty(videoSecondaryInfoRendererDescription)) {
return new Description(videoSecondaryInfoRendererDescription, Description.HTML);
return new Description(videoSecondaryInfoRendererDescription, Description.Type.HTML);
}

final String attributedDescription = attributedDescriptionToHtml(
getVideoSecondaryInfoRenderer().getObject("attributedDescription"));
if (!isNullOrEmpty(attributedDescription)) {
return new Description(attributedDescription, Description.HTML);
return new Description(attributedDescription, Description.Type.HTML);
}

String description = playerResponse.getObject(VIDEO_DETAILS)
Expand All @@ -293,7 +293,7 @@ public Description getDescription() throws ParsingException {
}

// Raw non-html description
return new Description(description, Description.PLAIN_TEXT);
return Description.of(description, Description.Type.PLAIN_TEXT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,24 @@
package org.schabi.newpipe.extractor.stream;

import java.io.Serializable;
import java.util.Objects;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.Serializable;

public class Description implements Serializable {

public static final int HTML = 1;
public static final int MARKDOWN = 2;
public static final int PLAIN_TEXT = 3;
public static final Description EMPTY_DESCRIPTION = new Description("", PLAIN_TEXT);

private final String content;
private final int type;
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;

public Description(@Nullable final String content, final int type) {
this.type = type;
this.content = Objects.requireNonNullElse(content, "");
}
public record Description(@Nonnull String content, @Nonnull Type type) implements Serializable {
@Nonnull
public static final Description EMPTY_DESCRIPTION = new Description("", Type.PLAIN_TEXT);

public String getContent() {
return content;
public enum Type {
HTML, MARKDOWN, PLAIN_TEXT
}

public int getType() {
return type;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
@Nonnull
public static Description of(@Nullable final String content, @Nonnull final Type type) {
if (isNullOrEmpty(content)) {
return EMPTY_DESCRIPTION;
}
final Description that = (Description) o;
return type == that.type && Objects.equals(content, that.content);
}

@Override
public int hashCode() {
return Objects.hash(content, type);
return new Description(content, type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ public void testMetaInfo() throws Exception {

for (final MetaInfo expectedMetaInfo : expectedMetaInfoList) {
final List<String> texts = metaInfoList.stream()
.map(metaInfo -> metaInfo.getContent().getContent())
.map(metaInfo -> metaInfo.getContent().content())
.collect(Collectors.toList());
final List<String> titles = metaInfoList.stream().map(MetaInfo::getTitle).collect(Collectors.toList());
final List<URL> urls = metaInfoList.stream().flatMap(info -> info.getUrls().stream())
.collect(Collectors.toList());
final List<String> urlTexts = metaInfoList.stream().flatMap(info -> info.getUrlTexts().stream())
.collect(Collectors.toList());

assertTrue(texts.contains(expectedMetaInfo.getContent().getContent()));
assertTrue(texts.contains(expectedMetaInfo.getContent().content()));
assertTrue(titles.contains(expectedMetaInfo.getTitle()));

for (final String expectedUrlText : expectedMetaInfo.getUrlTexts()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ public void testDescription() throws Exception {
assertNotNull(description);

if (expectedDescriptionIsEmpty()) {
assertTrue(description.getContent().isEmpty(), "description is not empty");
assertTrue(description.content().isEmpty(), "description is not empty");
} else {
assertFalse(description.getContent().isEmpty(), "description is empty");
assertFalse(description.content().isEmpty(), "description is empty");
}

for (final String s : expectedDescriptionContains()) {
ExtractorAsserts.assertContains(s, description.getContent());
ExtractorAsserts.assertContains(s, description.content());
}
}

Expand Down Expand Up @@ -454,15 +454,15 @@ public void testMetaInfo() throws Exception {
final List<Executable> assertions = new ArrayList<>();
for (final MetaInfo expectedMetaInfo : expectedMetaInfoList) {
final List<String> texts = metaInfoList.stream()
.map((metaInfo) -> metaInfo.getContent().getContent())
.map((metaInfo) -> metaInfo.getContent().content())
.collect(Collectors.toList());
final List<String> titles = metaInfoList.stream().map(MetaInfo::getTitle).collect(Collectors.toList());
final List<URL> urls = metaInfoList.stream().flatMap(info -> info.getUrls().stream())
.collect(Collectors.toList());
final List<String> urlTexts = metaInfoList.stream().flatMap(info -> info.getUrlTexts().stream())
.collect(Collectors.toList());

assertions.add(() -> assertContains(expectedMetaInfo.getContent().getContent(), texts));
assertions.add(() -> assertContains(expectedMetaInfo.getContent().content(), texts));
assertions.add(() -> assertContains(expectedMetaInfo.getTitle(), titles));

for (final String expectedUrlText : expectedMetaInfo.getUrlTexts()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void testGetCommentsAllData() throws IOException, ExtractionException {
for (final CommentsInfoItem c : comments.getItems()) {
assertFalse(Utils.isBlank(c.getUploaderName()));
BandcampTestUtils.testImages(c.getUploaderAvatars());
assertFalse(Utils.isBlank(c.getCommentText().getContent()));
assertFalse(Utils.isBlank(c.getCommentText().content()));
assertFalse(Utils.isBlank(c.getName()));
BandcampTestUtils.testImages(c.getThumbnails());
assertFalse(Utils.isBlank(c.getUrl()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ public void testStreamCount() throws ParsingException {
public void testDescription() throws ParsingException {
final Description description = extractor().getDescription();
assertNotEquals(Description.EMPTY_DESCRIPTION, description);
assertContains("Artwork by Shona Radcliffe", description.getContent()); // about
assertContains("Artwork by Shona Radcliffe", description.content()); // about
assertContains("All tracks written, produced and recorded by Mac Benson",
description.getContent()); // credits
assertContains("all rights reserved", description.getContent()); // license
description.content()); // credits
assertContains("all rights reserved", description.content()); // license
}

@Test
Expand Down
Loading
Loading