2019-12-22 12:53:15 +01:00
|
|
|
// Created by Fynn Godau 2019, licensed GNU GPL version 3 or later
|
|
|
|
|
2019-12-22 02:55:54 +01:00
|
|
|
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;
|
2019-12-22 12:53:15 +01:00
|
|
|
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
|
2019-12-22 02:55:54 +01:00
|
|
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
2020-04-20 23:52:12 +02:00
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
2019-12-22 02:55:54 +01:00
|
|
|
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
|
2019-12-22 12:53:15 +01:00
|
|
|
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampPlaylistExtractor;
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
2019-12-22 02:55:54 +01:00
|
|
|
|
|
|
|
import java.io.IOException;
|
2019-12-22 12:53:15 +01:00
|
|
|
import java.util.List;
|
2019-12-22 02:55:54 +01:00
|
|
|
|
2019-12-22 12:53:15 +01:00
|
|
|
import static org.junit.Assert.*;
|
2020-04-20 21:55:35 +02:00
|
|
|
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
|
2019-12-22 02:55:54 +01:00
|
|
|
|
2019-12-22 12:53:15 +01:00
|
|
|
/**
|
|
|
|
* Tests for {@link BandcampPlaylistExtractor}
|
|
|
|
*/
|
2019-12-22 02:55:54 +01:00
|
|
|
public class BandcampPlaylistExtractorTest {
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
public static void setUp() {
|
|
|
|
NewPipe.init(DownloaderTestImpl.getInstance());
|
|
|
|
}
|
|
|
|
|
2019-12-22 12:53:15 +01:00
|
|
|
/**
|
|
|
|
* Test whether playlists contain the correct amount of items
|
|
|
|
*/
|
2019-12-22 02:55:54 +01:00
|
|
|
@Test
|
|
|
|
public void testCount() throws ExtractionException, IOException {
|
2020-04-20 21:55:35 +02:00
|
|
|
PlaylistExtractor extractor = Bandcamp.getPlaylistExtractor("https://macbenson.bandcamp.com/album/coming-of-age");
|
2019-12-22 02:55:54 +01:00
|
|
|
extractor.fetchPage();
|
|
|
|
|
|
|
|
assertEquals(5, extractor.getStreamCount());
|
|
|
|
}
|
2019-12-22 12:53:15 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests whether different stream thumbnails (track covers) get loaded correctly
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testDifferentTrackCovers() throws ExtractionException, IOException {
|
2020-04-20 21:55:35 +02:00
|
|
|
PlaylistExtractor extractor = Bandcamp.getPlaylistExtractor("https://zachbensonarchive.bandcamp.com/album/results-of-boredom");
|
2019-12-22 12:53:15 +01:00
|
|
|
extractor.fetchPage();
|
|
|
|
|
|
|
|
List<StreamInfoItem> l = extractor.getInitialPage().getItems();
|
|
|
|
assertEquals(extractor.getThumbnailUrl(), l.get(0).getThumbnailUrl());
|
|
|
|
assertNotEquals(extractor.getThumbnailUrl(), l.get(5).getThumbnailUrl());
|
|
|
|
}
|
|
|
|
|
2020-01-03 13:13:42 +01:00
|
|
|
/**
|
|
|
|
* Tests that no attempt to load every track's cover individually is made
|
|
|
|
*/
|
|
|
|
@Test(timeout = 10000L)
|
|
|
|
public void testDifferentTrackCoversDuration() throws ExtractionException, IOException {
|
2020-04-20 21:55:35 +02:00
|
|
|
PlaylistExtractor extractor = Bandcamp.getPlaylistExtractor("https://infiniteammo.bandcamp.com/album/night-in-the-woods-vol-1-at-the-end-of-everything");
|
2020-01-03 13:13:42 +01:00
|
|
|
extractor.fetchPage();
|
|
|
|
|
|
|
|
/* All tracks in this album have the same cover art, but I don't know any albums with more than 10 tracks
|
|
|
|
* that has at least one track with a cover art different from the rest.
|
|
|
|
*/
|
|
|
|
List<StreamInfoItem> l = extractor.getInitialPage().getItems();
|
|
|
|
assertEquals(extractor.getThumbnailUrl(), l.get(0).getThumbnailUrl());
|
|
|
|
assertEquals(extractor.getThumbnailUrl(), l.get(5).getThumbnailUrl());
|
|
|
|
}
|
|
|
|
|
2019-12-22 12:53:15 +01:00
|
|
|
/**
|
|
|
|
* Test playlists with locked content
|
|
|
|
*/
|
|
|
|
@Test(expected = ContentNotAvailableException.class)
|
|
|
|
public void testLockedContent() throws ExtractionException, IOException {
|
2020-04-20 21:55:35 +02:00
|
|
|
PlaylistExtractor extractor = Bandcamp.getPlaylistExtractor("https://billwurtz.bandcamp.com/album/high-enough");
|
2019-12-22 12:53:15 +01:00
|
|
|
extractor.fetchPage();
|
|
|
|
}
|
2019-12-22 14:12:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test playlist with just one track
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testSingleStreamPlaylist() throws ExtractionException, IOException {
|
2020-04-20 21:55:35 +02:00
|
|
|
PlaylistExtractor extractor = Bandcamp.getPlaylistExtractor("https://zachjohnson1.bandcamp.com/album/endless");
|
2019-12-22 14:12:24 +01:00
|
|
|
extractor.fetchPage();
|
|
|
|
|
|
|
|
assertEquals(1, extractor.getStreamCount());
|
|
|
|
|
|
|
|
}
|
2020-04-20 23:52:12 +02:00
|
|
|
|
|
|
|
public static class ComingOfAge {
|
|
|
|
|
|
|
|
private static PlaylistExtractor extractor;
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
public static void setUp() throws ExtractionException, IOException {
|
|
|
|
NewPipe.init(DownloaderTestImpl.getInstance());
|
|
|
|
extractor = Bandcamp.getPlaylistExtractor("https://macbenson.bandcamp.com/album/coming-of-age");
|
|
|
|
extractor.fetchPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void getThumbnailUrl() throws ParsingException {
|
|
|
|
assertTrue(extractor.getThumbnailUrl().contains("f4.bcbits.com/img"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void getBannerUrl() throws ParsingException {
|
|
|
|
assertEquals("", extractor.getBannerUrl());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void getUploaderUrl() throws ParsingException {
|
|
|
|
assertTrue(extractor.getUploaderUrl().contains("macbenson.bandcamp.com"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void getUploaderName() throws ParsingException {
|
|
|
|
assertEquals("mac benson", extractor.getUploaderName());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void getUploaderAvatarUrl() throws ParsingException {
|
|
|
|
assertTrue(extractor.getUploaderAvatarUrl().contains("f4.bcbits.com/img"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void getStreamCount() throws ParsingException {
|
|
|
|
assertEquals(5, extractor.getStreamCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void getInitialPage() throws IOException, ExtractionException {
|
|
|
|
assertNotNull(extractor.getInitialPage().getItems().get(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void getName() throws ParsingException {
|
|
|
|
assertEquals("Coming of Age", extractor.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void getNextPageUrl() throws IOException, ExtractionException {
|
|
|
|
assertNull(extractor.getNextPageUrl());
|
|
|
|
}
|
|
|
|
}
|
2019-12-22 02:55:54 +01:00
|
|
|
}
|