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 @Nonnull
@Override @Override
public String getUploaderAvatarUrl() { public String getUploaderAvatarUrl() {
try {
return document.getElementsByClass("band-photo").first().attr("src"); return document.getElementsByClass("band-photo").first().attr("src");
} catch (NullPointerException e) {
return "";
}
} }
@Nonnull @Nonnull

View file

@ -61,6 +61,11 @@ public class BandcampStreamExtractorTest {
assertTrue(url.contains("://f4.bcbits.com/img/") && url.endsWith(".jpg")); 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 @Test
public void testAudioStream() { public void testAudioStream() {
assertTrue(extractor.getAudioStreams().get(0).getUrl().contains("bcbits.com/stream")); 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("http://zachbenson.bandcamp.com"));
assertFalse(linkHandler.acceptUrl("https://bandcamp.com")); assertFalse(linkHandler.acceptUrl("https://bandcamp.com"));
assertFalse(linkHandler.acceptUrl("https://zachbenson.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 // Tests expecting true
assertTrue(linkHandler.acceptUrl("https://zachbenson.bandcamp.com/track/kitchen")); assertTrue(linkHandler.acceptUrl("https://zachbenson.bandcamp.com/track/kitchen"));