mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2024-12-14 22:30:33 +05:30
Add channels (artists) to search results
This commit is contained in:
parent
794ca5eeae
commit
d05b14ae48
@ -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;
|
||||
}
|
||||
}
|
@ -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":
|
||||
|
@ -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<InfoItem> 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());
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user