fix search querry tests

This commit is contained in:
Christian Schabesberger 2018-08-05 14:14:36 +02:00
parent 701666f498
commit aeb813840d
11 changed files with 120 additions and 109 deletions

View File

@ -67,10 +67,10 @@ public abstract class StreamingService {
//////////////////////////////////////////// ////////////////////////////////////////////
// Url Id handler // Url Id handler
//////////////////////////////////////////// ////////////////////////////////////////////
public abstract LinkHandlerFactory getStreamUIHFactory(); public abstract LinkHandlerFactory getStreamLHFactory();
public abstract ListLinkHandlerFactory getChannelUIHFactory(); public abstract ListLinkHandlerFactory getChannelLHFactory();
public abstract ListLinkHandlerFactory getPlaylistUIHFactory(); public abstract ListLinkHandlerFactory getPlaylistLHFactory();
public abstract SearchQueryHandlerFactory getSearchQIHFactory(); public abstract SearchQueryHandlerFactory getSearchQHFactory();
//////////////////////////////////////////// ////////////////////////////////////////////
@ -86,31 +86,31 @@ public abstract class StreamingService {
public abstract StreamExtractor getStreamExtractor(LinkHandler UIHFactory) throws ExtractionException; public abstract StreamExtractor getStreamExtractor(LinkHandler UIHFactory) throws ExtractionException;
public SearchExtractor getSearchExtractor(String query, List<String> contentFilter, String sortFilter, String contentCountry) throws ExtractionException { public SearchExtractor getSearchExtractor(String query, List<String> contentFilter, String sortFilter, String contentCountry) throws ExtractionException {
return getSearchExtractor(getSearchQIHFactory().fromQuery(query, contentFilter, sortFilter), contentCountry); return getSearchExtractor(getSearchQHFactory().fromQuery(query, contentFilter, sortFilter), contentCountry);
} }
public ChannelExtractor getChannelExtractor(String id, List<String> contentFilter, String sortFilter) throws ExtractionException { public ChannelExtractor getChannelExtractor(String id, List<String> contentFilter, String sortFilter) throws ExtractionException {
return getChannelExtractor(getChannelUIHFactory().fromQuery(id, contentFilter, sortFilter)); return getChannelExtractor(getChannelLHFactory().fromQuery(id, contentFilter, sortFilter));
} }
public PlaylistExtractor getPlaylistExtractor(String id, List<String> contentFilter, String sortFilter) throws ExtractionException { public PlaylistExtractor getPlaylistExtractor(String id, List<String> contentFilter, String sortFilter) throws ExtractionException {
return getPlaylistExtractor(getPlaylistUIHFactory().fromQuery(id, contentFilter, sortFilter)); return getPlaylistExtractor(getPlaylistLHFactory().fromQuery(id, contentFilter, sortFilter));
} }
public SearchExtractor getSearchExtractor(String query, String contentCountry) throws ExtractionException { public SearchExtractor getSearchExtractor(String query, String contentCountry) throws ExtractionException {
return getSearchExtractor(getSearchQIHFactory().fromQuery(query), contentCountry); return getSearchExtractor(getSearchQHFactory().fromQuery(query), contentCountry);
} }
public ChannelExtractor getChannelExtractor(String url) throws ExtractionException { public ChannelExtractor getChannelExtractor(String url) throws ExtractionException {
return getChannelExtractor(getChannelUIHFactory().fromUrl(url)); return getChannelExtractor(getChannelLHFactory().fromUrl(url));
} }
public PlaylistExtractor getPlaylistExtractor(String url) throws ExtractionException { public PlaylistExtractor getPlaylistExtractor(String url) throws ExtractionException {
return getPlaylistExtractor(getPlaylistUIHFactory().fromUrl(url)); return getPlaylistExtractor(getPlaylistLHFactory().fromUrl(url));
} }
public StreamExtractor getStreamExtractor(String url) throws ExtractionException { public StreamExtractor getStreamExtractor(String url) throws ExtractionException {
return getStreamExtractor(getStreamUIHFactory().fromUrl(url)); return getStreamExtractor(getStreamLHFactory().fromUrl(url));
} }
@ -119,9 +119,9 @@ public abstract class StreamingService {
* figure out where the link is pointing to (a channel, video, playlist, etc.) * figure out where the link is pointing to (a channel, video, playlist, etc.)
*/ */
public final LinkType getLinkTypeByUrl(String url) throws ParsingException { public final LinkType getLinkTypeByUrl(String url) throws ParsingException {
LinkHandlerFactory sH = getStreamUIHFactory(); LinkHandlerFactory sH = getStreamLHFactory();
LinkHandlerFactory cH = getChannelUIHFactory(); LinkHandlerFactory cH = getChannelLHFactory();
LinkHandlerFactory pH = getPlaylistUIHFactory(); LinkHandlerFactory pH = getPlaylistLHFactory();
if (sH.acceptUrl(url)) { if (sH.acceptUrl(url)) {
return LinkType.STREAM; return LinkType.STREAM;

View File

@ -26,22 +26,22 @@ public class SoundcloudService extends StreamingService {
} }
@Override @Override
public SearchQueryHandlerFactory getSearchQIHFactory() { public SearchQueryHandlerFactory getSearchQHFactory() {
return new SoundcloudSearchQueryHandlerFactory(); return new SoundcloudSearchQueryHandlerFactory();
} }
@Override @Override
public LinkHandlerFactory getStreamUIHFactory() { public LinkHandlerFactory getStreamLHFactory() {
return SoundcloudStreamLinkHandlerFactory.getInstance(); return SoundcloudStreamLinkHandlerFactory.getInstance();
} }
@Override @Override
public ListLinkHandlerFactory getChannelUIHFactory() { public ListLinkHandlerFactory getChannelLHFactory() {
return SoundcloudChannelLinkHandlerFactory.getInstance(); return SoundcloudChannelLinkHandlerFactory.getInstance();
} }
@Override @Override
public ListLinkHandlerFactory getPlaylistUIHFactory() { public ListLinkHandlerFactory getPlaylistLHFactory() {
return SoundcloudPlaylistLinkHandlerFactory.getInstance(); return SoundcloudPlaylistLinkHandlerFactory.getInstance();
} }

View File

@ -31,7 +31,7 @@ public class SoundcloudSubscriptionExtractor extends SubscriptionExtractor {
String id; String id;
try { try {
id = service.getChannelUIHFactory().fromUrl(getUrlFrom(channelUrl)).getId(); id = service.getChannelLHFactory().fromUrl(getUrlFrom(channelUrl)).getId();
} catch (ExtractionException e) { } catch (ExtractionException e) {
throw new InvalidSourceException(e); throw new InvalidSourceException(e);
} }

View File

@ -49,22 +49,22 @@ public class YoutubeService extends StreamingService {
} }
@Override @Override
public LinkHandlerFactory getStreamUIHFactory() { public LinkHandlerFactory getStreamLHFactory() {
return YoutubeStreamLinkHandlerFactory.getInstance(); return YoutubeStreamLinkHandlerFactory.getInstance();
} }
@Override @Override
public ListLinkHandlerFactory getChannelUIHFactory() { public ListLinkHandlerFactory getChannelLHFactory() {
return YoutubeChannelLinkHandlerFactory.getInstance(); return YoutubeChannelLinkHandlerFactory.getInstance();
} }
@Override @Override
public ListLinkHandlerFactory getPlaylistUIHFactory() { public ListLinkHandlerFactory getPlaylistLHFactory() {
return YoutubePlaylistLinkHandlerFactory.getInstance(); return YoutubePlaylistLinkHandlerFactory.getInstance();
} }
@Override @Override
public SearchQueryHandlerFactory getSearchQIHFactory() { public SearchQueryHandlerFactory getSearchQHFactory() {
return YoutubeSearchQueryHandlerFactory.getInstance(); return YoutubeSearchQueryHandlerFactory.getInstance();
} }

View File

@ -175,7 +175,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
private void collectStreamsFrom(StreamInfoItemsCollector collector, Element element) { private void collectStreamsFrom(StreamInfoItemsCollector collector, Element element) {
collector.reset(); collector.reset();
final LinkHandlerFactory streamLinkHandlerFactory = getService().getStreamUIHFactory(); final LinkHandlerFactory streamLinkHandlerFactory = getService().getStreamLHFactory();
for (final Element li : element.children()) { for (final Element li : element.children()) {
if(isDeletedItem(li)) { if(isDeletedItem(li)) {
continue; continue;

View File

@ -48,18 +48,22 @@ public class YoutubePlaylistInfoItemExtractor implements PlaylistInfoItemExtract
@Override @Override
public String getUrl() throws ParsingException { public String getUrl() throws ParsingException {
String url;
try { try {
final Element href = el.select("div[class=\"yt-lockup-meta\"]").first() final Element div = el.select("div[class=\"yt-lockup-meta\"]").first();
.select("a").first();
if(div != null) {
final Element a = div.select("a").first();
return a.attr("abs:href");
}
// this is for yt premium playlists
return el.select("h3[class=\"yt-lockup-title\"").first()
.select("a").first()
.attr("abs:href");
url = href.attr("abs:href");
} catch (Exception e) { } catch (Exception e) {
throw new ParsingException("Failed to extract playlist url", e); throw new ParsingException("Failed to extract playlist url", e);
} }
return url;
} }
@Override @Override

View File

@ -27,7 +27,7 @@ public class SoundcloudSubscriptionExtractorTest {
public static void setupClass() { public static void setupClass() {
NewPipe.init(Downloader.getInstance()); NewPipe.init(Downloader.getInstance());
subscriptionExtractor = new SoundcloudSubscriptionExtractor(ServiceList.SoundCloud); subscriptionExtractor = new SoundcloudSubscriptionExtractor(ServiceList.SoundCloud);
urlHandler = ServiceList.SoundCloud.getChannelUIHFactory(); urlHandler = ServiceList.SoundCloud.getChannelLHFactory();
} }
@Test @Test

View File

@ -8,8 +8,11 @@ import org.schabi.newpipe.extractor.NewPipe;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudSearchQueryHandlerFactory.PLAYLISTS;
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudSearchQueryHandlerFactory.TRACKS;
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudSearchQueryHandlerFactory.USERS;
public class SoundcloudSearchQUHTest { public class SoundcloudSearchQHTest {
@BeforeClass @BeforeClass
public static void setUpClass() throws Exception { public static void setUpClass() throws Exception {
@ -24,50 +27,50 @@ public class SoundcloudSearchQUHTest {
@Test @Test
public void testRegularValues() throws Exception { public void testRegularValues() throws Exception {
assertEquals("https://api-v2.soundcloud.com/search?q=asdf&limit=10&offset=0", assertEquals("https://api-v2.soundcloud.com/search?q=asdf&limit=10&offset=0",
removeClientId(SoundCloud.getSearchQIHFactory().fromQuery("asdf").getUrl())); removeClientId(SoundCloud.getSearchQHFactory().fromQuery("asdf").getUrl()));
assertEquals("https://api-v2.soundcloud.com/search?q=hans&limit=10&offset=0", assertEquals("https://api-v2.soundcloud.com/search?q=hans&limit=10&offset=0",
removeClientId(SoundCloud.getSearchQIHFactory().fromQuery("hans").getUrl())); removeClientId(SoundCloud.getSearchQHFactory().fromQuery("hans").getUrl()));
assertEquals("https://api-v2.soundcloud.com/search?q=Poifj%26jaijf&limit=10&offset=0", assertEquals("https://api-v2.soundcloud.com/search?q=Poifj%26jaijf&limit=10&offset=0",
removeClientId(SoundCloud.getSearchQIHFactory().fromQuery("Poifj&jaijf").getUrl())); removeClientId(SoundCloud.getSearchQHFactory().fromQuery("Poifj&jaijf").getUrl()));
assertEquals("https://api-v2.soundcloud.com/search?q=G%C3%BCl%C3%BCm&limit=10&offset=0", assertEquals("https://api-v2.soundcloud.com/search?q=G%C3%BCl%C3%BCm&limit=10&offset=0",
removeClientId(SoundCloud.getSearchQIHFactory().fromQuery("Gülüm").getUrl())); removeClientId(SoundCloud.getSearchQHFactory().fromQuery("Gülüm").getUrl()));
assertEquals("https://api-v2.soundcloud.com/search?q=%3Fj%24%29H%C2%A7B&limit=10&offset=0", assertEquals("https://api-v2.soundcloud.com/search?q=%3Fj%24%29H%C2%A7B&limit=10&offset=0",
removeClientId(SoundCloud.getSearchQIHFactory().fromQuery("?j$)H§B").getUrl())); removeClientId(SoundCloud.getSearchQHFactory().fromQuery("?j$)H§B").getUrl()));
} }
@Test @Test
public void testGetContentFilter() throws Exception { public void testGetContentFilter() throws Exception {
assertEquals("tracks", SoundCloud.getSearchQIHFactory() assertEquals("tracks", SoundCloud.getSearchQHFactory()
.fromQuery("", asList(new String[]{"tracks"}), "").getContentFilters().get(0)); .fromQuery("", asList(new String[]{"tracks"}), "").getContentFilters().get(0));
assertEquals("users", SoundCloud.getSearchQIHFactory() assertEquals("users", SoundCloud.getSearchQHFactory()
.fromQuery("asdf", asList(new String[]{"users"}), "").getContentFilters().get(0)); .fromQuery("asdf", asList(new String[]{"users"}), "").getContentFilters().get(0));
} }
@Test @Test
public void testWithContentfilter() throws Exception { public void testWithContentfilter() throws Exception {
assertEquals("https://api-v2.soundcloud.com/search/tracks?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQIHFactory() assertEquals("https://api-v2.soundcloud.com/search/tracks?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQHFactory()
.fromQuery("asdf", asList(new String[]{"tracks"}), "").getUrl())); .fromQuery("asdf", asList(new String[]{TRACKS}), "").getUrl()));
assertEquals("https://api-v2.soundcloud.com/search/users?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQIHFactory() assertEquals("https://api-v2.soundcloud.com/search/users?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQHFactory()
.fromQuery("asdf", asList(new String[]{"users"}), "").getUrl())); .fromQuery("asdf", asList(new String[]{USERS}), "").getUrl()));
assertEquals("https://api-v2.soundcloud.com/search/playlists?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQIHFactory() assertEquals("https://api-v2.soundcloud.com/search/playlists?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQHFactory()
.fromQuery("asdf", asList(new String[]{"playlist"}), "").getUrl())); .fromQuery("asdf", asList(new String[]{PLAYLISTS}), "").getUrl()));
assertEquals("https://api-v2.soundcloud.com/search?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQIHFactory() assertEquals("https://api-v2.soundcloud.com/search?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQHFactory()
.fromQuery("asdf", asList(new String[]{"fjiijie"}), "").getUrl())); .fromQuery("asdf", asList(new String[]{"fjiijie"}), "").getUrl()));
} }
@Test @Test
public void testGetAvailableContentFilter() { public void testGetAvailableContentFilter() {
final String[] contentFilter = SoundCloud.getSearchQIHFactory().getAvailableContentFilter(); final String[] contentFilter = SoundCloud.getSearchQHFactory().getAvailableContentFilter();
assertEquals(4, contentFilter.length); assertEquals(4, contentFilter.length);
assertEquals("tracks", contentFilter[0]); assertEquals("all", contentFilter[0]);
assertEquals("users", contentFilter[1]); assertEquals("tracks", contentFilter[1]);
assertEquals("playlist", contentFilter[2]); assertEquals("users", contentFilter[2]);
assertEquals("any", contentFilter[3]); assertEquals("playlists", contentFilter[3]);
} }
@Test @Test
public void testGetAvailableSortFilter() { public void testGetAvailableSortFilter() {
final String[] contentFilter = SoundCloud.getSearchQIHFactory().getAvailableSortFilter(); final String[] contentFilter = SoundCloud.getSearchQHFactory().getAvailableSortFilter();
assertEquals(0, contentFilter.length); assertEquals(0, contentFilter.length);
} }
} }

View File

@ -29,7 +29,7 @@ public class YoutubeSubscriptionExtractorTest {
public static void setupClass() { public static void setupClass() {
NewPipe.init(Downloader.getInstance()); NewPipe.init(Downloader.getInstance());
subscriptionExtractor = new YoutubeSubscriptionExtractor(ServiceList.YouTube); subscriptionExtractor = new YoutubeSubscriptionExtractor(ServiceList.YouTube);
urlHandler = ServiceList.YouTube.getChannelUIHFactory(); urlHandler = ServiceList.YouTube.getChannelLHFactory();
} }
@Test @Test

View File

@ -0,0 +1,59 @@
package org.schabi.newpipe.extractor.services.youtube.search;
import org.junit.Test;
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
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;
public class YoutubeSearchQHTest {
@Test
public void testRegularValues() throws Exception {
assertEquals("https://www.youtube.com/results?q=asdf", YouTube.getSearchQHFactory().fromQuery("asdf").getUrl());
assertEquals("https://www.youtube.com/results?q=hans",YouTube.getSearchQHFactory().fromQuery("hans").getUrl());
assertEquals("https://www.youtube.com/results?q=Poifj%26jaijf", YouTube.getSearchQHFactory().fromQuery("Poifj&jaijf").getUrl());
assertEquals("https://www.youtube.com/results?q=G%C3%BCl%C3%BCm", YouTube.getSearchQHFactory().fromQuery("Gülüm").getUrl());
assertEquals("https://www.youtube.com/results?q=%3Fj%24%29H%C2%A7B", YouTube.getSearchQHFactory().fromQuery("?j$)H§B").getUrl());
}
@Test
public void testGetContentFilter() throws Exception {
assertEquals(VIDEOS, YouTube.getSearchQHFactory()
.fromQuery("", asList(new String[]{VIDEOS}), "").getContentFilters().get(0));
assertEquals(CHANNELS, YouTube.getSearchQHFactory()
.fromQuery("asdf", asList(new String[]{CHANNELS}), "").getContentFilters().get(0));
}
@Test
public void testWithContentfilter() throws Exception {
assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQAVAU", YouTube.getSearchQHFactory()
.fromQuery("asdf", asList(new String[]{VIDEOS}), "").getUrl());
assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQAlAU", YouTube.getSearchQHFactory()
.fromQuery("asdf", asList(new String[]{CHANNELS}), "").getUrl());
assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQA1AU", YouTube.getSearchQHFactory()
.fromQuery("asdf", asList(new String[]{PLAYLISTS}), "").getUrl());
assertEquals("https://www.youtube.com/results?q=asdf", YouTube.getSearchQHFactory()
.fromQuery("asdf", asList(new String[]{"fjiijie"}), "").getUrl());
}
@Test
public void testGetAvailableContentFilter() {
final String[] contentFilter = YouTube.getSearchQHFactory().getAvailableContentFilter();
assertEquals(4, contentFilter.length);
assertEquals("all", contentFilter[0]);
assertEquals("videos", contentFilter[1]);
assertEquals("channels", contentFilter[2]);
assertEquals("playlists", contentFilter[3]);
}
@Test
public void testGetAvailableSortFilter() {
final String[] contentFilter = YouTube.getSearchQHFactory().getAvailableSortFilter();
assertEquals(0, contentFilter.length);
}
}

View File

@ -1,55 +0,0 @@
package org.schabi.newpipe.extractor.services.youtube.search;
import org.junit.Test;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
public class YoutubeSearchQUHTest {
@Test
public void testRegularValues() throws Exception {
assertEquals("https://www.youtube.com/results?q=asdf", YouTube.getSearchQIHFactory().fromQuery("asdf").getUrl());
assertEquals("https://www.youtube.com/results?q=hans",YouTube.getSearchQIHFactory().fromQuery("hans").getUrl());
assertEquals("https://www.youtube.com/results?q=Poifj%26jaijf", YouTube.getSearchQIHFactory().fromQuery("Poifj&jaijf").getUrl());
assertEquals("https://www.youtube.com/results?q=G%C3%BCl%C3%BCm", YouTube.getSearchQIHFactory().fromQuery("Gülüm").getUrl());
assertEquals("https://www.youtube.com/results?q=%3Fj%24%29H%C2%A7B", YouTube.getSearchQIHFactory().fromQuery("?j$)H§B").getUrl());
}
@Test
public void testGetContentFilter() throws Exception {
assertEquals("stream", YouTube.getSearchQIHFactory()
.fromQuery("", asList(new String[]{"stream"}), "").getContentFilters().get(0));
assertEquals("channel", YouTube.getSearchQIHFactory()
.fromQuery("asdf", asList(new String[]{"channel"}), "").getContentFilters().get(0));
}
@Test
public void testWithContentfilter() throws Exception {
assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQAVAU", YouTube.getSearchQIHFactory()
.fromQuery("asdf", asList(new String[]{"stream"}), "").getUrl());
assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQAlAU", YouTube.getSearchQIHFactory()
.fromQuery("asdf", asList(new String[]{"channel"}), "").getUrl());
assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQA1AU", YouTube.getSearchQIHFactory()
.fromQuery("asdf", asList(new String[]{"playlist"}), "").getUrl());
assertEquals("https://www.youtube.com/results?q=asdf", YouTube.getSearchQIHFactory()
.fromQuery("asdf", asList(new String[]{"fjiijie"}), "").getUrl());
}
@Test
public void testGetAvailableContentFilter() {
final String[] contentFilter = YouTube.getSearchQIHFactory().getAvailableContentFilter();
assertEquals(4, contentFilter.length);
assertEquals("stream", contentFilter[0]);
assertEquals("channel", contentFilter[1]);
assertEquals("playlist", contentFilter[2]);
assertEquals("any", contentFilter[3]);
}
@Test
public void testGetAvailableSortFilter() {
final String[] contentFilter = YouTube.getSearchQIHFactory().getAvailableSortFilter();
assertEquals(0, contentFilter.length);
}
}