Bandcamp stream extractor: catch NullPointerException

This commit is contained in:
Fynn Godau 2019-12-22 01:14:35 +01:00
parent d5cdc20be1
commit 91c0ec7cea
3 changed files with 11 additions and 1 deletions

View File

@ -109,7 +109,11 @@ public class BandcampStreamExtractor extends StreamExtractor {
@Nonnull
@Override
public String getUploaderAvatarUrl() {
return document.getElementsByClass("band-photo").first().attr("src");
try {
return document.getElementsByClass("band-photo").first().attr("src");
} catch (NullPointerException e) {
return "";
}
}
@Nonnull

View File

@ -61,6 +61,11 @@ public class BandcampStreamExtractorTest {
assertTrue(url.contains("://f4.bcbits.com/img/") && url.endsWith(".jpg"));
}
@Test
public void testNoArtistProfilePicture() throws ExtractionException {
assertEquals("", bandcamp.getStreamExtractor("https://powertothequeerkids.bandcamp.com/track/human-nature").getUploaderAvatarUrl());
}
@Test
public void testAudioStream() {
assertTrue(extractor.getAudioStreams().get(0).getUrl().contains("bcbits.com/stream"));

View File

@ -38,6 +38,7 @@ public class BandcampStreamLinkHandlerFactoryTest {
assertFalse(linkHandler.acceptUrl("http://zachbenson.bandcamp.com"));
assertFalse(linkHandler.acceptUrl("https://bandcamp.com"));
assertFalse(linkHandler.acceptUrl("https://zachbenson.bandcamp.com/"));
assertFalse(linkHandler.acceptUrl("https://powertothequeerkids.bandcamp.com/album/power-to-the-queer-kids"));
// Tests expecting true
assertTrue(linkHandler.acceptUrl("https://zachbenson.bandcamp.com/track/kitchen"));