diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRadioStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRadioStreamExtractor.java index 82bd0d287..3c1148c7c 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRadioStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampRadioStreamExtractor.java @@ -11,6 +11,7 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; import org.schabi.newpipe.extractor.linkhandler.LinkHandler; import org.schabi.newpipe.extractor.stream.AudioStream; +import org.schabi.newpipe.extractor.stream.Description; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -91,8 +92,8 @@ public class BandcampRadioStreamExtractor extends BandcampStreamExtractor { @Nonnull @Override - public String getDescription() { - return showInfo.getString("desc"); + public Description getDescription() { + return new Description(showInfo.getString("desc"), Description.PLAIN_TEXT); } @Override @@ -120,4 +121,22 @@ public class BandcampRadioStreamExtractor extends BandcampStreamExtractor { return list; } + + @Nonnull + @Override + public String getLicence() { + return ""; + } + + @Nonnull + @Override + public String getCategory() { + return ""; + } + + @Nonnull + @Override + public List getTags() { + return new ArrayList<>(); + } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java index c76cb474b..2300809d7 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java @@ -6,6 +6,8 @@ import org.json.JSONException; import org.json.JSONObject; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; import org.schabi.newpipe.extractor.MediaFormat; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.downloader.Downloader; @@ -20,6 +22,7 @@ import javax.annotation.Nullable; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampChannelExtractor.getImageUrl; @@ -121,14 +124,15 @@ public class BandcampStreamExtractor extends StreamExtractor { @Nonnull @Override - public String getDescription() { - return BandcampExtractorHelper.smartConcatenate( + public Description getDescription() { + String s = BandcampExtractorHelper.smartConcatenate( new String[]{ getStringOrNull(current, "about"), getStringOrNull(current, "lyrics"), getStringOrNull(current, "credits") }, "\n\n" ); + return new Description(s, Description.PLAIN_TEXT); } /** @@ -176,7 +180,7 @@ public class BandcampStreamExtractor extends StreamExtractor { @Nonnull @Override public String getDashMpdUrl() throws ParsingException { - return null; + return ""; } @Nonnull @@ -210,13 +214,13 @@ public class BandcampStreamExtractor extends StreamExtractor { @Nonnull @Override public List getSubtitlesDefault() { - return null; + return new ArrayList<>(); } @Nonnull @Override public List getSubtitles(MediaFormat format) { - return null; + return new ArrayList<>(); } @Override @@ -238,4 +242,77 @@ public class BandcampStreamExtractor extends StreamExtractor { public String getErrorMessage() { return null; } + + @Nonnull + @Override + public String getHost() { + return ""; + } + + @Nonnull + @Override + public String getPrivacy() { + return ""; + } + + @Nonnull + @Override + public String getCategory() { + // Get first tag from html, which is the artist's Genre + return document.getElementsByAttributeValue("itemprop", "keywords").first().text(); + } + + @Nonnull + @Override + public String getLicence() { + + int license = current.getInt("license_type"); + + // Tests resulted in this mapping of ints to licence: https://cloud.disroot.org/s/ZTWBxbQ9fKRmRWJ/preview + + switch (license) { + case 1: + return "All rights reserved ©"; + case 2: + return "CC BY-NC-ND 3.0"; + case 3: + return "CC BY-NC-SA 3.0"; + case 4: + return "CC BY-NC 3.0"; + case 5: + return "CC BY-ND 3.0"; + case 8: + return "CC BY-SA 3.0"; + case 6: + return "CC BY 3.0"; + default: + return "Unknown license (internal ID " + license + ")"; + } + } + + @Nullable + @Override + public Locale getLanguageInfo() { + return null; + } + + @Nonnull + @Override + public List getTags() { + Elements tagElements = document.getElementsByAttributeValue("itemprop", "keywords"); + + ArrayList tags = new ArrayList<>(); + + for (Element e : tagElements) { + tags.add(e.text()); + } + + return tags; + } + + @Nonnull + @Override + public String getSupportInfo() { + return ""; + } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampStreamExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampStreamExtractorTest.java index 2f7a03bff..5574c3408 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampStreamExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampStreamExtractorTest.java @@ -9,6 +9,9 @@ import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampStreamExtractor; +import org.schabi.newpipe.extractor.stream.StreamExtractor; + +import java.io.IOException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -52,7 +55,7 @@ public class BandcampStreamExtractorTest { @Test public void testDescription() { - assertEquals(831, extractor.getDescription().length()); + assertEquals(831, extractor.getDescription().getContent().length()); } @Test @@ -77,4 +80,19 @@ public class BandcampStreamExtractorTest { bandcamp.getStreamExtractor("https://bandcamp.com"); } + @Test + public void testCategory() throws ExtractionException, IOException { + StreamExtractor se = bandcamp.getStreamExtractor("https://npet.bandcamp.com/track/track-1"); + se.fetchPage(); + assertEquals("acoustic", se.getCategory()); + } + + @Test + public void testLicense() throws ExtractionException, IOException { + StreamExtractor se = bandcamp.getStreamExtractor("https://npet.bandcamp.com/track/track-1"); + se.fetchPage(); + assertEquals("CC BY 3.0", se.getLicence()); + } + + }