From d05b14ae48e3c82e8cbe671d5a7cd7133f4c9fd4 Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Sun, 22 Dec 2019 01:55:04 +0100 Subject: [PATCH] Add channels (artists) to search results --- .../BandcampChannelInfoItemExtractor.java | 46 +++++++++++++++++++ .../extractors/BandcampSearchExtractor.java | 11 +---- .../bandcamp/BandcampSearchExtractorTest.java | 21 +++++++-- 3 files changed, 65 insertions(+), 13 deletions(-) create mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampChannelInfoItemExtractor.java diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampChannelInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampChannelInfoItemExtractor.java new file mode 100644 index 00000000..b5d851ea --- /dev/null +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampChannelInfoItemExtractor.java @@ -0,0 +1,46 @@ +package org.schabi.newpipe.extractor.services.bandcamp.extractors; + +import org.schabi.newpipe.extractor.channel.ChannelInfoItemExtractor; +import org.schabi.newpipe.extractor.exceptions.ParsingException; + +public class BandcampChannelInfoItemExtractor implements ChannelInfoItemExtractor { + + private String name, url, image, location; + + public BandcampChannelInfoItemExtractor(String name, String url, String image, String location) { + this.name = name; + this.url = url; + this.image = image; + this.location = location; + } + + @Override + public String getName() throws ParsingException { + return name; + } + + @Override + public String getUrl() throws ParsingException { + return url; + } + + @Override + public String getThumbnailUrl() throws ParsingException { + return image; + } + + @Override + public String getDescription() { + return location; + } + + @Override + public long getSubscriberCount() { + return -1; + } + + @Override + public long getStreamCount() { + return -1; + } +} diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampSearchExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampSearchExtractor.java index 34f52af1..fc89002f 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampSearchExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampSearchExtractor.java @@ -69,16 +69,7 @@ public class BandcampSearchExtractor extends SearchExtractor { break; case "ARTIST": - String id = resultInfo.getElementsByClass("itemurl").first() - .getElementsByTag("a").first() - .attr("href") // the link contains the id - .split("search_item_id=") - [1] // the number is behind its name - .split("&") // there is another attribute behind the name - [0]; // get the number - - //searchResults.add(new Artist(heading, Long.parseLong(id), image, subhead)); - //collector.commit Channel with heading, id, image, subhead + collector.commit(new BandcampChannelInfoItemExtractor(heading, url, image, subhead)); break; case "ALBUM": diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampSearchExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampSearchExtractorTest.java index 11ce3d0d..5780e161 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampSearchExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampSearchExtractorTest.java @@ -5,10 +5,13 @@ package org.schabi.newpipe.extractor.services.bandcamp; import org.junit.BeforeClass; import org.junit.Test; import org.schabi.newpipe.DownloaderTestImpl; +import org.schabi.newpipe.extractor.Extractor; import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.search.SearchExtractor; +import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampChannelInfoItemExtractor; import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampSearchExtractor; import java.io.IOException; @@ -36,8 +39,7 @@ public class BandcampSearchExtractorTest { */ @Test public void testBestFriendsBasement() throws ExtractionException, IOException { - extractor = (BandcampSearchExtractor) bandcamp - .getSearchExtractor("best friend's basement"); + SearchExtractor extractor = bandcamp.getSearchExtractor("best friend's basement"); ListExtractor.InfoItemsPage page = extractor.getInitialPage(); InfoItem bestFriendsBasement = page.getItems().get(0); @@ -47,9 +49,22 @@ public class BandcampSearchExtractorTest { assertTrue(bestFriendsBasement.getThumbnailUrl().endsWith(".jpg")); assertTrue(bestFriendsBasement.getThumbnailUrl().contains("f4.bcbits.com/img/")); assertEquals(InfoItem.InfoType.STREAM, bestFriendsBasement.getInfoType()); + } + /** + * Tests whether searching bandcamp for "C418" returns the artist's profile + */ + @Test + public void testC418() throws ExtractionException, IOException { + SearchExtractor extractor = bandcamp.getSearchExtractor("C418"); + InfoItem c418 = extractor.getInitialPage() + .getItems().get(0); - + // C418's artist profile should be the first result, no? + assertEquals("C418", c418.getName()); + assertTrue(c418.getThumbnailUrl().endsWith(".jpg")); + assertTrue(c418.getThumbnailUrl().contains("f4.bcbits.com/img/")); + assertEquals("https://c418.bandcamp.com", c418.getUrl()); } }