Commit 1a322ad8 authored by bopol's avatar bopol
Browse files

Add uploader verified by service extraction

parent db253e20
......@@ -7,4 +7,5 @@ public interface BaseChannelExtractorTest extends BaseListExtractorTest {
void testBannerUrl() throws Exception;
void testFeedUrl() throws Exception;
void testSubscriberCount() throws Exception;
void testVerified() throws Exception;
}
......@@ -7,4 +7,5 @@ public interface BasePlaylistExtractorTest extends BaseListExtractorTest {
void testUploaderName() throws Exception;
void testUploaderAvatarUrl() throws Exception;
void testStreamCount() throws Exception;
void testUploaderVerified() throws Exception;
}
......@@ -45,6 +45,7 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest<St
public abstract StreamType expectedStreamType();
public abstract String expectedUploaderName();
public abstract String expectedUploaderUrl();
public boolean expectedUploaderVerified() { return false; }
public String expectedSubChannelName() { return ""; } // default: there is no subchannel
public String expectedSubChannelUrl() { return ""; } // default: there is no subchannel
public abstract List<String> expectedDescriptionContains(); // e.g. for full links
......@@ -99,6 +100,11 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest<St
assertIsSecureUrl(extractor().getUploaderAvatarUrl());
}
@Test
public void testUploaderVerified() throws Exception {
assertEquals(expectedUploaderVerified(), extractor().isUploaderVerified());
}
@Test
@Override
public void testSubChannelName() throws Exception {
......
......@@ -104,6 +104,11 @@ public class PeertubeAccountExtractorTest {
public void testSubscriberCount() throws ParsingException {
assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 500);
}
@Override
public void testVerified() throws Exception {
assertFalse(extractor.isVerified());
}
}
public static class FreeSoftwareFoundation implements BaseChannelExtractorTest {
......@@ -200,5 +205,10 @@ public class PeertubeAccountExtractorTest {
public void testSubscriberCount() throws ParsingException {
assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 100);
}
@Override
public void testVerified() throws Exception {
assertFalse(extractor.isVerified());
}
}
}
package org.schabi.newpipe.extractor.services.peertube;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.extractor.NewPipe;
......@@ -119,6 +118,11 @@ public class PeertubeChannelExtractorTest {
public void testSubscriberCount() throws ParsingException {
assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 230);
}
@Override
public void testVerified() throws Exception {
assertFalse(extractor.isVerified());
}
}
public static class ChatSceptique implements BaseChannelExtractorTest {
......@@ -231,5 +235,10 @@ public class PeertubeChannelExtractorTest {
public void testSubscriberCount() throws ParsingException {
assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 700);
}
@Override
public void testVerified() throws Exception {
assertFalse(extractor.isVerified());
}
}
}
......@@ -101,6 +101,11 @@ public class SoundcloudChannelExtractorTest {
public void testSubscriberCount() {
assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 1e6);
}
@Override
public void testVerified() throws Exception {
assertTrue(extractor.isVerified());
}
}
public static class DubMatix implements BaseChannelExtractorTest {
......@@ -195,5 +200,10 @@ public class SoundcloudChannelExtractorTest {
public void testSubscriberCount() {
assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 2e6);
}
@Override
public void testVerified() throws Exception {
assertTrue(extractor.isVerified());
}
}
}
......@@ -111,6 +111,11 @@ public class SoundcloudPlaylistExtractorTest {
public void testStreamCount() {
assertTrue("Stream count does not fit: " + extractor.getStreamCount(), extractor.getStreamCount() >= 10);
}
@Override
public void testUploaderVerified() throws Exception {
assertTrue(extractor.isUploaderVerified());
}
}
public static class RandomHouseMusic implements BasePlaylistExtractorTest {
......@@ -203,6 +208,11 @@ public class SoundcloudPlaylistExtractorTest {
public void testStreamCount() {
assertTrue("Stream count does not fit: " + extractor.getStreamCount(), extractor.getStreamCount() >= 10);
}
@Override
public void testUploaderVerified() throws Exception {
assertFalse(extractor.isUploaderVerified());
}
}
public static class EDMxxx implements BasePlaylistExtractorTest {
......@@ -310,6 +320,11 @@ public class SoundcloudPlaylistExtractorTest {
public void testStreamCount() {
assertTrue("Stream count does not fit: " + extractor.getStreamCount(), extractor.getStreamCount() >= 370);
}
@Override
public void testUploaderVerified() throws Exception {
assertFalse(extractor.isUploaderVerified());
}
}
public static class SmallPlaylist implements BasePlaylistExtractorTest {
......@@ -409,5 +424,10 @@ public class SoundcloudPlaylistExtractorTest {
public void testStreamCount() {
assertEquals(2, extractor.getStreamCount());
}
@Override
public void testUploaderVerified() throws Exception {
assertFalse(extractor.isUploaderVerified());
}
}
}
......@@ -8,14 +8,19 @@ import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.search.SearchExtractor;
import org.schabi.newpipe.extractor.services.DefaultSearchExtractorTest;
import javax.annotation.Nullable;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;
import static java.util.Collections.singletonList;
import static org.junit.Assert.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoDuplicatedItems;
import static org.schabi.newpipe.extractor.services.soundcloud.linkHandler.SoundcloudSearchQueryHandlerFactory.*;
......@@ -139,4 +144,40 @@ public class SoundcloudSearchExtractorTest {
throw new RuntimeException(e);
}
}
public static class UserVerified extends DefaultSearchExtractorTest {
private static SearchExtractor extractor;
private static final String QUERY = "David Guetta";
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = SoundCloud.getSearchExtractor(QUERY, singletonList(USERS), "");
extractor.fetchPage();
}
@Override public SearchExtractor extractor() { return extractor; }
@Override public StreamingService expectedService() { return SoundCloud; }
@Override public String expectedName() { return QUERY; }
@Override public String expectedId() { return QUERY; }
@Override public String expectedUrlContains() { return "soundcloud.com/search/users?q=" + urlEncode(QUERY); }
@Override public String expectedOriginalUrlContains() { return "soundcloud.com/search/users?q=" + urlEncode(QUERY); }
@Override public String expectedSearchString() { return QUERY; }
@Nullable @Override public String expectedSearchSuggestion() { return null; }
@Override public InfoItem.InfoType expectedInfoItemType() { return InfoItem.InfoType.CHANNEL; }
@Test
public void testIsVerified() throws IOException, ExtractionException {
final List<InfoItem> items = extractor.getInitialPage().getItems();
boolean verified = false;
for (InfoItem item : items) {
if (item.getUrl().equals("https://soundcloud.com/davidguetta")) {
verified = ((ChannelInfoItem) item).isVerified();
break;
}
}
assertTrue(verified);
}
}
}
......@@ -16,14 +16,10 @@ import java.io.IOException;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestGetPageInNewExtractor;
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestMoreItems;
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems;
import static org.schabi.newpipe.extractor.services.DefaultTests.*;
/**
* Test for {@link ChannelExtractor}
......@@ -157,6 +153,12 @@ public class YoutubeChannelExtractorTest {
assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 0);
assertTrue("Subscriber count too small", extractor.getSubscriberCount() >= 4e6);
}
@Override
public void testVerified() throws Exception {
assertTrue(extractor.isVerified());
}
}
// Youtube RED/Premium ad blocking test
......@@ -250,6 +252,11 @@ public class YoutubeChannelExtractorTest {
assertTrue("Subscriber count too small", extractor.getSubscriberCount() >= 10e6);
}
@Override
public void testVerified() throws Exception {
assertTrue(extractor.isVerified());
}
}
public static class Kurzgesagt implements BaseChannelExtractorTest {
......@@ -343,6 +350,11 @@ public class YoutubeChannelExtractorTest {
public void testSubscriberCount() throws Exception {
assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 5e6);
}
@Override
public void testVerified() throws Exception {
assertTrue(extractor.isVerified());
}
}
public static class KurzgesagtAdditional {
......@@ -453,6 +465,11 @@ public class YoutubeChannelExtractorTest {
public void testSubscriberCount() throws Exception {
assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 5e5);
}
@Override
public void testVerified() throws Exception {
assertTrue(extractor.isVerified());
}
}
public static class RandomChannel implements BaseChannelExtractorTest {
......@@ -550,6 +567,11 @@ public class YoutubeChannelExtractorTest {
long subscribers = extractor.getSubscriberCount();
assertTrue("Wrong subscriber count: " + subscribers, subscribers >= 50);
}
@Override
public void testVerified() throws Exception {
assertFalse(extractor.isVerified());
}
}
}
......@@ -13,11 +13,7 @@ import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.services.BasePlaylistExtractorTest;
import org.schabi.newpipe.extractor.services.youtube.YoutubePlaylistExtractorTest.ContinuationsTests;
import org.schabi.newpipe.extractor.services.youtube.YoutubePlaylistExtractorTest.HugePlaylist;
import org.schabi.newpipe.extractor.services.youtube.YoutubePlaylistExtractorTest.LearningPlaylist;
import org.schabi.newpipe.extractor.services.youtube.YoutubePlaylistExtractorTest.NotAvailable;
import org.schabi.newpipe.extractor.services.youtube.YoutubePlaylistExtractorTest.TimelessPopHits;
import org.schabi.newpipe.extractor.services.youtube.YoutubePlaylistExtractorTest.*;
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubePlaylistExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
......@@ -39,7 +35,7 @@ import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRela
*/
@RunWith(Suite.class)
@SuiteClasses({NotAvailable.class, TimelessPopHits.class, HugePlaylist.class,
LearningPlaylist.class, ContinuationsTests.class})
LearningPlaylist.class, ContinuationsTests.class})
public class YoutubePlaylistExtractorTest {
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/playlist/";
......@@ -163,6 +159,11 @@ public class YoutubePlaylistExtractorTest {
public void testStreamCount() throws Exception {
assertTrue("Error in the streams count", extractor.getStreamCount() > 100);
}
@Override
public void testUploaderVerified() throws Exception {
assertFalse(extractor.isUploaderVerified());
}
}
public static class HugePlaylist implements BasePlaylistExtractorTest {
......@@ -276,6 +277,11 @@ public class YoutubePlaylistExtractorTest {
public void testStreamCount() throws Exception {
assertTrue("Error in the streams count", extractor.getStreamCount() > 100);
}
@Override
public void testUploaderVerified() throws Exception {
assertTrue(extractor.isUploaderVerified());
}
}
public static class LearningPlaylist implements BasePlaylistExtractorTest {
......@@ -375,6 +381,11 @@ public class YoutubePlaylistExtractorTest {
public void testStreamCount() throws Exception {
assertTrue("Error in the streams count", extractor.getStreamCount() > 40);
}
@Override
public void testUploaderVerified() throws Exception {
assertTrue(extractor.isUploaderVerified());
}
}
public static class ContinuationsTests {
......@@ -388,8 +399,8 @@ public class YoutubePlaylistExtractorTest {
@Test
public void testNoContinuations() throws Exception {
final YoutubePlaylistExtractor extractor = (YoutubePlaylistExtractor) YouTube
.getPlaylistExtractor(
"https://www.youtube.com/playlist?list=PLXJg25X-OulsVsnvZ7RVtSDW-id9_RzAO");
.getPlaylistExtractor(
"https://www.youtube.com/playlist?list=PLXJg25X-OulsVsnvZ7RVtSDW-id9_RzAO");
extractor.fetchPage();
assertNoMoreItems(extractor);
......@@ -398,12 +409,12 @@ public class YoutubePlaylistExtractorTest {
@Test
public void testOnlySingleContinuation() throws Exception {
final YoutubePlaylistExtractor extractor = (YoutubePlaylistExtractor) YouTube
.getPlaylistExtractor(
"https://www.youtube.com/playlist?list=PLjgwFL8urN2DFRuRkFTkmtHjyoNWHHdZX");
.getPlaylistExtractor(
"https://www.youtube.com/playlist?list=PLjgwFL8urN2DFRuRkFTkmtHjyoNWHHdZX");
extractor.fetchPage();
final ListExtractor.InfoItemsPage<StreamInfoItem> page = defaultTestMoreItems(
extractor);
extractor);
assertFalse("More items available when it shouldn't", page.hasNextPage());
}
}
......
......@@ -13,14 +13,19 @@ import org.schabi.newpipe.extractor.services.DefaultSearchExtractorTest;
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper;
import org.schabi.newpipe.extractor.stream.Description;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import javax.annotation.Nullable;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
import static java.util.Collections.singletonList;
import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.assertEquals;
......@@ -31,7 +36,6 @@ import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoDuplica
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.CHANNELS;
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.PLAYLISTS;
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.VIDEOS;
import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING;
public class YoutubeSearchExtractorTest {
......@@ -269,4 +273,41 @@ public class YoutubeSearchExtractorTest {
@Override public String expectedOriginalUrlContains() throws Exception { return "youtube.com/results?search_query=" + QUERY; }
}
public static class ChannelVerified extends DefaultSearchExtractorTest {
private static SearchExtractor extractor;
private static final String QUERY = "bbc";
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = YouTube.getSearchExtractor(QUERY, singletonList(CHANNELS), "");
extractor.fetchPage();
}
@Override public SearchExtractor extractor() { return extractor; }
@Override public StreamingService expectedService() { return YouTube; }
@Override public String expectedName() { return QUERY; }
@Override public String expectedId() { return QUERY; }
@Override public String expectedUrlContains() { return "youtube.com/results?search_query=" + QUERY; }
@Override public String expectedOriginalUrlContains() { return "youtube.com/results?search_query=" + QUERY; }
@Override public String expectedSearchString() { return QUERY; }
@Nullable @Override public String expectedSearchSuggestion() { return null; }
@Override public InfoItem.InfoType expectedInfoItemType() { return InfoItem.InfoType.CHANNEL; }
@Test
public void testAtLeastOneVerified() throws IOException, ExtractionException {
final List<InfoItem> items = extractor.getInitialPage().getItems();
boolean verified = false;
for (InfoItem item : items) {
if (((ChannelInfoItem) item).isVerified()) {
verified = true;
break;
}
}
assertTrue(verified);
}
}
}
......@@ -41,6 +41,7 @@ public class YoutubeStreamExtractorAgeRestrictedTest extends DefaultStreamExtrac
@Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; }
@Override public String expectedUploaderName() { return "EpicFiveTV"; }
@Override public String expectedUploaderUrl() { return "https://www.youtube.com/channel/UCuPUHlLP5POZphOIrjrNxiw"; }
@Override public boolean expectedUploaderVerified() { return true; }
@Override public List<String> expectedDescriptionContains() { return Arrays.asList("http://instagram.com/Ruben_Sole", "AVN"); }
@Override public long expectedLength() { return 1790; }
@Override public long expectedTimestamp() { return TIMESTAMP; }
......
......@@ -103,6 +103,7 @@ public class YoutubeStreamExtractorDefaultTest {
return Arrays.asList("https://www.youtube.com/channel/UC7l23W7gFi4Uho6WSzckZRA",
"https://www.handcraftpictures.com/");
}
@Override public boolean expectedUploaderVerified() { return true; }
@Override public long expectedLength() { return 381; }
@Override public long expectedTimestamp() { return TIMESTAMP; }
@Override public long expectedViewCountAtLeast() { return 26682500; }
......@@ -150,6 +151,7 @@ public class YoutubeStreamExtractorDefaultTest {
@Nullable @Override public String expectedTextualUploadDate() { return "2018-06-19"; }
@Override public long expectedLikeCountAtLeast() { return 340100; }
@Override public long expectedDislikeCountAtLeast() { return 18700; }
@Override public boolean expectedUploaderVerified() { return true; }
// @formatter:on
@Override
@Test
......@@ -271,6 +273,7 @@ public class YoutubeStreamExtractorDefaultTest {
@Override public String expectedUploaderName() { return "maiLab"; }
@Override public String expectedUploaderUrl() { return "https://www.youtube.com/channel/UCyHDQ5C6z1NDmJ4g6SerW8g"; }
@Override public List<String> expectedDescriptionContains() {return Arrays.asList("Vitamin", "2:44", "Was ist Vitamin D?");}
@Override public boolean expectedUploaderVerified() { return true; }
@Override public long expectedLength() { return 1010; }
@Override public long expectedViewCountAtLeast() { return 815500; }
@Nullable @Override public String expectedUploadDate() { return "2020-11-18 00:00:00.000"; }
......@@ -339,6 +342,7 @@ public class YoutubeStreamExtractorDefaultTest {
Collections.singletonList("Wikipedia (German)")
));
}
@Override public boolean expectedUploaderVerified() { return true; }
// @formatter:on
@Override
@Ignore("TODO fix")
......
......@@ -45,6 +45,7 @@ public class YoutubeStreamExtractorLivestreamTest extends DefaultStreamExtractor
return Arrays.asList("https://bit.ly/chilledcow-playlists",
"https://bit.ly/chilledcow-submissions");
}
@Override public boolean expectedUploaderVerified() { return true; }
@Override public long expectedLength() { return 0; }
@Override public long expectedTimestamp() { return TIMESTAMP; }
@Override public long expectedViewCountAtLeast() { return 0; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment