add support for yt content country
This commit is contained in:
parent
3a865749e8
commit
0c3dc86b07
|
@ -30,7 +30,6 @@ import org.schabi.newpipe.extractor.utils.Localization;
|
|||
import javax.annotation.Nonnull;
|
||||
|
||||
public abstract class KioskExtractor extends ListExtractor<StreamInfoItem> {
|
||||
private String contentCountry = null;
|
||||
private final String id;
|
||||
|
||||
public KioskExtractor(StreamingService streamingService,
|
||||
|
@ -41,17 +40,6 @@ public abstract class KioskExtractor extends ListExtractor<StreamInfoItem> {
|
|||
this.id = kioskId;
|
||||
}
|
||||
|
||||
/**
|
||||
* For certain Websites the content of a kiosk will be different depending
|
||||
* on the country you want to poen the website in. Therefore you should
|
||||
* set the contentCountry.
|
||||
* @param contentCountry Set the country decoded as Country Code: http://www.1728.org/countries.htm
|
||||
*/
|
||||
public void setContentCountry(String contentCountry) {
|
||||
this.contentCountry = contentCountry;
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getId() {
|
||||
|
@ -69,9 +57,4 @@ public abstract class KioskExtractor extends ListExtractor<StreamInfoItem> {
|
|||
@Nonnull
|
||||
@Override
|
||||
public abstract String getName() throws ParsingException;
|
||||
|
||||
|
||||
public String getContentCountry() {
|
||||
return contentCountry;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,22 +53,16 @@ public class YoutubeSearchExtractor extends SearchExtractor {
|
|||
@Override
|
||||
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
||||
final String site;
|
||||
final String url = getUrl();
|
||||
final String contentCountry = getLocalization().getCountry();
|
||||
final String url = getUrl() + "?gl="+ getLocalization().getCountry();
|
||||
//String url = builder.build().toString();
|
||||
//if we've been passed a valid language code, append it to the URL
|
||||
if (!contentCountry.isEmpty()) {
|
||||
//assert Pattern.matches("[a-z]{2}(-([A-Z]{2}|[0-9]{1,3}))?", languageCode);
|
||||
site = downloader.download(url, getLocalization());
|
||||
} else {
|
||||
site = downloader.download(url);
|
||||
}
|
||||
site = downloader.download(url, getLocalization());
|
||||
|
||||
doc = Jsoup.parse(site, url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSearchSuggestion() throws ParsingException {
|
||||
public String getSearchSuggestion() {
|
||||
final Element el = doc.select("div[class*=\"spell-correction\"]").first();
|
||||
if (el != null) {
|
||||
return el.select("a").first().text();
|
||||
|
@ -79,13 +73,13 @@ public class YoutubeSearchExtractor extends SearchExtractor {
|
|||
|
||||
@Nonnull
|
||||
@Override
|
||||
public InfoItemsPage<InfoItem> getInitialPage() throws IOException, ExtractionException {
|
||||
public InfoItemsPage<InfoItem> getInitialPage() throws ExtractionException {
|
||||
return new InfoItemsPage<>(collectItems(doc), getNextPageUrl());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNextPageUrl() throws ExtractionException {
|
||||
return getUrl() + "&page=" + Integer.toString( 2);
|
||||
return getUrl() + "&page=" + 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -104,7 +98,7 @@ public class YoutubeSearchExtractor extends SearchExtractor {
|
|||
.getQuery())
|
||||
.get("page"));
|
||||
|
||||
return currentUrl.replace("&page=" + Integer.toString( pageNr),
|
||||
return currentUrl.replace("&page=" + pageNr,
|
||||
"&page=" + Integer.toString(pageNr + 1));
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ public class YoutubeTrendingExtractor extends KioskExtractor {
|
|||
|
||||
@Override
|
||||
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
||||
final String contentCountry = getContentCountry();
|
||||
final String contentCountry = getLocalization().getCountry();
|
||||
String url = getUrl();
|
||||
if(contentCountry != null && !contentCountry.isEmpty()) {
|
||||
url += "?gl=" + contentCountry;
|
||||
|
|
|
@ -51,7 +51,6 @@ public class YoutubeTrendingExtractorTest {
|
|||
.getKioskList()
|
||||
.getExtractorById("Trending", null);
|
||||
extractor.fetchPage();
|
||||
extractor.setContentCountry("de");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue