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
////////////////////////////////////////////
public abstract LinkHandlerFactory getStreamUIHFactory();
public abstract ListLinkHandlerFactory getChannelUIHFactory();
public abstract ListLinkHandlerFactory getPlaylistUIHFactory();
public abstract SearchQueryHandlerFactory getSearchQIHFactory();
public abstract LinkHandlerFactory getStreamLHFactory();
public abstract ListLinkHandlerFactory getChannelLHFactory();
public abstract ListLinkHandlerFactory getPlaylistLHFactory();
public abstract SearchQueryHandlerFactory getSearchQHFactory();
////////////////////////////////////////////
@ -86,31 +86,31 @@ public abstract class StreamingService {
public abstract StreamExtractor getStreamExtractor(LinkHandler UIHFactory) 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 {
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 {
return getPlaylistExtractor(getPlaylistUIHFactory().fromQuery(id, contentFilter, sortFilter));
return getPlaylistExtractor(getPlaylistLHFactory().fromQuery(id, contentFilter, sortFilter));
}
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 {
return getChannelExtractor(getChannelUIHFactory().fromUrl(url));
return getChannelExtractor(getChannelLHFactory().fromUrl(url));
}
public PlaylistExtractor getPlaylistExtractor(String url) throws ExtractionException {
return getPlaylistExtractor(getPlaylistUIHFactory().fromUrl(url));
return getPlaylistExtractor(getPlaylistLHFactory().fromUrl(url));
}
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.)
*/
public final LinkType getLinkTypeByUrl(String url) throws ParsingException {
LinkHandlerFactory sH = getStreamUIHFactory();
LinkHandlerFactory cH = getChannelUIHFactory();
LinkHandlerFactory pH = getPlaylistUIHFactory();
LinkHandlerFactory sH = getStreamLHFactory();
LinkHandlerFactory cH = getChannelLHFactory();
LinkHandlerFactory pH = getPlaylistLHFactory();
if (sH.acceptUrl(url)) {
return LinkType.STREAM;

View File

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

View File

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

View File

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

View File

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

View File

@ -48,18 +48,22 @@ public class YoutubePlaylistInfoItemExtractor implements PlaylistInfoItemExtract
@Override
public String getUrl() throws ParsingException {
String url;
try {
final Element href = el.select("div[class=\"yt-lockup-meta\"]").first()
.select("a").first();
final Element div = el.select("div[class=\"yt-lockup-meta\"]").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) {
throw new ParsingException("Failed to extract playlist url", e);
}
return url;
}
@Override

View File

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

View File

@ -8,8 +8,11 @@ import org.schabi.newpipe.extractor.NewPipe;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
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
public static void setUpClass() throws Exception {
@ -24,50 +27,50 @@ public class SoundcloudSearchQUHTest {
@Test
public void testRegularValues() throws Exception {
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",
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",
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",
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",
removeClientId(SoundCloud.getSearchQIHFactory().fromQuery("?j$)H§B").getUrl()));
removeClientId(SoundCloud.getSearchQHFactory().fromQuery("?j$)H§B").getUrl()));
}
@Test
public void testGetContentFilter() throws Exception {
assertEquals("tracks", SoundCloud.getSearchQIHFactory()
assertEquals("tracks", SoundCloud.getSearchQHFactory()
.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));
}
@Test
public void testWithContentfilter() throws Exception {
assertEquals("https://api-v2.soundcloud.com/search/tracks?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQIHFactory()
.fromQuery("asdf", asList(new String[]{"tracks"}), "").getUrl()));
assertEquals("https://api-v2.soundcloud.com/search/users?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQIHFactory()
.fromQuery("asdf", asList(new String[]{"users"}), "").getUrl()));
assertEquals("https://api-v2.soundcloud.com/search/playlists?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQIHFactory()
.fromQuery("asdf", asList(new String[]{"playlist"}), "").getUrl()));
assertEquals("https://api-v2.soundcloud.com/search?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()));
assertEquals("https://api-v2.soundcloud.com/search/users?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQHFactory()
.fromQuery("asdf", asList(new String[]{USERS}), "").getUrl()));
assertEquals("https://api-v2.soundcloud.com/search/playlists?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQHFactory()
.fromQuery("asdf", asList(new String[]{PLAYLISTS}), "").getUrl()));
assertEquals("https://api-v2.soundcloud.com/search?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQHFactory()
.fromQuery("asdf", asList(new String[]{"fjiijie"}), "").getUrl()));
}
@Test
public void testGetAvailableContentFilter() {
final String[] contentFilter = SoundCloud.getSearchQIHFactory().getAvailableContentFilter();
final String[] contentFilter = SoundCloud.getSearchQHFactory().getAvailableContentFilter();
assertEquals(4, contentFilter.length);
assertEquals("tracks", contentFilter[0]);
assertEquals("users", contentFilter[1]);
assertEquals("playlist", contentFilter[2]);
assertEquals("any", contentFilter[3]);
assertEquals("all", contentFilter[0]);
assertEquals("tracks", contentFilter[1]);
assertEquals("users", contentFilter[2]);
assertEquals("playlists", contentFilter[3]);
}
@Test
public void testGetAvailableSortFilter() {
final String[] contentFilter = SoundCloud.getSearchQIHFactory().getAvailableSortFilter();
final String[] contentFilter = SoundCloud.getSearchQHFactory().getAvailableSortFilter();
assertEquals(0, contentFilter.length);
}
}

View File

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