diff --git a/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java b/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java index 6dad3acc7..0081aa0b6 100644 --- a/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java @@ -28,9 +28,24 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; import java.io.IOException; public abstract class KioskExtractor extends ListExtractor { - public KioskExtractor(StreamingService streamingService, String url, String nextStreamsUrl) + private String contentCountry = null; + + public KioskExtractor(StreamingService streamingService, + String url, + String nextStreamsUrl) throws IOException, ExtractionException { super(streamingService, url, nextStreamsUrl); + this.contentCountry = contentCountry; + } + + /** + * 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; } /** @@ -49,4 +64,8 @@ public abstract class KioskExtractor extends ListExtractor { public String getName() throws ParsingException { return getType(); } + + public String getContentCountry() { + return contentCountry; + } } diff --git a/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskInfo.java b/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskInfo.java index 68c04553e..c3fee602c 100644 --- a/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskInfo.java +++ b/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskInfo.java @@ -33,22 +33,30 @@ import java.io.IOException; public class KioskInfo extends ListInfo { public String type; - public static KioskInfo getInfo(String url) throws IOException, ExtractionException { - return getInfo(NewPipe.getServiceByUrl(url), url); + public static KioskInfo getInfo(String url, + String contentCountry) throws IOException, ExtractionException { + return getInfo(NewPipe.getServiceByUrl(url), url, contentCountry); } - public static KioskInfo getInfo(ServiceList serviceItem, String url) throws IOException, ExtractionException { - return getInfo(serviceItem.getService(), url); + public static KioskInfo getInfo(ServiceList serviceItem, + String url, + String contentContry) throws IOException, ExtractionException { + return getInfo(serviceItem.getService(), url, contentContry); } - public static KioskInfo getInfo(StreamingService service, String url) throws IOException, ExtractionException { + public static KioskInfo getInfo(StreamingService service, + String url, + String contentCountry) throws IOException, ExtractionException { KioskList kl = service.getKioskList(); KioskExtractor extractor = kl.getExtryctorByUrl(url); - return getInfo(extractor); + return getInfo(extractor, contentCountry); } - public static KioskInfo getInfo(KioskExtractor extractor) throws ParsingException { + public static KioskInfo getInfo(KioskExtractor extractor, + String contentCountry) throws IOException, ExtractionException { KioskInfo info = new KioskInfo(); + extractor.setContentCountry(contentCountry); + extractor.fetchPage(); info.type = extractor.getType(); info.name = extractor.getName(); info.id = extractor.getId(); diff --git a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractor.java index 77cc2a135..8c71f967a 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractor.java @@ -44,9 +44,14 @@ public class YoutubeTrendingExtractor extends KioskExtractor { public void fetchPage() throws IOException, ExtractionException { Downloader downloader = NewPipe.getDownloader(); - String channelUrl = getCleanUrl(); - String pageContent = downloader.download(channelUrl); - doc = Jsoup.parse(pageContent, channelUrl); + final String contentCountry = getContentCountry(); + String url = getCleanUrl(); + if(contentCountry != null && !contentCountry.isEmpty()) { + url += "?gl=" + contentCountry; + } + + String pageContent = downloader.download(url); + doc = Jsoup.parse(pageContent, url); } @Override