Skip to content

Commit

Permalink
Merge pull request #53 from coffeemakr/bugfix-channel-extractor
Browse files Browse the repository at this point in the history
Fix channel info item collector
  • Loading branch information
theScrabi authored Dec 7, 2017
2 parents 4f62d96 + f76cc49 commit 17ce9f5
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public ChannelInfoItem extract(ChannelInfoItemExtractor extractor) throws Parsin
String name = extractor.getName();
String url = extractor.getUrl();

ChannelInfoItem resultItem = new ChannelInfoItem(serviceId, name, url);
ChannelInfoItem resultItem = new ChannelInfoItem(serviceId, url, name);


// optional information
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/org/schabi/newpipe/extractor/ExtractorAsserts.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.schabi.newpipe.extractor;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

public class ExtractorAsserts {
Expand All @@ -11,4 +13,12 @@ public static void assertEmptyErrors(String message, List<Throwable> errors) {
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
import org.junit.Ignore;
import org.junit.Test;
import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.InfoItem;
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.SearchResult;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.net.MalformedURLException;
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.
Expand Down Expand Up @@ -42,16 +48,27 @@ public static void setUpClass() throws Exception {
NewPipe.init(Downloader.getInstance());
YoutubeSearchEngine engine = new YoutubeSearchEngine(1);

// Youtube will suggest "asdf" instead of "asdgff"
// keep in mind that the suggestions can change by country (the parameter "de")
result = engine.search("asdgff", 0, "de", SearchEngine.Filter.ANY)
result = engine.search("pewdiepie", 0, "de", SearchEngine.Filter.ANY)
.getSearchResult();
}

@Test
public void testResultList() {
System.out.println("Results: " + result.getResults());
assertFalse("Results are empty: " + result.resultList, result.resultList.isEmpty());
final List<InfoItem> results = result.getResults();
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.schabi.newpipe.extractor.search.SearchResult;

import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsValidUrl;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;


Expand Down Expand Up @@ -53,6 +54,9 @@ public void setUp() throws Exception {
@Test
public void testResultList() {
assertFalse(result.resultList.isEmpty());
for(InfoItem item: result.getResults()) {
assertIsValidUrl(item.url);
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.schabi.newpipe.extractor.search.SearchResult;

import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsValidUrl;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;


Expand Down Expand Up @@ -53,6 +54,9 @@ public void setUp() throws Exception {
@Test
public void testResultList() {
assertFalse(result.resultList.isEmpty());
for(InfoItem item: result.getResults()) {
assertIsValidUrl(item.url);
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.schabi.newpipe.extractor.search.SearchResult;

import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsValidUrl;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;


Expand Down Expand Up @@ -53,6 +54,9 @@ public void setUp() throws Exception {
@Test
public void testResultList() {
assertFalse(result.resultList.isEmpty());
for(InfoItem item: result.getResults()) {
assertIsValidUrl(item.url);
}
}

@Test
Expand Down

0 comments on commit 17ce9f5

Please sign in to comment.