2019-12-21 19:00:07 +01:00
|
|
|
// 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.ExtractionException;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
2020-05-25 20:22:23 +02:00
|
|
|
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper;
|
2019-12-21 19:00:07 +01:00
|
|
|
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampStreamExtractor;
|
2020-03-17 20:40:25 +01:00
|
|
|
import org.schabi.newpipe.extractor.stream.StreamExtractor;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2020-06-04 14:09:21 +02:00
|
|
|
import java.util.Calendar;
|
2020-06-04 19:12:10 +02:00
|
|
|
import java.util.TimeZone;
|
2019-12-21 19:00:07 +01:00
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import static org.junit.Assert.assertTrue;
|
2020-04-20 21:55:35 +02:00
|
|
|
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
|
2019-12-21 19:00:07 +01:00
|
|
|
|
|
|
|
public class BandcampStreamExtractorTest {
|
|
|
|
|
|
|
|
private static BandcampStreamExtractor extractor;
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
public static void setUp() throws Exception {
|
|
|
|
NewPipe.init(DownloaderTestImpl.getInstance());
|
2020-04-20 21:55:35 +02:00
|
|
|
extractor = (BandcampStreamExtractor) Bandcamp
|
2019-12-21 19:00:07 +01:00
|
|
|
.getStreamExtractor("https://zachbenson.bandcamp.com/track/kitchen");
|
|
|
|
extractor.fetchPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testServiceId() {
|
2020-06-04 19:29:37 +02:00
|
|
|
assertEquals(4, extractor.getServiceId());
|
2019-12-21 19:00:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testName() throws ParsingException {
|
|
|
|
assertEquals("kitchen", extractor.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testUrl() throws ParsingException {
|
|
|
|
assertEquals("https://zachbenson.bandcamp.com/track/kitchen", extractor.getUrl());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testArtistUrl() throws ParsingException {
|
|
|
|
assertEquals("https://zachbenson.bandcamp.com/", extractor.getUploaderUrl());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testDescription() {
|
2020-06-04 19:17:51 +02:00
|
|
|
assertTrue(extractor.getDescription().getContent().contains("Boy, you've taken up my thoughts"));
|
2019-12-21 19:00:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testArtistProfilePicture() {
|
|
|
|
String url = extractor.getUploaderAvatarUrl();
|
|
|
|
assertTrue(url.contains("://f4.bcbits.com/img/") && url.endsWith(".jpg"));
|
|
|
|
}
|
|
|
|
|
2020-06-04 13:03:16 +02:00
|
|
|
@Test
|
2020-06-04 14:09:21 +02:00
|
|
|
public void testUploadDate() throws ParsingException {
|
2020-06-04 19:12:10 +02:00
|
|
|
final Calendar expectedCalendar = Calendar.getInstance();
|
|
|
|
// 27 Sep 2019 21:49:14 GMT
|
|
|
|
expectedCalendar.setTimeZone(TimeZone.getTimeZone("GMT"));
|
|
|
|
expectedCalendar.set(2019, Calendar.SEPTEMBER, 27, 21, 49, 14);
|
|
|
|
expectedCalendar.set(Calendar.MILLISECOND, 0);
|
|
|
|
|
|
|
|
assertEquals(expectedCalendar.getTimeInMillis(), extractor.getUploadDate().date().getTimeInMillis());
|
2020-06-04 13:03:16 +02:00
|
|
|
}
|
|
|
|
|
2019-12-22 01:14:35 +01:00
|
|
|
@Test
|
|
|
|
public void testNoArtistProfilePicture() throws ExtractionException {
|
2020-04-20 21:55:35 +02:00
|
|
|
assertEquals("", Bandcamp.getStreamExtractor("https://powertothequeerkids.bandcamp.com/track/human-nature").getUploaderAvatarUrl());
|
2019-12-22 01:14:35 +01:00
|
|
|
}
|
|
|
|
|
2019-12-21 21:47:06 +01:00
|
|
|
@Test
|
|
|
|
public void testAudioStream() {
|
|
|
|
assertTrue(extractor.getAudioStreams().get(0).getUrl().contains("bcbits.com/stream"));
|
|
|
|
assertEquals(1, extractor.getAudioStreams().size());
|
|
|
|
}
|
|
|
|
|
2020-03-17 20:40:25 +01:00
|
|
|
@Test
|
|
|
|
public void testCategory() throws ExtractionException, IOException {
|
2020-04-20 21:55:35 +02:00
|
|
|
StreamExtractor se = Bandcamp.getStreamExtractor("https://npet.bandcamp.com/track/track-1");
|
2020-03-17 20:40:25 +01:00
|
|
|
se.fetchPage();
|
|
|
|
assertEquals("acoustic", se.getCategory());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testLicense() throws ExtractionException, IOException {
|
2020-04-20 21:55:35 +02:00
|
|
|
StreamExtractor se = Bandcamp.getStreamExtractor("https://npet.bandcamp.com/track/track-1");
|
2020-03-17 20:40:25 +01:00
|
|
|
se.fetchPage();
|
|
|
|
assertEquals("CC BY 3.0", se.getLicence());
|
|
|
|
}
|
|
|
|
|
2020-05-25 20:22:23 +02:00
|
|
|
@Test
|
|
|
|
public void testTranslateIdsToUrl() throws ParsingException {
|
|
|
|
assertEquals("https://zachbenson.bandcamp.com/album/covers", BandcampExtractorHelper.getStreamUrlFromIds(2862267535L, 2063639444L, "album"));
|
|
|
|
// TODO write more test cases
|
|
|
|
}
|
2020-03-17 20:40:25 +01:00
|
|
|
|
2019-12-21 19:00:07 +01:00
|
|
|
}
|