Merge pull request #53 from coffeemakr/bugfix-channel-extractor
Fix channel info item collector
This commit is contained in:
commit
17ce9f537e
|
@ -35,7 +35,7 @@ public class ChannelInfoItemCollector extends InfoItemCollector<ChannelInfoItem,
|
||||||
String name = extractor.getName();
|
String name = extractor.getName();
|
||||||
String url = extractor.getUrl();
|
String url = extractor.getUrl();
|
||||||
|
|
||||||
ChannelInfoItem resultItem = new ChannelInfoItem(serviceId, name, url);
|
ChannelInfoItem resultItem = new ChannelInfoItem(serviceId, url, name);
|
||||||
|
|
||||||
|
|
||||||
// optional information
|
// optional information
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.schabi.newpipe.extractor;
|
package org.schabi.newpipe.extractor;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ExtractorAsserts {
|
public class ExtractorAsserts {
|
||||||
|
@ -11,4 +13,12 @@ public class ExtractorAsserts {
|
||||||
throw new AssertionError(message, errors.get(0));
|
throw new AssertionError(message, errors.get(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void assertIsValidUrl(String url) {
|
||||||
|
try {
|
||||||
|
new URL(url);
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
throw new AssertionError("Invalid url: " + url, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,18 @@ import org.junit.BeforeClass;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.schabi.newpipe.Downloader;
|
import org.schabi.newpipe.Downloader;
|
||||||
|
import org.schabi.newpipe.extractor.InfoItem;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
|
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
|
||||||
import org.schabi.newpipe.extractor.search.SearchEngine;
|
import org.schabi.newpipe.extractor.search.SearchEngine;
|
||||||
import org.schabi.newpipe.extractor.search.SearchResult;
|
import org.schabi.newpipe.extractor.search.SearchResult;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import java.net.MalformedURLException;
|
||||||
import static org.junit.Assert.assertTrue;
|
import java.net.URL;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsValidUrl;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Created by Christian Schabesberger on 29.12.15.
|
* Created by Christian Schabesberger on 29.12.15.
|
||||||
|
@ -42,16 +48,27 @@ public class YoutubeSearchEngineAllTest {
|
||||||
NewPipe.init(Downloader.getInstance());
|
NewPipe.init(Downloader.getInstance());
|
||||||
YoutubeSearchEngine engine = new YoutubeSearchEngine(1);
|
YoutubeSearchEngine engine = new YoutubeSearchEngine(1);
|
||||||
|
|
||||||
// Youtube will suggest "asdf" instead of "asdgff"
|
result = engine.search("pewdiepie", 0, "de", SearchEngine.Filter.ANY)
|
||||||
// keep in mind that the suggestions can change by country (the parameter "de")
|
|
||||||
result = engine.search("asdgff", 0, "de", SearchEngine.Filter.ANY)
|
|
||||||
.getSearchResult();
|
.getSearchResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResultList() {
|
public void testResultList() {
|
||||||
System.out.println("Results: " + result.getResults());
|
final List<InfoItem> results = result.getResults();
|
||||||
assertFalse("Results are empty: " + result.resultList, result.resultList.isEmpty());
|
System.out.println("Results: " + results);
|
||||||
|
assertFalse("Results are empty: " + results, results.isEmpty());
|
||||||
|
|
||||||
|
InfoItem firstInfoItem = results.get(0);
|
||||||
|
|
||||||
|
// THe channel should be the first item
|
||||||
|
assertTrue(firstInfoItem instanceof ChannelInfoItem);
|
||||||
|
assertEquals("name", "PewDiePie", firstInfoItem.name);
|
||||||
|
assertEquals("url","https://www.youtube.com/user/PewDiePie", firstInfoItem.url);
|
||||||
|
|
||||||
|
for(InfoItem item: results) {
|
||||||
|
assertIsValidUrl(item.url);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.schabi.newpipe.extractor.search.SearchEngine;
|
||||||
import org.schabi.newpipe.extractor.search.SearchResult;
|
import org.schabi.newpipe.extractor.search.SearchResult;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsValidUrl;
|
||||||
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,6 +54,9 @@ public class YoutubeSearchEngineChannelTest {
|
||||||
@Test
|
@Test
|
||||||
public void testResultList() {
|
public void testResultList() {
|
||||||
assertFalse(result.resultList.isEmpty());
|
assertFalse(result.resultList.isEmpty());
|
||||||
|
for(InfoItem item: result.getResults()) {
|
||||||
|
assertIsValidUrl(item.url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.schabi.newpipe.extractor.search.SearchEngine;
|
||||||
import org.schabi.newpipe.extractor.search.SearchResult;
|
import org.schabi.newpipe.extractor.search.SearchResult;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsValidUrl;
|
||||||
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,6 +54,9 @@ public class YoutubeSearchEnginePlaylistTest {
|
||||||
@Test
|
@Test
|
||||||
public void testResultList() {
|
public void testResultList() {
|
||||||
assertFalse(result.resultList.isEmpty());
|
assertFalse(result.resultList.isEmpty());
|
||||||
|
for(InfoItem item: result.getResults()) {
|
||||||
|
assertIsValidUrl(item.url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.schabi.newpipe.extractor.search.SearchEngine;
|
||||||
import org.schabi.newpipe.extractor.search.SearchResult;
|
import org.schabi.newpipe.extractor.search.SearchResult;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsValidUrl;
|
||||||
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,6 +54,9 @@ public class YoutubeSearchEngineStreamTest {
|
||||||
@Test
|
@Test
|
||||||
public void testResultList() {
|
public void testResultList() {
|
||||||
assertFalse(result.resultList.isEmpty());
|
assertFalse(result.resultList.isEmpty());
|
||||||
|
for(InfoItem item: result.getResults()) {
|
||||||
|
assertIsValidUrl(item.url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue