[Bandcamp] Implement PlaylistExtractor.getDescsription()

This commit is contained in:
TobiGr 2023-05-15 15:23:03 +02:00
parent ca0ce00753
commit c70bb83801
2 changed files with 36 additions and 1 deletions

View File

@ -11,6 +11,8 @@ import com.grack.nanojson.JsonParserException;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.schabi.newpipe.extractor.Page; import org.schabi.newpipe.extractor.Page;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.downloader.Downloader; import org.schabi.newpipe.extractor.downloader.Downloader;
@ -25,6 +27,7 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
import java.io.IOException; import java.io.IOException;
import java.util.Objects;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -112,7 +115,27 @@ public class BandcampPlaylistExtractor extends PlaylistExtractor {
@Nonnull @Nonnull
@Override @Override
public Description getDescription() throws ParsingException { public Description getDescription() throws ParsingException {
return Description.EMPTY_DESCRIPTION; final Element tInfo = document.getElementById("trackInfo");
if (tInfo == null) {
throw new ParsingException("Could not find trackInfo in document");
}
final Elements about = tInfo.getElementsByClass("tralbum-about");
final Elements credits = tInfo.getElementsByClass("tralbum-credits");
final Element license = document.getElementById("license");
if (about.isEmpty() && credits.isEmpty() && license == null) {
return Description.EMPTY_DESCRIPTION;
}
final StringBuilder sb = new StringBuilder();
if (!about.isEmpty()) {
sb.append(Objects.requireNonNull(about.first()).html());
}
if (!credits.isEmpty()) {
sb.append(Objects.requireNonNull(credits.first()).html());
}
if (license != null) {
sb.append(license.html());
}
return new Description(sb.toString(), Description.HTML);
} }
@Nonnull @Nonnull

View File

@ -13,12 +13,14 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor; import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.services.BasePlaylistExtractorTest; import org.schabi.newpipe.extractor.services.BasePlaylistExtractorTest;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampPlaylistExtractor; import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampPlaylistExtractor;
import org.schabi.newpipe.extractor.stream.Description;
import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertContains;
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp; import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
/** /**
@ -135,6 +137,16 @@ public class BandcampPlaylistExtractorTest {
assertEquals(5, extractor.getStreamCount()); assertEquals(5, extractor.getStreamCount());
} }
@Test
public void testDescription() throws ParsingException {
final Description description = extractor.getDescription();
assertNotEquals(Description.EMPTY_DESCRIPTION, description);
assertContains("Artwork by Shona Radcliffe", description.getContent()); // about
assertContains("All tracks written, produced and recorded by Mac Benson",
description.getContent()); // credits
assertContains("all rights reserved", description.getContent()); // license
}
@Override @Override
public void testUploaderVerified() throws Exception { public void testUploaderVerified() throws Exception {
assertFalse(extractor.isUploaderVerified()); assertFalse(extractor.isUploaderVerified());