Bandcamp playlist and search extractors: better and more tests

This commit is contained in:
Fynn Godau 2019-12-22 12:53:15 +01:00
parent 655df356a2
commit e12ddaef7f
4 changed files with 44 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.schabi.newpipe.extractor.InfoItemsCollector;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;

View File

@ -7,6 +7,7 @@ import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
@ -50,7 +51,7 @@ public class BandcampPlaylistExtractor extends PlaylistExtractor {
if (trackInfo.length() <= 1) {
// In this case, we are actually viewing a track page!
throw new ExtractionException("Page is actually a track, not an album");
throw new ContentNotAvailableException("Album needs to be purchased or is actually a track");
}
}

View File

@ -1,17 +1,26 @@
// Created by Fynn Godau 2019, licensed GNU GPL version 3 or later
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.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampPlaylistExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import java.io.IOException;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ServiceList.bandcamp;
/**
* Tests for {@link BandcampPlaylistExtractor}
*/
public class BandcampPlaylistExtractorTest {
@BeforeClass
@ -19,6 +28,9 @@ public class BandcampPlaylistExtractorTest {
NewPipe.init(DownloaderTestImpl.getInstance());
}
/**
* Test whether playlists contain the correct amount of items
*/
@Test
public void testCount() throws ExtractionException, IOException {
PlaylistExtractor extractor = bandcamp.getPlaylistExtractor("https://macbenson.bandcamp.com/album/coming-of-age");
@ -26,4 +38,26 @@ public class BandcampPlaylistExtractorTest {
assertEquals(5, extractor.getStreamCount());
}
/**
* Tests whether different stream thumbnails (track covers) get loaded correctly
*/
@Test
public void testDifferentTrackCovers() throws ExtractionException, IOException {
PlaylistExtractor extractor = bandcamp.getPlaylistExtractor("https://zachbensonarchive.bandcamp.com/album/results-of-boredom");
extractor.fetchPage();
List<StreamInfoItem> l = extractor.getInitialPage().getItems();
assertEquals(extractor.getThumbnailUrl(), l.get(0).getThumbnailUrl());
assertNotEquals(extractor.getThumbnailUrl(), l.get(5).getThumbnailUrl());
}
/**
* Test playlists with locked content
*/
@Test(expected = ContentNotAvailableException.class)
public void testLockedContent() throws ExtractionException, IOException {
PlaylistExtractor extractor = bandcamp.getPlaylistExtractor("https://billwurtz.bandcamp.com/album/high-enough");
extractor.fetchPage();
}
}

View File

@ -10,8 +10,10 @@ 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.playlist.PlaylistInfoItem;
import org.schabi.newpipe.extractor.search.SearchExtractor;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampChannelInfoItemExtractor;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampPlaylistInfoItemExtractor;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampSearchExtractor;
import java.io.IOException;
@ -77,11 +79,14 @@ public class BandcampSearchExtractorTest {
InfoItem minecraft = extractor.getInitialPage()
.getItems().get(0);
// C418's artist profile should be the first result, no?
// Minecraft volume alpha should be the first result, no?
assertEquals("Minecraft - Volume Alpha", minecraft.getName());
assertTrue(minecraft.getThumbnailUrl().endsWith(".jpg"));
assertTrue(minecraft.getThumbnailUrl().contains("f4.bcbits.com/img/"));
assertEquals("https://c418.bandcamp.com/album/minecraft-volume-alpha", minecraft.getUrl());
// Verify that playlists get counted correctly
assertEquals(24, ((PlaylistInfoItem) minecraft).getStreamCount());
}
}