fix broken search results
This commit is contained in:
parent
24cb684e23
commit
32d316330c
|
@ -53,7 +53,7 @@ public class YoutubeSearchExtractor extends SearchExtractor {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
||||||
final String site;
|
final String site;
|
||||||
final String url = getUrl() + "?gl="+ getLocalization().getCountry();
|
final String url = getUrl();
|
||||||
//String url = builder.build().toString();
|
//String url = builder.build().toString();
|
||||||
//if we've been passed a valid language code, append it to the URL
|
//if we've been passed a valid language code, append it to the URL
|
||||||
site = downloader.download(url, getLocalization());
|
site = downloader.download(url, getLocalization());
|
||||||
|
@ -61,6 +61,11 @@ public class YoutubeSearchExtractor extends SearchExtractor {
|
||||||
doc = Jsoup.parse(site, url);
|
doc = Jsoup.parse(site, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUrl() throws ParsingException {
|
||||||
|
return super.getUrl() + "&gl="+ getLocalization().getCountry();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSearchSuggestion() {
|
public String getSearchSuggestion() {
|
||||||
final Element el = doc.select("div[class*=\"spell-correction\"]").first();
|
final Element el = doc.select("div[class*=\"spell-correction\"]").first();
|
||||||
|
@ -79,7 +84,7 @@ public class YoutubeSearchExtractor extends SearchExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getNextPageUrl() throws ExtractionException {
|
public String getNextPageUrl() throws ExtractionException {
|
||||||
return getUrl() + "&page=" + 2 + "&gl=" + getLocalization().getCountry();
|
return getUrl() + "&page=" + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -219,7 +219,7 @@ public class YoutubePlaylistExtractorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUploaderName() throws Exception {
|
public void testUploaderName() throws Exception {
|
||||||
assertEquals("Tomas Nilsson", extractor.getUploaderName());
|
assertEquals("Tomas Nilsson TOMPA571", extractor.getUploaderName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -45,12 +45,12 @@ public class YoutubeSearchExtractorChannelOnlyTest extends YoutubeSearchExtracto
|
||||||
}
|
}
|
||||||
assertFalse("First and second page are equal", equals);
|
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
|
@Test
|
||||||
public void testGetSecondPageUrl() throws Exception {
|
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
|
@Test
|
||||||
|
|
|
@ -49,16 +49,20 @@ public class YoutubeSearchExtractorDefaultTest extends YoutubeSearchExtractorBas
|
||||||
itemsPage = extractor.getInitialPage();
|
itemsPage = extractor.getInitialPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetUrl() throws Exception {
|
||||||
|
assertEquals("https://www.youtube.com/results?q=pewdiepie&gl=GB", extractor.getUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetSecondPageUrl() throws Exception {
|
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
|
@Test
|
||||||
public void testResultList_FirstElement() {
|
public void testResultList_FirstElement() {
|
||||||
InfoItem firstInfoItem = itemsPage.getItems().get(1);
|
InfoItem firstInfoItem = itemsPage.getItems().get(0);
|
||||||
|
|
||||||
// THe channel should be the first item
|
// THe channel should be the first item
|
||||||
assertTrue(firstInfoItem instanceof ChannelInfoItem);
|
assertTrue(firstInfoItem instanceof ChannelInfoItem);
|
||||||
|
@ -96,7 +100,7 @@ public class YoutubeSearchExtractorDefaultTest extends YoutubeSearchExtractorBas
|
||||||
}
|
}
|
||||||
assertFalse("First and second page are equal", equals);
|
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
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue