Bandcamp channel extractor: handel nonexistent images better

This commit is contained in:
Fynn Godau 2019-12-22 01:38:48 +01:00
parent 91c0ec7cea
commit 794ca5eeae
3 changed files with 22 additions and 2 deletions

View File

@ -3,6 +3,7 @@
package org.schabi.newpipe.extractor.services.bandcamp.extractors;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.schabi.newpipe.extractor.NewPipe;
@ -61,7 +62,12 @@ public class BandcampChannelExtractor extends ChannelExtractor {
@Override
public String getAvatarUrl() {
try {
return getImageUrl(channelInfo.getLong("bio_image_id"), false);
} catch (JSONException e) {
// In this case, the id is null and no image is available
return "";
}
}
/**
@ -82,6 +88,9 @@ public class BandcampChannelExtractor extends ChannelExtractor {
} catch (IOException | ReCaptchaException e) {
throw new ParsingException("Could not download artist web site", e);
} catch (NullPointerException e) {
// No banner available
return "";
}
}

View File

@ -85,7 +85,7 @@ public class BandcampExtractorHelper {
// Remove empty strings
ArrayList<String> list = new ArrayList<>(Arrays.asList(strings));
for (int i = list.size() - 1; i >= 0; i--) {
if (list.get(i) == null || list.get(i).isEmpty()) {
if (list.get(i) == null || list.get(i).isEmpty() || list.get(i).equals("null")) {
list.remove(i);
}
}

View File

@ -4,6 +4,7 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.schabi.newpipe.DownloaderTestImpl;
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.BandcampChannelExtractor;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper;
@ -45,4 +46,14 @@ public class BandcampChannelExtractorTest {
// Why is this picture in png format when all other pictures are jpg?
assertTrue(extractor.getBannerUrl().endsWith(".png"));
}
@Test
public void testGetNoAvatar() throws ExtractionException {
assertEquals("", bandcamp.getChannelExtractor("https://powertothequeerkids.bandcamp.com/").getAvatarUrl());
}
@Test
public void testGetNoBanner() throws ExtractionException {
assertEquals("", bandcamp.getChannelExtractor("https://powertothequeerkids.bandcamp.com/").getBannerUrl());
}
}