mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2024-12-14 22:30:33 +05:30
Bandcamp channel extractor: handel nonexistent images better
This commit is contained in:
parent
91c0ec7cea
commit
794ca5eeae
@ -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() {
|
||||
return getImageUrl(channelInfo.getLong("bio_image_id"), false);
|
||||
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 "";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user