Skip to content

Commit 32d3163

Browse files
committed
fix broken search results
1 parent 24cb684 commit 32d3163

4 files changed

Lines changed: 17 additions & 8 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,19 @@ public YoutubeSearchExtractor(StreamingService service,
5353
@Override
5454
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
5555
final String site;
56-
final String url = getUrl() + "?gl="+ getLocalization().getCountry();
56+
final String url = getUrl();
5757
//String url = builder.build().toString();
5858
//if we've been passed a valid language code, append it to the URL
5959
site = downloader.download(url, getLocalization());
6060

6161
doc = Jsoup.parse(site, url);
6262
}
6363

64+
@Override
65+
public String getUrl() throws ParsingException {
66+
return super.getUrl() + "&gl="+ getLocalization().getCountry();
67+
}
68+
6469
@Override
6570
public String getSearchSuggestion() {
6671
final Element el = doc.select("div[class*=\"spell-correction\"]").first();
@@ -79,7 +84,7 @@ public InfoItemsPage<InfoItem> getInitialPage() throws ExtractionException {
7984

8085
@Override
8186
public String getNextPageUrl() throws ExtractionException {
82-
return getUrl() + "&page=" + 2 + "&gl=" + getLocalization().getCountry();
87+
return getUrl() + "&page=" + 2;
8388
}
8489

8590
@Override

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public void testUploaderUrl() throws Exception {
219219

220220
@Test
221221
public void testUploaderName() throws Exception {
222-
assertEquals("Tomas Nilsson", extractor.getUploaderName());
222+
assertEquals("Tomas Nilsson TOMPA571", extractor.getUploaderName());
223223
}
224224

225225
@Test

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorChannelOnlyTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ public void testGetSecondPage() throws Exception {
4545
}
4646
assertFalse("First and second page are equal", equals);
4747

48-
assertEquals("https://www.youtube.com/results?q=pewdiepie&sp=EgIQAlAU&page=3&gl=GB", secondPage.getNextPageUrl());
48+
assertEquals("https://www.youtube.com/results?q=pewdiepie&sp=EgIQAlAU&gl=GB&page=3", secondPage.getNextPageUrl());
4949
}
5050

5151
@Test
5252
public void testGetSecondPageUrl() throws Exception {
53-
assertEquals("https://www.youtube.com/results?q=pewdiepie&sp=EgIQAlAU&page=2&gl=GB", extractor.getNextPageUrl());
53+
assertEquals("https://www.youtube.com/results?q=pewdiepie&sp=EgIQAlAU&gl=GB&page=2", extractor.getNextPageUrl());
5454
}
5555

5656
@Test

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorDefaultTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,20 @@ public static void setUpClass() throws Exception {
4949
itemsPage = extractor.getInitialPage();
5050
}
5151

52+
@Test
53+
public void testGetUrl() throws Exception {
54+
assertEquals("https://www.youtube.com/results?q=pewdiepie&gl=GB", extractor.getUrl());
55+
}
5256

5357

5458
@Test
5559
public void testGetSecondPageUrl() throws Exception {
56-
assertEquals("https://www.youtube.com/results?q=pewdiepie&page=2&gl=GB", extractor.getNextPageUrl());
60+
assertEquals("https://www.youtube.com/results?q=pewdiepie&gl=GB&page=2", extractor.getNextPageUrl());
5761
}
5862

5963
@Test
6064
public void testResultList_FirstElement() {
61-
InfoItem firstInfoItem = itemsPage.getItems().get(1);
65+
InfoItem firstInfoItem = itemsPage.getItems().get(0);
6266

6367
// THe channel should be the first item
6468
assertTrue(firstInfoItem instanceof ChannelInfoItem);
@@ -96,7 +100,7 @@ public void testGetSecondPage() throws Exception {
96100
}
97101
assertFalse("First and second page are equal", equals);
98102

99-
assertEquals("https://www.youtube.com/results?q=pewdiepie&page=3&gl=GB", secondPage.getNextPageUrl());
103+
assertEquals("https://www.youtube.com/results?q=pewdiepie&gl=GB&page=3", secondPage.getNextPageUrl());
100104
}
101105

102106
@Test

0 commit comments

Comments
 (0)