From 32d316330c26f7a2611721701158248c0dfd583c Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Thu, 25 Oct 2018 15:46:47 +0200 Subject: [PATCH] fix broken search results --- .../youtube/extractors/YoutubeSearchExtractor.java | 9 +++++++-- .../services/youtube/YoutubePlaylistExtractorTest.java | 2 +- .../search/YoutubeSearchExtractorChannelOnlyTest.java | 4 ++-- .../search/YoutubeSearchExtractorDefaultTest.java | 10 +++++++--- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java index ddac54996..709e5f577 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java @@ -53,7 +53,7 @@ public class YoutubeSearchExtractor extends SearchExtractor { @Override public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException { final String site; - final String url = getUrl() + "?gl="+ getLocalization().getCountry(); + final String url = getUrl(); //String url = builder.build().toString(); //if we've been passed a valid language code, append it to the URL site = downloader.download(url, getLocalization()); @@ -61,6 +61,11 @@ public class YoutubeSearchExtractor extends SearchExtractor { doc = Jsoup.parse(site, url); } + @Override + public String getUrl() throws ParsingException { + return super.getUrl() + "&gl="+ getLocalization().getCountry(); + } + @Override public String getSearchSuggestion() { final Element el = doc.select("div[class*=\"spell-correction\"]").first(); @@ -79,7 +84,7 @@ public class YoutubeSearchExtractor extends SearchExtractor { @Override public String getNextPageUrl() throws ExtractionException { - return getUrl() + "&page=" + 2 + "&gl=" + getLocalization().getCountry(); + return getUrl() + "&page=" + 2; } @Override diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java index 1cb6388a2..9cfd6c00e 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java @@ -219,7 +219,7 @@ public class YoutubePlaylistExtractorTest { @Test public void testUploaderName() throws Exception { - assertEquals("Tomas Nilsson", extractor.getUploaderName()); + assertEquals("Tomas Nilsson TOMPA571", extractor.getUploaderName()); } @Test diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorChannelOnlyTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorChannelOnlyTest.java index 937cee5ec..14b94b510 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorChannelOnlyTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorChannelOnlyTest.java @@ -45,12 +45,12 @@ public class YoutubeSearchExtractorChannelOnlyTest extends YoutubeSearchExtracto } assertFalse("First and second page are equal", equals); - assertEquals("https://www.youtube.com/results?q=pewdiepie&sp=EgIQAlAU&page=3&gl=GB", secondPage.getNextPageUrl()); + assertEquals("https://www.youtube.com/results?q=pewdiepie&sp=EgIQAlAU&gl=GB&page=3", secondPage.getNextPageUrl()); } @Test public void testGetSecondPageUrl() throws Exception { - assertEquals("https://www.youtube.com/results?q=pewdiepie&sp=EgIQAlAU&page=2&gl=GB", extractor.getNextPageUrl()); + assertEquals("https://www.youtube.com/results?q=pewdiepie&sp=EgIQAlAU&gl=GB&page=2", extractor.getNextPageUrl()); } @Test diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorDefaultTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorDefaultTest.java index 3df6434ee..172ca62c1 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorDefaultTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorDefaultTest.java @@ -49,16 +49,20 @@ public class YoutubeSearchExtractorDefaultTest extends YoutubeSearchExtractorBas itemsPage = extractor.getInitialPage(); } + @Test + public void testGetUrl() throws Exception { + assertEquals("https://www.youtube.com/results?q=pewdiepie&gl=GB", extractor.getUrl()); + } @Test public void testGetSecondPageUrl() throws Exception { - assertEquals("https://www.youtube.com/results?q=pewdiepie&page=2&gl=GB", extractor.getNextPageUrl()); + assertEquals("https://www.youtube.com/results?q=pewdiepie&gl=GB&page=2", extractor.getNextPageUrl()); } @Test public void testResultList_FirstElement() { - InfoItem firstInfoItem = itemsPage.getItems().get(1); + InfoItem firstInfoItem = itemsPage.getItems().get(0); // THe channel should be the first item assertTrue(firstInfoItem instanceof ChannelInfoItem); @@ -96,7 +100,7 @@ public class YoutubeSearchExtractorDefaultTest extends YoutubeSearchExtractorBas } assertFalse("First and second page are equal", equals); - assertEquals("https://www.youtube.com/results?q=pewdiepie&page=3&gl=GB", secondPage.getNextPageUrl()); + assertEquals("https://www.youtube.com/results?q=pewdiepie&gl=GB&page=3", secondPage.getNextPageUrl()); } @Test