Improve Channel and Playlist tests

This commit is contained in:
Mauricio Colli 2018-03-04 17:26:13 -03:00
parent 11216f361f
commit d9cf1fd631
10 changed files with 1144 additions and 307 deletions

View File

@ -201,7 +201,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
return ""; return "";
} }
} catch (Exception e) { } catch (Exception e) {
throw new ParsingException("could not get next streams' url", e); throw new ParsingException("Could not get next page url", e);
} }
} }

View File

@ -1,19 +1,22 @@
package org.schabi.newpipe.extractor; package org.schabi.newpipe.extractor;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
public class ExtractorAsserts { public class ExtractorAsserts {
public static void assertEmptyErrors(String message, List<Throwable> errors) { public static void assertEmptyErrors(String message, List<Throwable> errors) {
if(!errors.isEmpty()) { if (!errors.isEmpty()) {
for (Throwable throwable : errors) { StringBuilder messageBuilder = new StringBuilder(message);
message += "\n * " + throwable.getMessage(); for (Throwable e : errors) {
messageBuilder.append("\n * ").append(e.getMessage());
} }
throw new AssertionError(message, errors.get(0)); messageBuilder.append(" ");
throw new AssertionError(messageBuilder.toString(), errors.get(0));
} }
} }
@ -22,7 +25,7 @@ public class ExtractorAsserts {
try { try {
return new URL(url); return new URL(url);
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
throw new AssertionError("Invalid url: " + url, e); throw new AssertionError("Invalid url: " + "\"" + url + "\"", e);
} }
} }
@ -34,4 +37,23 @@ public class ExtractorAsserts {
URL url = urlFromString(urlToCheck); URL url = urlFromString(urlToCheck);
assertEquals("Protocol of URL is not secure", "https", url.getProtocol()); assertEquals("Protocol of URL is not secure", "https", url.getProtocol());
} }
public static void assertNotEmpty(String stringToCheck) {
assertNotEmpty(null, stringToCheck);
}
public static void assertNotEmpty(@Nullable String message, String stringToCheck) {
assertNotNull(message, stringToCheck);
assertFalse(message, stringToCheck.isEmpty());
}
public static void assertEmpty(String stringToCheck) {
assertEmpty(null, stringToCheck);
}
public static void assertEmpty(@Nullable String message, String stringToCheck) {
if (stringToCheck != null) {
assertTrue(message, stringToCheck.isEmpty());
}
}
} }

View File

@ -0,0 +1,10 @@
package org.schabi.newpipe.extractor.services;
@SuppressWarnings("unused")
public interface BaseChannelExtractorTest extends BaseListExtractorTest {
void testDescription() throws Exception;
void testAvatarUrl() throws Exception;
void testBannerUrl() throws Exception;
void testFeedUrl() throws Exception;
void testSubscriberCount() throws Exception;
}

View File

@ -0,0 +1,10 @@
package org.schabi.newpipe.extractor.services;
@SuppressWarnings("unused")
public interface BaseExtractorTest {
void testServiceId() throws Exception;
void testName() throws Exception;
void testId() throws Exception;
void testCleanUrl() throws Exception;
void testOriginalUrl() throws Exception;
}

View File

@ -0,0 +1,65 @@
package org.schabi.newpipe.extractor.services;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.InfoItemsCollector;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import java.util.List;
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.*;
public interface BaseListExtractorTest extends BaseExtractorTest {
@SuppressWarnings("unused")
void testRelatedItems() throws Exception;
@SuppressWarnings("unused")
void testMoreRelatedItems() throws Exception;
static void defaultTestListOfItems(int expectedServiceId, List<? extends InfoItem> itemsList, List<Throwable> errors) {
assertTrue("List of items is empty", !itemsList.isEmpty());
assertFalse("List of items contains a null element", itemsList.contains(null));
assertEmptyErrors("Errors during stream list extraction", errors);
for (InfoItem item : itemsList) {
assertIsSecureUrl(item.getUrl());
if (item.getThumbnailUrl() != null && !item.getThumbnailUrl().isEmpty()) {
assertIsSecureUrl(item.getThumbnailUrl());
}
assertNotNull("InfoItem type not set: " + item, item.getInfoType());
assertEquals("Service id doesn't match: " + item, expectedServiceId, item.getServiceId());
if (item instanceof StreamInfoItem) {
StreamInfoItem streamInfoItem = (StreamInfoItem) item;
assertNotEmpty("Uploader name not set: " + item, streamInfoItem.getUploaderName());
assertNotEmpty("Uploader url not set: " + item, streamInfoItem.getUploaderUrl());
}
}
}
static void defaultTestRelatedItems(ListExtractor extractor, int expectedServiceId) throws Exception {
final InfoItemsCollector<? extends InfoItem, ?> itemsCollector = extractor.getInfoItems();
final List<? extends InfoItem> itemsList = itemsCollector.getItemList();
List<Throwable> errors = itemsCollector.getErrors();
defaultTestListOfItems(expectedServiceId, itemsList, errors);
}
static ListExtractor.InfoItemPage<? extends InfoItem> defaultTestMoreItems(ListExtractor extractor, int expectedServiceId) throws Exception {
assertTrue("Doesn't have more items", extractor.hasNextPage());
ListExtractor.InfoItemPage<? extends InfoItem> nextPage = extractor.getPage(extractor.getNextPageUrl());
assertTrue("Next page is empty", !nextPage.getItemsList().isEmpty());
assertEmptyErrors("Next page have errors", nextPage.getErrors());
defaultTestListOfItems(expectedServiceId, nextPage.getItemsList(), nextPage.getErrors());
return nextPage;
}
static void defaultTestGetPageInNewExtractor(ListExtractor extractor, ListExtractor newExtractor, int expectedServiceId) throws Exception {
final String nextPageUrl = extractor.getNextPageUrl();
final ListExtractor.InfoItemPage<? extends InfoItem> page = newExtractor.getPage(nextPageUrl);
BaseListExtractorTest.defaultTestListOfItems(expectedServiceId, page.getItemsList(), page.getErrors());
}
}

View File

@ -0,0 +1,11 @@
package org.schabi.newpipe.extractor.services;
@SuppressWarnings("unused")
public interface BasePlaylistExtractorTest extends BaseListExtractorTest {
void testThumbnailUrl() throws Exception;
void testBannerUrl() throws Exception;
void testUploaderUrl() throws Exception;
void testUploaderName() throws Exception;
void testUploaderAvatarUrl() throws Exception;
void testStreamCount() throws Exception;
}

View File

@ -2,87 +2,199 @@ package org.schabi.newpipe.extractor.services.soundcloud;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import org.schabi.newpipe.Downloader; import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest;
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmpty;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
/** /**
* Test for {@link ChannelExtractor} * Test for {@link SoundcloudChannelExtractor}
*/ */
@RunWith(Enclosed.class)
public class SoundcloudChannelExtractorTest { public class SoundcloudChannelExtractorTest {
public static class LilUzi implements BaseChannelExtractorTest {
static ChannelExtractor extractor; private static SoundcloudChannelExtractor extractor;
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance()); NewPipe.init(Downloader.getInstance());
extractor = SoundCloud extractor = (SoundcloudChannelExtractor) SoundCloud
.getChannelExtractor("https://soundcloud.com/liluzivert"); .getChannelExtractor("http://soundcloud.com/liluzivert/sets");
extractor.fetchPage(); extractor.fetchPage();
} }
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test @Test
public void testGetDownloader() throws Exception { public void testServiceId() {
assertNotNull(NewPipe.getDownloader()); assertEquals(SoundCloud.getServiceId(), extractor.getServiceId());
} }
@Test @Test
public void testGetName() throws Exception { public void testName() {
assertEquals("LIL UZI VERT", extractor.getName()); assertEquals("LIL UZI VERT", extractor.getName());
} }
@Test @Test
public void testGetDescription() throws Exception { public void testId() {
assertTrue(extractor.getDescription() != null); assertEquals("10494998", extractor.getId());
} }
@Test @Test
public void testGetAvatarUrl() throws Exception { public void testCleanUrl() {
assertEquals("https://soundcloud.com/liluzivert", extractor.getCleanUrl());
}
@Test
public void testOriginalUrl() {
assertEquals("http://soundcloud.com/liluzivert/sets", extractor.getOriginalUrl());
}
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testRelatedItems() throws Exception {
BaseListExtractorTest.defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
}
@Test
public void testMoreRelatedItems() throws Exception {
BaseListExtractorTest.defaultTestMoreItems(extractor, SoundCloud.getServiceId());
}
/*//////////////////////////////////////////////////////////////////////////
// ChannelExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testDescription() {
assertNotNull(extractor.getDescription());
}
@Test
public void testAvatarUrl() {
assertIsSecureUrl(extractor.getAvatarUrl()); assertIsSecureUrl(extractor.getAvatarUrl());
} }
@Test @Test
public void testGetStreams() throws Exception { public void testBannerUrl() {
assertFalse("no streams are received", extractor.getInfoItems().getItemList().isEmpty()); assertIsSecureUrl(extractor.getBannerUrl());
} }
@Test @Test
public void testGetStreamsErrors() throws Exception { public void testFeedUrl() {
assertTrue("errors during stream list extraction", extractor.getInfoItems().getErrors().isEmpty()); assertEmpty(extractor.getFeedUrl());
} }
@Test @Test
public void testHasMoreStreams() throws Exception { public void testSubscriberCount() {
// Setup the streams assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 1e6);
extractor.getInfoItems(); }
assertTrue("don't have more streams", extractor.hasNextPage()); }
public static class DubMatix implements BaseChannelExtractorTest {
private static SoundcloudChannelExtractor extractor;
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = (SoundcloudChannelExtractor) SoundCloud
.getChannelExtractor("https://soundcloud.com/dubmatix");
extractor.fetchPage();
}
/*//////////////////////////////////////////////////////////////////////////
// Additional Testing
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testGetPageInNewExtractor() throws Exception {
final ChannelExtractor newExtractor = SoundCloud.getChannelExtractor(extractor.getCleanUrl());
BaseListExtractorTest.defaultTestGetPageInNewExtractor(extractor, newExtractor, SoundCloud.getServiceId());
}
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testServiceId() {
assertEquals(SoundCloud.getServiceId(), extractor.getServiceId());
} }
@Test @Test
public void testGetSubscriberCount() throws Exception { public void testName() {
assertTrue("wrong subscriber count", extractor.getSubscriberCount() >= 1000000); assertEquals("dubmatix", extractor.getName());
} }
@Test @Test
public void testGetNextPageUrl() throws Exception { public void testId() {
assertTrue(extractor.hasNextPage()); assertEquals("542134", extractor.getId());
} }
@Test @Test
public void testGetPage() throws Exception { public void testCleanUrl() {
// Setup the streams assertEquals("https://soundcloud.com/dubmatix", extractor.getCleanUrl());
extractor.getInfoItems();
ListExtractor.InfoItemPage<StreamInfoItem> nextItemsResult = extractor.getPage(extractor.getNextPageUrl());
assertTrue("extractor didn't have next streams", !nextItemsResult.getItemsList().isEmpty());
assertTrue("errors occurred during extraction of the next streams", nextItemsResult.getErrors().isEmpty());
assertTrue("extractor didn't have more streams after getInfoItemPage", extractor.hasNextPage());
} }
@Test
public void testOriginalUrl() {
assertEquals("https://soundcloud.com/dubmatix", extractor.getOriginalUrl());
}
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testRelatedItems() throws Exception {
BaseListExtractorTest.defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
}
@Test
public void testMoreRelatedItems() throws Exception {
BaseListExtractorTest.defaultTestMoreItems(extractor, SoundCloud.getServiceId());
}
/*//////////////////////////////////////////////////////////////////////////
// ChannelExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testDescription() {
assertNotNull(extractor.getDescription());
}
@Test
public void testAvatarUrl() {
assertIsSecureUrl(extractor.getAvatarUrl());
}
@Test
public void testBannerUrl() {
assertIsSecureUrl(extractor.getBannerUrl());
}
@Test
public void testFeedUrl() {
assertEmpty(extractor.getFeedUrl());
}
@Test
public void testSubscriberCount() {
assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 2e6);
}
}
} }

View File

@ -1,11 +1,18 @@
package org.schabi.newpipe.extractor.services.soundcloud; package org.schabi.newpipe.extractor.services.soundcloud;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import org.schabi.newpipe.Downloader; import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor; import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
import org.schabi.newpipe.extractor.services.BasePlaylistExtractorTest;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
@ -14,84 +21,302 @@ import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
/** /**
* Test for {@link PlaylistExtractor} * Test for {@link PlaylistExtractor}
*/ */
@RunWith(Enclosed.class)
public class SoundcloudPlaylistExtractorTest { public class SoundcloudPlaylistExtractorTest {
private static PlaylistExtractor extractor; public static class LuvTape implements BasePlaylistExtractorTest {
private static SoundcloudPlaylistExtractor extractor;
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance()); NewPipe.init(Downloader.getInstance());
extractor = SoundCloud extractor = (SoundcloudPlaylistExtractor) SoundCloud
.getPlaylistExtractor("https://soundcloud.com/liluzivert/sets/the-perfect-luv-tape-r"); .getPlaylistExtractor("https://soundcloud.com/liluzivert/sets/the-perfect-luv-tape-r?test=123");
extractor.fetchPage(); extractor.fetchPage();
} }
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test @Test
public void testGetDownloader() throws Exception { public void testServiceId() {
assertNotNull(NewPipe.getDownloader()); assertEquals(SoundCloud.getServiceId(), extractor.getServiceId());
} }
@Test @Test
public void testGetId() throws Exception { public void testName() {
assertEquals(extractor.getId(), "246349810"); assertEquals("THE PERFECT LUV TAPE®", extractor.getName());
} }
@Test @Test
public void testGetName() throws Exception { public void testId() {
assertEquals(extractor.getName(), "THE PERFECT LUV TAPE®"); assertEquals("246349810", extractor.getId());
} }
@Test @Test
public void testGetThumbnailUrl() throws Exception { public void testCleanUrl() {
assertEquals("https://soundcloud.com/liluzivert/sets/the-perfect-luv-tape-r", extractor.getCleanUrl());
}
@Test
public void testOriginalUrl() {
assertEquals("https://soundcloud.com/liluzivert/sets/the-perfect-luv-tape-r?test=123", extractor.getOriginalUrl());
}
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testRelatedItems() throws Exception {
BaseListExtractorTest.defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
}
@Test
public void testMoreRelatedItems() {
try {
BaseListExtractorTest.defaultTestMoreItems(extractor, SoundCloud.getServiceId());
} catch (Throwable ignored) {
return;
}
fail("This playlist doesn't have more items, it should throw an error");
}
/*//////////////////////////////////////////////////////////////////////////
// PlaylistExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testThumbnailUrl() {
assertIsSecureUrl(extractor.getThumbnailUrl()); assertIsSecureUrl(extractor.getThumbnailUrl());
} }
@Ignore
@Test @Test
public void testGetUploaderUrl() throws Exception { public void testBannerUrl() {
assertIsSecureUrl(extractor.getUploaderUrl()); assertIsSecureUrl(extractor.getBannerUrl());
assertEquals(extractor.getUploaderUrl(), "https://soundcloud.com/liluzivert");
} }
@Test @Test
public void testGetUploaderName() throws Exception { public void testUploaderUrl() {
assertEquals(extractor.getUploaderName(), "LIL UZI VERT"); final String uploaderUrl = extractor.getUploaderUrl();
assertIsSecureUrl(uploaderUrl);
assertTrue(uploaderUrl, uploaderUrl.contains("liluzivert"));
} }
@Test @Test
public void testGetUploaderAvatarUrl() throws Exception { public void testUploaderName() {
assertTrue(extractor.getUploaderName().contains("LIL UZI VERT"));
}
@Test
public void testUploaderAvatarUrl() {
assertIsSecureUrl(extractor.getUploaderAvatarUrl()); assertIsSecureUrl(extractor.getUploaderAvatarUrl());
} }
@Test @Test
public void testGetStreamsCount() throws Exception { public void testStreamCount() {
assertEquals(extractor.getStreamCount(), 10); assertTrue("Error in the streams count", extractor.getStreamCount() >= 10);
}
}
public static class RandomHouseDanceMusic implements BasePlaylistExtractorTest {
private static SoundcloudPlaylistExtractor extractor;
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = (SoundcloudPlaylistExtractor) SoundCloud
.getPlaylistExtractor("http://soundcloud.com/finn-trapple/sets/random-house-dance-music-2");
extractor.fetchPage();
}
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testServiceId() {
assertEquals(SoundCloud.getServiceId(), extractor.getServiceId());
} }
@Test @Test
public void testGetStreams() throws Exception { public void testName() {
assertTrue("no streams are received", !extractor.getInfoItems().getItemList().isEmpty()); assertEquals("Random House & Dance Music #2", extractor.getName());
} }
@Test @Test
public void testGetStreamsErrors() throws Exception { public void testId() {
assertTrue("errors during stream list extraction", extractor.getInfoItems().getErrors().isEmpty()); assertEquals("436855608", extractor.getId());
} }
@Test @Test
public void testHasMoreStreams() throws Exception { public void testCleanUrl() {
// Setup the streams assertEquals("https://soundcloud.com/finn-trapple/sets/random-house-dance-music-2", extractor.getCleanUrl());
extractor.getInfoItems();
assertTrue("extractor didn't have more streams", !extractor.hasNextPage());
} }
@Test(expected = ExtractionException.class) @Test
public void testGetNextPageNonExistent() throws Exception { public void testOriginalUrl() {
// Setup the streams assertEquals("http://soundcloud.com/finn-trapple/sets/random-house-dance-music-2", extractor.getOriginalUrl());
extractor.getInfoItems(); }
// This playlist don't have more streams, it should throw an error /*//////////////////////////////////////////////////////////////////////////
extractor.getPage(extractor.getNextPageUrl()); // ListExtractor
//////////////////////////////////////////////////////////////////////////*/
fail("Expected exception wasn't thrown"); @Test
public void testRelatedItems() throws Exception {
BaseListExtractorTest.defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
}
@Test
public void testMoreRelatedItems() throws Exception {
BaseListExtractorTest.defaultTestMoreItems(extractor, SoundCloud.getServiceId());
}
/*//////////////////////////////////////////////////////////////////////////
// PlaylistExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testThumbnailUrl() {
assertIsSecureUrl(extractor.getThumbnailUrl());
}
@Ignore
@Test
public void testBannerUrl() {
assertIsSecureUrl(extractor.getBannerUrl());
}
@Test
public void testUploaderUrl() {
final String uploaderUrl = extractor.getUploaderUrl();
assertIsSecureUrl(uploaderUrl);
assertTrue(uploaderUrl, uploaderUrl.contains("finn-trapple"));
}
@Test
public void testUploaderName() {
assertEquals("Finn TrApple", extractor.getUploaderName());
}
@Test
public void testUploaderAvatarUrl() {
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
}
@Test
public void testStreamCount() {
assertTrue("Error in the streams count", extractor.getStreamCount() >= 10);
}
}
public static class EDMxxx implements BasePlaylistExtractorTest {
private static SoundcloudPlaylistExtractor extractor;
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = (SoundcloudPlaylistExtractor) SoundCloud
.getPlaylistExtractor("https://soundcloud.com/user350509423/sets/edm-xxx");
extractor.fetchPage();
}
/*//////////////////////////////////////////////////////////////////////////
// Additional Testing
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testGetPageInNewExtractor() throws Exception {
final PlaylistExtractor newExtractor = SoundCloud.getPlaylistExtractor(extractor.getCleanUrl());
BaseListExtractorTest.defaultTestGetPageInNewExtractor(extractor, newExtractor, SoundCloud.getServiceId());
}
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testServiceId() {
assertEquals(SoundCloud.getServiceId(), extractor.getServiceId());
}
@Test
public void testName() {
assertEquals("EDM xXx", extractor.getName());
}
@Test
public void testId() {
assertEquals("136000376", extractor.getId());
}
@Test
public void testCleanUrl() {
assertEquals("https://soundcloud.com/user350509423/sets/edm-xxx", extractor.getCleanUrl());
}
@Test
public void testOriginalUrl() {
assertEquals("https://soundcloud.com/user350509423/sets/edm-xxx", extractor.getOriginalUrl());
}
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testRelatedItems() throws Exception {
BaseListExtractorTest.defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
}
@Test
public void testMoreRelatedItems() throws Exception {
ListExtractor.InfoItemPage<? extends InfoItem> currentPage = BaseListExtractorTest.defaultTestMoreItems(extractor, ServiceList.SoundCloud.getServiceId());
// Test for 2 more levels
for (int i = 0; i < 2; i++) {
currentPage = extractor.getPage(currentPage.getNextPageUrl());
BaseListExtractorTest.defaultTestListOfItems(SoundCloud.getServiceId(), currentPage.getItemsList(), currentPage.getErrors());
}
}
/*//////////////////////////////////////////////////////////////////////////
// PlaylistExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testThumbnailUrl() {
assertIsSecureUrl(extractor.getThumbnailUrl());
}
@Ignore
@Test
public void testBannerUrl() {
assertIsSecureUrl(extractor.getBannerUrl());
}
@Test
public void testUploaderUrl() {
final String uploaderUrl = extractor.getUploaderUrl();
assertIsSecureUrl(uploaderUrl);
assertTrue(uploaderUrl, uploaderUrl.contains("user350509423"));
}
@Test
public void testUploaderName() {
assertEquals("user350509423", extractor.getUploaderName());
}
@Test
public void testUploaderAvatarUrl() {
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
}
@Test
public void testStreamCount() {
assertTrue("Error in the streams count", extractor.getStreamCount() >= 3900);
}
} }
} }

View File

@ -2,125 +2,396 @@ package org.schabi.newpipe.extractor.services.youtube;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import org.schabi.newpipe.Downloader; import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest;
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmptyErrors; import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
import static org.schabi.newpipe.extractor.ServiceList.YouTube; import static org.schabi.newpipe.extractor.ServiceList.YouTube;
/*
* Created by Christian Schabesberger on 12.09.16.
*
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
* YoutubeSearchEngineStreamTest.java is part of NewPipe.
*
* NewPipe is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NewPipe is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/
/** /**
* Test for {@link ChannelExtractor} * Test for {@link ChannelExtractor}
*/ */
@RunWith(Enclosed.class)
public class YoutubeChannelExtractorTest { public class YoutubeChannelExtractorTest {
public static class Gronkh implements BaseChannelExtractorTest {
static YoutubeChannelExtractor extractor; private static YoutubeChannelExtractor extractor;
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance()); NewPipe.init(Downloader.getInstance());
extractor = (YoutubeChannelExtractor) YouTube extractor = (YoutubeChannelExtractor) YouTube
.getChannelExtractor("https://www.youtube.com/user/Gronkh"); .getChannelExtractor("http://www.youtube.com/user/Gronkh");
extractor.fetchPage(); extractor.fetchPage();
} }
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test @Test
public void testGetDownloader() throws Exception { public void testServiceId() {
assertNotNull(NewPipe.getDownloader()); assertEquals(YouTube.getServiceId(), extractor.getServiceId());
} }
@Test @Test
public void testGetName() throws Exception { public void testName() throws Exception {
assertEquals(extractor.getName(), "Gronkh"); assertEquals("Gronkh", extractor.getName());
} }
@Test @Test
public void testGetId() throws Exception { public void testId() throws Exception {
assertEquals(extractor.getId(), "UCYJ61XIK64sp6ZFFS8sctxw"); assertEquals("UCYJ61XIK64sp6ZFFS8sctxw", extractor.getId());
} }
@Test @Test
public void testGetUrl() throws Exception { public void testCleanUrl() {
assertEquals(extractor.getCleanUrl(), "https://www.youtube.com/channel/UCYJ61XIK64sp6ZFFS8sctxw"); assertEquals("https://www.youtube.com/channel/UCYJ61XIK64sp6ZFFS8sctxw", extractor.getCleanUrl());
} }
@Test @Test
public void testGetDescription() throws Exception { public void testOriginalUrl() {
assertEquals(extractor.getDescription(), "★ ★ ★ KLICK MICH HART, DU SAU! :D ★ ★ ★ Zart im Schmelz und süffig im Abgang. Ungebremster Spieltrieb seit 1896. Tägliche Folgen nonstop seit dem 01.04.2010!..."); assertEquals("http://www.youtube.com/user/Gronkh", extractor.getOriginalUrl());
}
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testRelatedItems() throws Exception {
BaseListExtractorTest.defaultTestRelatedItems(extractor, YouTube.getServiceId());
} }
@Test @Test
public void testGetAvatarUrl() throws Exception { public void testMoreRelatedItems() throws Exception {
assertTrue(extractor.getAvatarUrl(), extractor.getAvatarUrl().contains("yt3")); BaseListExtractorTest.defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
}
/*//////////////////////////////////////////////////////////////////////////
// ChannelExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testDescription() throws Exception {
assertTrue(extractor.getDescription().contains("Zart im Schmelz und süffig im Abgang. Ungebremster Spieltrieb"));
} }
@Test @Test
public void testGetBannerUrl() throws Exception { public void testAvatarUrl() throws Exception {
assertTrue(extractor.getBannerUrl(), extractor.getBannerUrl().contains("yt3")); String avatarUrl = extractor.getAvatarUrl();
assertIsSecureUrl(avatarUrl);
assertTrue(avatarUrl, avatarUrl.contains("yt3"));
} }
@Test @Test
public void testGetFeedUrl() throws Exception { public void testBannerUrl() throws Exception {
assertEquals(extractor.getFeedUrl(), "https://www.youtube.com/feeds/videos.xml?channel_id=UCYJ61XIK64sp6ZFFS8sctxw"); String bannerUrl = extractor.getBannerUrl();
assertIsSecureUrl(bannerUrl);
assertTrue(bannerUrl, bannerUrl.contains("yt3"));
} }
@Test @Test
public void testGetStreams() throws Exception { public void testFeedUrl() throws Exception {
assertTrue("no streams are received", !extractor.getInfoItems().getItemList().isEmpty()); assertEquals("https://www.youtube.com/feeds/videos.xml?channel_id=UCYJ61XIK64sp6ZFFS8sctxw", extractor.getFeedUrl());
} }
@Test @Test
public void testGetStreamsErrors() throws Exception { public void testSubscriberCount() throws Exception {
assertEmptyErrors("errors during stream list extraction", extractor.getInfoItems().getErrors()); assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 0);
}
}
public static class Kurzgesagt implements BaseChannelExtractorTest {
private static YoutubeChannelExtractor extractor;
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = (YoutubeChannelExtractor) YouTube
.getChannelExtractor("https://www.youtube.com/channel/UCsXVk37bltHxD1rDPwtNM8Q");
extractor.fetchPage();
}
/*//////////////////////////////////////////////////////////////////////////
// Additional Testing
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testGetPageInNewExtractor() throws Exception {
final ChannelExtractor newExtractor = YouTube.getChannelExtractor(extractor.getCleanUrl());
BaseListExtractorTest.defaultTestGetPageInNewExtractor(extractor, newExtractor, YouTube.getServiceId());
}
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testServiceId() {
assertEquals(YouTube.getServiceId(), extractor.getServiceId());
} }
@Test @Test
public void testHasMoreStreams() throws Exception { public void testName() throws Exception {
// Setup the streams String name = extractor.getName();
extractor.getInfoItems(); assertTrue(name, name.startsWith("Kurzgesagt"));
assertTrue("don't have more streams", extractor.hasNextPage());
} }
@Test @Test
public void testGetSubscriberCount() throws Exception { public void testId() throws Exception {
assertTrue("wrong subscriber count", extractor.getSubscriberCount() >= 0); assertEquals("UCsXVk37bltHxD1rDPwtNM8Q", extractor.getId());
} }
@Test @Test
public void testGetNextPageUrl() throws Exception { public void testCleanUrl() {
assertTrue(extractor.hasNextPage()); assertEquals("https://www.youtube.com/channel/UCsXVk37bltHxD1rDPwtNM8Q", extractor.getCleanUrl());
} }
@Test @Test
public void testGetPage() throws Exception { public void testOriginalUrl() {
// Setup the streams assertEquals("https://www.youtube.com/channel/UCsXVk37bltHxD1rDPwtNM8Q", extractor.getOriginalUrl());
extractor.getInfoItems();
ListExtractor.InfoItemPage<StreamInfoItem> nextItemsResult = extractor.getPage(extractor.getNextPageUrl());
assertTrue("extractor didn't have next streams", !nextItemsResult.getItemsList().isEmpty());
assertEmptyErrors("errors occurred during extraction of the next streams", nextItemsResult.getErrors());
assertTrue("extractor didn't have more streams after getInfoItemPage", extractor.hasNextPage());
} }
}
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testRelatedItems() throws Exception {
BaseListExtractorTest.defaultTestRelatedItems(extractor, YouTube.getServiceId());
}
@Test
public void testMoreRelatedItems() throws Exception {
BaseListExtractorTest.defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
}
/*//////////////////////////////////////////////////////////////////////////
// ChannelExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testDescription() throws Exception {
final String description = extractor.getDescription();
assertTrue(description, description.contains("small team who want to make science look beautiful"));
//TODO: Description get cuts out, because the og:description is optimized and don't have all the content
//assertTrue(description, description.contains("Currently we make one animation video per month"));
}
@Test
public void testAvatarUrl() throws Exception {
String avatarUrl = extractor.getAvatarUrl();
assertIsSecureUrl(avatarUrl);
assertTrue(avatarUrl, avatarUrl.contains("yt3"));
}
@Test
public void testBannerUrl() throws Exception {
String bannerUrl = extractor.getBannerUrl();
assertIsSecureUrl(bannerUrl);
assertTrue(bannerUrl, bannerUrl.contains("yt3"));
}
@Test
public void testFeedUrl() throws Exception {
assertEquals("https://www.youtube.com/feeds/videos.xml?channel_id=UCsXVk37bltHxD1rDPwtNM8Q", extractor.getFeedUrl());
}
@Test
public void testSubscriberCount() throws Exception {
assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 5e6);
}
}
public static class CaptainDisillusion implements BaseChannelExtractorTest {
private static YoutubeChannelExtractor extractor;
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = (YoutubeChannelExtractor) YouTube
.getChannelExtractor("https://www.youtube.com/user/CaptainDisillusion/videos");
extractor.fetchPage();
}
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testServiceId() {
assertEquals(YouTube.getServiceId(), extractor.getServiceId());
}
@Test
public void testName() throws Exception {
assertEquals("CaptainDisillusion", extractor.getName());
}
@Test
public void testId() throws Exception {
assertEquals("UCEOXxzW2vU0P-0THehuIIeg", extractor.getId());
}
@Test
public void testCleanUrl() {
assertEquals("https://www.youtube.com/channel/UCEOXxzW2vU0P-0THehuIIeg", extractor.getCleanUrl());
}
@Test
public void testOriginalUrl() {
assertEquals("https://www.youtube.com/user/CaptainDisillusion/videos", extractor.getOriginalUrl());
}
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testRelatedItems() throws Exception {
BaseListExtractorTest.defaultTestRelatedItems(extractor, YouTube.getServiceId());
}
@Test
public void testMoreRelatedItems() throws Exception {
BaseListExtractorTest.defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
}
/*//////////////////////////////////////////////////////////////////////////
// ChannelExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testDescription() throws Exception {
final String description = extractor.getDescription();
assertTrue(description, description.contains("In a world where"));
}
@Test
public void testAvatarUrl() throws Exception {
String avatarUrl = extractor.getAvatarUrl();
assertIsSecureUrl(avatarUrl);
assertTrue(avatarUrl, avatarUrl.contains("yt3"));
}
@Test
public void testBannerUrl() throws Exception {
String bannerUrl = extractor.getBannerUrl();
assertIsSecureUrl(bannerUrl);
assertTrue(bannerUrl, bannerUrl.contains("yt3"));
}
@Test
public void testFeedUrl() throws Exception {
assertEquals("https://www.youtube.com/feeds/videos.xml?channel_id=UCEOXxzW2vU0P-0THehuIIeg", extractor.getFeedUrl());
}
@Test
public void testSubscriberCount() throws Exception {
assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 5e5);
}
}
public static class RandomChannel implements BaseChannelExtractorTest {
private static YoutubeChannelExtractor extractor;
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = (YoutubeChannelExtractor) YouTube
.getChannelExtractor("https://www.youtube.com/channel/UCUaQMQS9lY5lit3vurpXQ6w");
extractor.fetchPage();
}
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testServiceId() {
assertEquals(YouTube.getServiceId(), extractor.getServiceId());
}
@Test
public void testName() throws Exception {
assertEquals("random channel", extractor.getName());
}
@Test
public void testId() throws Exception {
assertEquals("UCUaQMQS9lY5lit3vurpXQ6w", extractor.getId());
}
@Test
public void testCleanUrl() {
assertEquals("https://www.youtube.com/channel/UCUaQMQS9lY5lit3vurpXQ6w", extractor.getCleanUrl());
}
@Test
public void testOriginalUrl() {
assertEquals("https://www.youtube.com/channel/UCUaQMQS9lY5lit3vurpXQ6w", extractor.getOriginalUrl());
}
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testRelatedItems() throws Exception {
BaseListExtractorTest.defaultTestRelatedItems(extractor, YouTube.getServiceId());
}
@Test
public void testMoreRelatedItems() {
try {
BaseListExtractorTest.defaultTestMoreItems(extractor, YouTube.getServiceId());
} catch (Throwable ignored) {
return;
}
fail("This channel doesn't have more items, it should throw an error");
}
/*//////////////////////////////////////////////////////////////////////////
// ChannelExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testDescription() throws Exception {
final String description = extractor.getDescription();
assertTrue(description, description.contains("Hey there iu will upoload a load of pranks onto this channel"));
}
@Test
public void testAvatarUrl() throws Exception {
String avatarUrl = extractor.getAvatarUrl();
assertIsSecureUrl(avatarUrl);
assertTrue(avatarUrl, avatarUrl.contains("yt3"));
}
@Test
public void testBannerUrl() throws Exception {
String bannerUrl = extractor.getBannerUrl();
assertIsSecureUrl(bannerUrl);
assertTrue(bannerUrl, bannerUrl.contains("yt3"));
}
@Test
public void testFeedUrl() throws Exception {
assertEquals("https://www.youtube.com/feeds/videos.xml?channel_id=UCUaQMQS9lY5lit3vurpXQ6w", extractor.getFeedUrl());
}
@Test
public void testSubscriberCount() throws Exception {
assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 50);
}
}
};

View File

@ -1,120 +1,231 @@
package org.schabi.newpipe.extractor.services.youtube; package org.schabi.newpipe.extractor.services.youtube;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import org.schabi.newpipe.Downloader; import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
import org.schabi.newpipe.extractor.services.BasePlaylistExtractorTest;
import java.util.List; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*; import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmptyErrors;
import static org.schabi.newpipe.extractor.ServiceList.YouTube; import static org.schabi.newpipe.extractor.ServiceList.YouTube;
/** /**
* Test for {@link YoutubePlaylistExtractor} * Test for {@link YoutubePlaylistExtractor}
*/ */
@RunWith(Enclosed.class)
public class YoutubePlaylistExtractorTest { public class YoutubePlaylistExtractorTest {
public static class TimelessPopHits implements BasePlaylistExtractorTest {
private static YoutubePlaylistExtractor extractor; private static YoutubePlaylistExtractor extractor;
private static void assertNotEmpty(String message, String value) {
assertNotNull(message, value);
assertFalse(message, value.isEmpty());
}
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance()); NewPipe.init(Downloader.getInstance());
extractor = (YoutubePlaylistExtractor) YouTube extractor = (YoutubePlaylistExtractor) YouTube
.getPlaylistExtractor("https://www.youtube.com/watch?v=lp-EO5I60KA&list=PLMC9KNkIncKtPzgY-5rmhvj7fax8fdxoj"); .getPlaylistExtractor("http://www.youtube.com/watch?v=lp-EO5I60KA&list=PLMC9KNkIncKtPzgY-5rmhvj7fax8fdxoj");
extractor.fetchPage(); extractor.fetchPage();
} }
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test @Test
public void testGetDownloader() throws Exception { public void testServiceId() {
assertNotNull(NewPipe.getDownloader()); assertEquals(YouTube.getServiceId(), extractor.getServiceId());
} }
@Test @Test
public void testGetId() throws Exception { public void testName() throws Exception {
assertEquals(extractor.getId(), "PLMC9KNkIncKtPzgY-5rmhvj7fax8fdxoj"); String name = extractor.getName();
assertTrue(name, name.startsWith("Pop Music Playlist: Timeless Pop Hits"));
} }
@Test @Test
public void testGetName() throws Exception { public void testId() throws Exception {
assertEquals(extractor.getName(), "Pop Music Playlist: Timeless Pop Hits (Updated Weekly 2018)"); assertEquals("PLMC9KNkIncKtPzgY-5rmhvj7fax8fdxoj", extractor.getId());
} }
@Test @Test
public void testGetThumbnailUrl() throws Exception { public void testCleanUrl() {
assertTrue(extractor.getThumbnailUrl(), extractor.getThumbnailUrl().contains("yt")); assertEquals("https://www.youtube.com/playlist?list=PLMC9KNkIncKtPzgY-5rmhvj7fax8fdxoj", extractor.getCleanUrl());
} }
@Test @Test
public void testGetBannerUrl() throws Exception { public void testOriginalUrl() {
System.out.println(extractor.getBannerUrl()); assertEquals("http://www.youtube.com/watch?v=lp-EO5I60KA&list=PLMC9KNkIncKtPzgY-5rmhvj7fax8fdxoj", extractor.getOriginalUrl());
assertTrue(extractor.getBannerUrl(), extractor.getBannerUrl().contains("yt")); }
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testRelatedItems() throws Exception {
BaseListExtractorTest.defaultTestRelatedItems(extractor, YouTube.getServiceId());
} }
@Test @Test
public void testGetUploaderUrl() throws Exception { public void testMoreRelatedItems() throws Exception {
assertTrue(extractor.getUploaderUrl(), extractor.getUploaderUrl().contains("youtube.com")); BaseListExtractorTest.defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
}
/*//////////////////////////////////////////////////////////////////////////
// PlaylistExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testThumbnailUrl() throws Exception {
final String thumbnailUrl = extractor.getThumbnailUrl();
assertIsSecureUrl(thumbnailUrl);
assertTrue(thumbnailUrl, thumbnailUrl.contains("yt"));
} }
@Test @Test
public void testGetUploaderName() throws Exception { public void testBannerUrl() throws Exception {
assertTrue(extractor.getUploaderName(), !extractor.getUploaderName().isEmpty()); final String bannerUrl = extractor.getBannerUrl();
assertIsSecureUrl(bannerUrl);
assertTrue(bannerUrl, bannerUrl.contains("yt"));
} }
@Test @Test
public void testGetUploaderAvatarUrl() throws Exception { public void testUploaderUrl() throws Exception {
assertTrue(extractor.getUploaderAvatarUrl(), extractor.getUploaderAvatarUrl().contains("yt")); assertTrue(extractor.getUploaderUrl().contains("youtube.com"));
} }
@Test @Test
public void testGetStreamsCount() throws Exception { public void testUploaderName() throws Exception {
assertTrue("error in the streams count", extractor.getStreamCount() > 100); final String uploaderName = extractor.getUploaderName();
assertTrue(uploaderName, uploaderName.contains("Just Hits"));
} }
@Test @Test
public void testGetStreams() throws Exception { public void testUploaderAvatarUrl() throws Exception {
List<StreamInfoItem> streams = extractor.getInfoItems().getItemList(); final String uploaderAvatarUrl = extractor.getUploaderAvatarUrl();
assertFalse("no streams are received", streams.isEmpty()); assertTrue(uploaderAvatarUrl, uploaderAvatarUrl.contains("yt"));
assertTrue(streams.size() > 60);
assertFalse(streams.contains(null));
for(StreamInfoItem item: streams) {
assertEquals("Service id doesn't match", YouTube.getServiceId(), item.getServiceId());
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());
}
} }
@Test @Test
public void testGetStreamsErrors() throws Exception { public void testStreamCount() throws Exception {
assertEmptyErrors("errors during stream list extraction", extractor.getInfoItems().getErrors()); assertTrue("Error in the streams count", extractor.getStreamCount() > 100);
}
}
public static class ImportantVideos implements BasePlaylistExtractorTest {
private static YoutubePlaylistExtractor extractor;
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = (YoutubePlaylistExtractor) YouTube
.getPlaylistExtractor("https://www.youtube.com/playlist?list=PLOy0j9AvlVZPto6IkjKfpu0Scx--7PGTC");
extractor.fetchPage();
}
/*//////////////////////////////////////////////////////////////////////////
// Additional Testing
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testGetPageInNewExtractor() throws Exception {
final PlaylistExtractor newExtractor = YouTube.getPlaylistExtractor(extractor.getCleanUrl());
BaseListExtractorTest.defaultTestGetPageInNewExtractor(extractor, newExtractor, YouTube.getServiceId());
}
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testServiceId() {
assertEquals(YouTube.getServiceId(), extractor.getServiceId());
} }
@Test @Test
public void testHasMoreStreams() throws Exception { public void testName() throws Exception {
// Setup the streams String name = extractor.getName();
extractor.getInfoItems(); assertTrue(name, name.contains("Important videos"));
assertTrue("extractor didn't have more streams", extractor.hasNextPage());
} }
@Test
@Test @Ignore public void testId() throws Exception {
public void testGetNextPage() throws Exception { assertEquals("PLOy0j9AvlVZPto6IkjKfpu0Scx--7PGTC", extractor.getId());
// Setup the streams
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());
assertTrue("extractor didn't have more streams after getInfoItemPage", extractor.hasNextPage());
} }
@Test
public void testCleanUrl() {
assertEquals("https://www.youtube.com/playlist?list=PLOy0j9AvlVZPto6IkjKfpu0Scx--7PGTC", extractor.getCleanUrl());
}
@Test
public void testOriginalUrl() {
assertEquals("https://www.youtube.com/playlist?list=PLOy0j9AvlVZPto6IkjKfpu0Scx--7PGTC", extractor.getOriginalUrl());
}
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testRelatedItems() throws Exception {
BaseListExtractorTest.defaultTestRelatedItems(extractor, YouTube.getServiceId());
}
@Test
public void testMoreRelatedItems() throws Exception {
ListExtractor.InfoItemPage<? extends InfoItem> currentPage = BaseListExtractorTest.defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
// Test for 2 more levels
for (int i = 0; i < 2; i++) {
currentPage = extractor.getPage(currentPage.getNextPageUrl());
BaseListExtractorTest.defaultTestListOfItems(YouTube.getServiceId(), currentPage.getItemsList(), currentPage.getErrors());
}
}
/*//////////////////////////////////////////////////////////////////////////
// PlaylistExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testThumbnailUrl() throws Exception {
final String thumbnailUrl = extractor.getThumbnailUrl();
assertIsSecureUrl(thumbnailUrl);
assertTrue(thumbnailUrl, thumbnailUrl.contains("yt"));
}
@Test
public void testBannerUrl() throws Exception {
final String bannerUrl = extractor.getBannerUrl();
assertIsSecureUrl(bannerUrl);
assertTrue(bannerUrl, bannerUrl.contains("yt"));
}
@Test
public void testUploaderUrl() throws Exception {
assertTrue(extractor.getUploaderUrl().contains("youtube.com"));
}
@Test
public void testUploaderName() throws Exception {
assertEquals("Crazy Horse", extractor.getUploaderName());
}
@Test
public void testUploaderAvatarUrl() throws Exception {
final String uploaderAvatarUrl = extractor.getUploaderAvatarUrl();
assertTrue(uploaderAvatarUrl, uploaderAvatarUrl.contains("yt"));
}
@Test
public void testStreamCount() throws Exception {
assertTrue("Error in the streams count", extractor.getStreamCount() > 100);
}
}
} }