2017-08-06 22:20:15 +02:00
|
|
|
package org.schabi.newpipe.extractor.services.youtube;
|
|
|
|
|
2017-12-07 02:09:46 +01:00
|
|
|
import org.junit.BeforeClass;
|
2017-12-29 01:12:55 +01:00
|
|
|
import org.junit.Ignore;
|
2017-08-06 22:20:15 +02:00
|
|
|
import org.junit.Test;
|
|
|
|
import org.schabi.newpipe.Downloader;
|
2017-08-12 22:19:56 +02:00
|
|
|
import org.schabi.newpipe.extractor.ListExtractor;
|
2017-08-06 22:20:15 +02:00
|
|
|
import org.schabi.newpipe.extractor.NewPipe;
|
2017-11-25 03:13:26 +01:00
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
|
|
|
|
|
|
|
import java.util.List;
|
2017-08-06 22:20:15 +02:00
|
|
|
|
2017-08-08 17:01:50 +02:00
|
|
|
import static org.junit.Assert.*;
|
2017-11-25 03:13:26 +01:00
|
|
|
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmptyErrors;
|
2017-08-07 18:12:51 +02:00
|
|
|
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
2017-08-06 22:20:15 +02:00
|
|
|
|
|
|
|
/**
|
2017-11-25 03:13:26 +01:00
|
|
|
* Test for {@link YoutubePlaylistExtractor}
|
2017-08-06 22:20:15 +02:00
|
|
|
*/
|
|
|
|
public class YoutubePlaylistExtractorTest {
|
2017-12-07 02:09:46 +01:00
|
|
|
private static YoutubePlaylistExtractor extractor;
|
2017-11-25 03:13:26 +01:00
|
|
|
|
|
|
|
private static void assertNotEmpty(String message, String value) {
|
|
|
|
assertNotNull(message, value);
|
|
|
|
assertFalse(message, value.isEmpty());
|
|
|
|
}
|
2017-08-06 22:20:15 +02:00
|
|
|
|
2017-12-07 02:09:46 +01:00
|
|
|
@BeforeClass
|
|
|
|
public static void setUp() throws Exception {
|
2017-08-06 22:20:15 +02:00
|
|
|
NewPipe.init(Downloader.getInstance());
|
2018-02-10 03:46:05 +01:00
|
|
|
extractor = (YoutubePlaylistExtractor) YouTube
|
2017-12-29 01:12:55 +01:00
|
|
|
.getPlaylistExtractor("https://www.youtube.com/watch?v=lp-EO5I60KA&list=PLMC9KNkIncKtPzgY-5rmhvj7fax8fdxoj");
|
2017-12-29 14:40:42 +01:00
|
|
|
extractor.fetchPage();
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-08-08 17:01:50 +02:00
|
|
|
public void testGetDownloader() throws Exception {
|
2017-08-06 22:20:15 +02:00
|
|
|
assertNotNull(NewPipe.getDownloader());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetId() throws Exception {
|
2017-12-29 01:12:55 +01:00
|
|
|
assertEquals(extractor.getId(), "PLMC9KNkIncKtPzgY-5rmhvj7fax8fdxoj");
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetName() throws Exception {
|
2017-12-29 01:12:55 +01:00
|
|
|
assertEquals(extractor.getName(), "Pop Music Playlist: Timeless Pop Hits (Updated Weekly 2018)");
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-08-08 23:36:11 +02:00
|
|
|
public void testGetThumbnailUrl() throws Exception {
|
|
|
|
assertTrue(extractor.getThumbnailUrl(), extractor.getThumbnailUrl().contains("yt"));
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetBannerUrl() throws Exception {
|
2018-03-12 16:14:33 +01:00
|
|
|
System.out.println(extractor.getBannerUrl());
|
2017-08-06 22:20:15 +02:00
|
|
|
assertTrue(extractor.getBannerUrl(), extractor.getBannerUrl().contains("yt"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetUploaderUrl() throws Exception {
|
|
|
|
assertTrue(extractor.getUploaderUrl(), extractor.getUploaderUrl().contains("youtube.com"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetUploaderName() throws Exception {
|
|
|
|
assertTrue(extractor.getUploaderName(), !extractor.getUploaderName().isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetUploaderAvatarUrl() throws Exception {
|
|
|
|
assertTrue(extractor.getUploaderAvatarUrl(), extractor.getUploaderAvatarUrl().contains("yt"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetStreamsCount() throws Exception {
|
|
|
|
assertTrue("error in the streams count", extractor.getStreamCount() > 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetStreams() throws Exception {
|
2018-03-01 01:02:43 +01:00
|
|
|
List<StreamInfoItem> streams = extractor.getInfoItems().getItemList();
|
2017-11-25 03:13:26 +01:00
|
|
|
assertFalse("no streams are received", streams.isEmpty());
|
|
|
|
assertTrue(streams.size() > 60);
|
|
|
|
assertFalse(streams.contains(null));
|
|
|
|
for(StreamInfoItem item: streams) {
|
2018-02-10 03:46:05 +01:00
|
|
|
assertEquals("Service id doesn't match", YouTube.getServiceId(), item.getServiceId());
|
2017-11-25 03:13:26 +01:00
|
|
|
assertNotNull("Stream type not set: " + item, item.getStreamType());
|
|
|
|
//assertNotEmpty("Upload date not set: " + item, item.getUploadDate());
|
|
|
|
assertNotEmpty("Uploader name not set: " + item, item.getUploaderName());
|
|
|
|
assertNotEmpty("Uploader url not set: " + item, item.getUploaderUrl());
|
|
|
|
}
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetStreamsErrors() throws Exception {
|
2018-03-01 01:02:43 +01:00
|
|
|
assertEmptyErrors("errors during stream list extraction", extractor.getInfoItems().getErrors());
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testHasMoreStreams() throws Exception {
|
|
|
|
// Setup the streams
|
2018-03-01 01:02:43 +01:00
|
|
|
extractor.getInfoItems();
|
2018-02-24 22:20:50 +01:00
|
|
|
assertTrue("extractor didn't have more streams", extractor.hasNextPage());
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
|
|
|
|
2017-12-29 01:12:55 +01:00
|
|
|
|
|
|
|
@Test @Ignore
|
2018-02-24 22:20:50 +01:00
|
|
|
public void testGetNextPage() throws Exception {
|
2017-08-06 22:20:15 +02:00
|
|
|
// Setup the streams
|
2018-03-01 01:02:43 +01:00
|
|
|
extractor.getInfoItems();
|
|
|
|
ListExtractor.InfoItemPage<StreamInfoItem> infoItemPage = extractor.getPage(extractor.getNextPageUrl());
|
|
|
|
assertTrue("extractor didn't have next streams", !infoItemPage.getItemsList().isEmpty());
|
|
|
|
assertEmptyErrors("errors occurred during extraction of the next streams", infoItemPage.getErrors());
|
2018-02-24 22:20:50 +01:00
|
|
|
assertTrue("extractor didn't have more streams after getInfoItemPage", extractor.hasNextPage());
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|