fix broken search results

This commit is contained in:
Christian Schabesberger 2018-10-25 15:46:47 +02:00
parent 24cb684e23
commit 32d316330c
4 changed files with 17 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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